Skip to content

fix(ui): stop capturing Platform in on-device UI worklets (backport #967) - #976

Merged
dannyhw merged 1 commit into
v10-stablefrom
backport/worklet-platform-capture-v10
Nov 14, 2026
Merged

dannyhw merged 1 commit into
v10-stablefrom
backport/worklet-platform-capture-v10

Conversation

@dannyhw

@dannyhw dannyhw commented Nov 14, 2026

Copy link
Copy Markdown
Member

Issue: #935

What I did

Backport of #967 to v10-stable.

On React Native 0.87 with react-native-worklets 0.12, the full on-device UI crashes on launch with "[Worklets] Trying to convert a cyclic object to a serializable". The menu backdrop and addons panel useAnimatedStyle worklets read Platform.OS inside the worklet, so the worklets babel plugin captured Platform, and in the published CommonJS build the whole react-native module, and Worklets tried to copy it to the UI runtime.

  • MobileMenuDrawer.tsx and MobileAddonsPanel.tsx read Platform.OS once at module level into isAndroid and use that inside the worklets, so they capture a boolean.
  • The backdrop worklet destructures animatedIndex instead of capturing the whole props object.
  • Patch changeset for @storybook/react-native-ui.

Differences from #967:

  • The jest test (worklets.test.tsx) is left out. @storybook/react-native-ui has no jest setup on v10-stable, and adding one is more than a patch backport should carry.
  • The addons panel worklet keeps this branch's dependency array. The web-only dependency array on next comes from a different change.

How to test

Build the package and check what the worklets in the published CommonJS output capture, by running the worklets babel plugin over packages/react-native-ui/dist/index.js and reading each worklet's __closure:

addons panel worklet menu backdrop worklet
v10-stable react_native, insets, height, animatedPosition react_native, backdropComponentProps
this branch isAndroid, insets, height, animatedPosition isAndroid, animatedIndex
pnpm build
pnpm lint
pnpm -F @storybook/react-native-ui check:types
pnpm test:ci

All of these pass on this branch. The crash itself was reproduced and the fix verified on iOS and Android for #967 on next; this backport has not been run on a device, since the example app on this branch is on React Native 0.86 with react-native-worklets 0.10, where the crash doesn't occur.

  • Does this need a new example in examples/expo-example? No
  • Does this need an update to the documentation? No

On React Native 0.87 with react-native-worklets 0.12 the on-device UI
crashes as soon as MobileMenuDrawer mounts, with "[Worklets] Trying to
convert a cyclic object to a serializable" or errors thrown from
native module getters while Worklets walks the captured values.

The menu backdrop and the addons panel both read `Platform.OS` inside a
`useAnimatedStyle` worklet. The worklets babel plugin captures every
outer value a worklet references and Worklets copies them to the UI
runtime, so these worklets carried `Platform` with them, and in the
published CommonJS build, where the import compiles to
`react_native.Platform.OS`, the entire `react-native` module.

Read `Platform.OS` once at module level into `isAndroid` and use that in
the worklets, so they only capture a boolean. The backdrop worklet also
destructures `animatedIndex` instead of capturing the whole props object.

Backport of #967 to v10-stable, without its jest test:
@storybook/react-native-ui has no jest setup on this branch.

(cherry picked from commit da0e7cf)

Co-authored-by: Daniel Williams <me@dannyhw.com>
@changeset-bot

changeset-bot Bot commented Nov 14, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6d14a48

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
@storybook/react-native-ui Patch
@storybook/addon-ondevice-actions Patch
@storybook/addon-ondevice-backgrounds Patch
@storybook/addon-ondevice-controls Patch
@storybook/addon-ondevice-notes Patch
@storybook/react-native-theming Patch
@storybook/react-native-ui-common Patch
@storybook/react-native-ui-lite Patch
@storybook/react-native Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@dannyhw
dannyhw merged commit 6cf17d5 into v10-stable Nov 14, 2026
1 check 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.

2 participants