Skip to content

fix(react-native): configure the Worklets Babel plugin with strictGlobal - #83

Open
NathanWalker wants to merge 1 commit into
android-react-nativefrom
fix/rn-worklets-strict-global
Open

NathanWalker wants to merge 1 commit into
android-react-nativefrom
fix/rn-worklets-strict-global

Conversation

@NathanWalker

Copy link
Copy Markdown
Contributor

Split out of #77 (item 5 of the "NativeScript bugs" list in ng-native/ng-native#931).

Summary

Without strictGlobal, the Worklets Babel plugin captures every name a worklet doesn't declare into the worklet's closure. That closure is read on the JS thread when the defining module is evaluated, and NativeScript's classes don't exist there. A module-level worklet that names UILabel failed at startup with ReferenceError: Property 'UILabel' doesn't exist.

 // babel.config.js written by the config plugin and `nativescript-rn configure`
 presets: [
-  'babel-preset-expo',
+  ['babel-preset-expo', { worklets: false }],   // so the preset doesn't add a second copy
 ],
 plugins: [
   '@nativescript/react-native/babel-plugin',
-  'react-native-worklets/plugin',
+  ['react-native-worklets/plugin', { strictGlobal: true }],
 ],
  • Bare entries in an existing config are upgraded in place.
  • An entry that already has options but lacks strictGlobal gets a warning rather than a rewrite.
  • The Babel setup also runs on Android-only prebuilds.

The README changes for this are in the README PR.

Evidence

node test/config-plugin.test.js runs the real plugin against temp project directories.

  • Before: this branch's test against the base plugin fails:
    AssertionError: Expected values to be strictly deep-equal:
      actual: 'babel-preset-expo',
      expected: [ 'babel-preset-expo', { worklets: false } ]
    
  • After: it passes.

The other package tests give the same results as on the base branch.

On the iOS simulator (tested in #77), a module-level worklet naming UILabel loads.

Merge Danger

Door: two-way

Blast Radius: generated babel.config.js

It rewrites existing configs, but only bare react-native-worklets/plugin and babel-preset-expo entries. Entries the user has already given options to are left alone and only warned about.

Without strictGlobal the Worklets plugin captures every name a worklet
does not declare into its closure, read on the JS thread when the module
is evaluated, where NativeScript's classes do not exist: a module-level
worklet naming UILabel failed at startup with
"ReferenceError: Property 'UILabel' doesn't exist".

The config plugin and configure CLI now write
['react-native-worklets/plugin', { strictGlobal: true }] and
['babel-preset-expo', { worklets: false }] (so the preset adds no second
copy), upgrade bare entries in an existing config, and warn when an
entry with options lacks strictGlobal. The Babel setup also runs on
Android-only prebuilds.
@coderabbitai

coderabbitai Bot commented Oct 24, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4a3e8ffb-3132-44e1-b36e-056730347b86

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

No deployments
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