fix: allow web transformer to run without a compiled worklet#13
Merged
Conversation
The Transformer constructor required a __workletHash, which is only set when the worklets babel plugin transforms the code. Web bundlers (vite/esbuild) don't run that plugin over node_modules, so constructing a transformer threw on web. The web TransformerTextInput runs the worklet synchronously in JS and doesn't need a compiled worklet, so skip the check when Platform.OS === 'web'.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The web
TransformerTextInputadded in #12 crashes on construction in a real web app:The
Transformerconstructor checks for__workletHashto confirm the worklet was compiled. That hash is only added by thereact-native-workletsBabel plugin — which Metro runs overnode_moduleson native, but web bundlers (vite/esbuild) don't when pre-bundling the prebuiltlib/. So on web the function reaches the constructor uncompiled and throws, making any worklet-based transformer (e.g.PhoneNumberTransformer) unusable.Fix
Web has no UI runtime: the web
TransformerTextInputalready runs the worklet synchronously in JS (transformer.worklet(...)), so it doesn't need a compiled worklet at all. Skip the__workletHashassertion whenPlatform.OS === 'web'; native keeps enforcing it so a missing"worklet"directive is still caught there.Test plan
PhoneNumberTransformer({ international: true })input formats live, derives E.164, and resolves the country flag from the area code. Without this fix the same setup throws on mount.yarn test(123 passing),tsc, and eslint clean.