Skip to content

fix: accept worklets without __closure emitted by react-native-worklets' Babel plugin - #276

Open
wn-na wants to merge 1 commit into
margelo:mainfrom
wn-na:fix/closureless-worklets
Open

wn-na wants to merge 1 commit into
margelo:mainfrom
wn-na:fix/closureless-worklets

Conversation

@wn-na

@wn-na wn-na commented Oct 19, 2026

Copy link
Copy Markdown

Summary

The Babel plugin from react-native-worklets (Reanimated 4) emits __workletHash as a number and omits __closure for worklets that capture no variables. worklets-core only accepts a worklet when the hash is a string or __closure exists, so these worklets were treated as regular JS functions and threw Regular javascript function '...' cannot be shared when called from another worklet.

Fixes #275

Changes

  • Add JsiWorklet::isClosurelessWorklet(): returns true when __workletHash is a number and __initData.code is a string.
  • isDecoratedAsWorklet(): accept closureless worklets.
  • createWorklet(): when __closure is missing on a closureless worklet, use an empty array instead of bailing out. Generated code for such worklets never reads this.__closure.

Existing worklets (string hash, or any worklet with a __closure) take the same path as before.

Test plan

  • A 'worklet' function with no captured variables, called from a worklet on a worklets-core context, runs instead of throwing.
  • Worklets with captured variables still work (closure values are passed through as before).
  • Worklets transpiled by react-native-worklets-core/plugin alone still work.
  • iOS and Android (the change is in shared C++).

🤖 Generated with Claude Code

…ts' Babel plugin

The react-native-worklets Babel plugin emits __workletHash as a number and
omits __closure for worklets that capture no variables. These were treated
as regular JS functions and threw "Regular javascript function '...' cannot
be shared" when called from another worklet.

Fixes margelo#275

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

Worklets without captured variables are rejected as "Regular javascript function" when transpiled by react-native-worklets' Babel plugin

1 participant