Skip to content

fix: pre-compile worklets in build to prevent NativeWorklets copy crash#34

Merged
arekkubaczkowski merged 1 commit into
mainfrom
claude/bottom-sheet-stack-bug-ifxvij
Jul 7, 2026
Merged

fix: pre-compile worklets in build to prevent NativeWorklets copy crash#34
arekkubaczkowski merged 1 commit into
mainfrom
claude/bottom-sheet-stack-bug-ifxvij

Conversation

@arekkubaczkowski

Copy link
Copy Markdown
Owner

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

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
@arekkubaczkowski arekkubaczkowski force-pushed the claude/bottom-sheet-stack-bug-ifxvij branch from ab4cf63 to 9748cec Compare July 7, 2026 05:10
@arekkubaczkowski arekkubaczkowski merged commit fb8e12c into main Jul 7, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant