From 9748cec792b09b9812abb1743e0e6c10e23a79f3 Mon Sep 17 00:00:00 2001 From: Arek Kubaczkowski Date: Tue, 7 Jul 2026 05:07:35 +0000 Subject: [PATCH] fix: pre-compile worklets in build to prevent NativeWorklets copy crash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Claude-Session: https://claude.ai/code/session_01J3Nqm7ZRJu2kN6JgXX4Dw2 --- babel.config.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/babel.config.js b/babel.config.js index 5392927..f544784 100644 --- a/babel.config.js +++ b/babel.config.js @@ -8,5 +8,8 @@ module.exports = { panicThreshold: 'all_errors', }, ], + // Pre-compile worklets so shipped CJS doesn't crash consumers with + // "Cannot copy value of type NativeWorklets". Must run last. + 'react-native-worklets/plugin', ], };