fix: pre-compile worklets in build to prevent NativeWorklets copy crash#34
Merged
Merged
Conversation
Adapters (GorhomSheetAdapter, CustomModalAdapter) call worklets APIs such as `scheduleOnRN` inside worklets via named imports from `react-native-worklets`. The library ships precompiled CommonJS, where bob turned those named imports into namespace member access (`_reactNativeWorklets.scheduleOnRN`). When a consumer app's worklets Babel plugin re-processes that already-compiled worklet, it can't recognize the member access as a hoistable global, so it captures the entire `_reactNativeWorklets` namespace object — including the native `NativeWorklets` singleton — into the worklet closure. Serializing that closure to the UI thread crashes with: [Worklets] Cannot copy value of type NativeWorklets. Add `react-native-worklets/plugin` to the library's own Babel build (after react-compiler, so it runs last). The plugin now transforms worklets at build time: it resolves the named import to just the serializable `scheduleOnRN` function in the closure and stamps `__workletHash`, so the consumer's plugin skips re-processing entirely. No consumer-side config change required. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J3Nqm7ZRJu2kN6JgXX4Dw2
ab4cf63 to
9748cec
Compare
Closed
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.
Adapters (GorhomSheetAdapter, CustomModalAdapter) call worklets APIs such
as
scheduleOnRNinside worklets via named imports fromreact-native-worklets. The library ships precompiled CommonJS, where bobturned those named imports into namespace member access
(
_reactNativeWorklets.scheduleOnRN). When a consumer app's worklets Babelplugin re-processes that already-compiled worklet, it can't recognize the
member access as a hoistable global, so it captures the entire
_reactNativeWorkletsnamespace object — including the nativeNativeWorkletssingleton — into the worklet closure. Serializing thatclosure to the UI thread crashes with:
[Worklets] Cannot copy value of type NativeWorklets.
Add
react-native-worklets/pluginto the library's own Babel build (afterreact-compiler, so it runs last). The plugin now transforms worklets at
build time: it resolves the named import to just the serializable
scheduleOnRNfunction in the closure and stamps__workletHash, so theconsumer's plugin skips re-processing entirely. No consumer-side config
change required.
Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01J3Nqm7ZRJu2kN6JgXX4Dw2