Skip to content

fix: apply Storybook entry-point swapping to react-native bundle builds - #952

Closed
dannyhw wants to merge 2 commits into
v10-stablefrom
dannyhw/fix/bundle-entry-swap-v10
Closed

dannyhw wants to merge 2 commits into
v10-stablefrom
dannyhw/fix/bundle-entry-swap-v10

Conversation

@dannyhw

@dannyhw dannyhw commented Oct 24, 2026

Copy link
Copy Markdown
Member

Issue: #944

What I did

Backport of #951 to v10-stable.

STORYBOOK_ENABLED=true react-native bundle, and therefore bare React Native release builds, shipped the app instead of Storybook. Metro's build path never calls resolveRequest for the entry. withStorybook now also sets a Metro transformerPath worker that swaps the app entry at transform time. It chains to the existing worker, and it resolves Metro's default worker the way react-native bundle loads it. See #951 for details.

Conflicts, all small:

  • v10 has no preview alias, so that import and its test are not part of this branch.
  • tests/package.json keeps v10's test file list and adds the new bundleEntrySwap test.
  • The lockfile change is the same 7 lines as on next. Metro 0.84.6 was already resolved here.

How to test

  • pnpm -F @storybook/tests test: the bundleEntrySwap e2e test, a real Metro.runBuild, fails on v10-stable (5 of 6) and passes here.
  • Manually, in a bare RN 0.88 app on @storybook/react-native 10.7.0 with this branch's dist:
    • STORYBOOK_ENABLED=true npx react-native bundle --entry-file index.js --platform ios --dev true --bundle-output /tmp/sb.js gives the Storybook bundle (before: the app).
    • With Storybook disabled, the output is byte-identical to before.

Typecheck, lint, Prettier, pnpm test and pnpm --filter expo-example check all pass.

`STORYBOOK_ENABLED=true react-native bundle`, which is also what Xcode and Gradle
run for release builds, shipped the app instead of Storybook: the swap lived only in
`resolver.resolveRequest`, and Metro does not ask the resolver about the entry when it
is building. It now also happens in a transform worker that chains to whichever worker
the app had configured, resolved the way Metro resolves it, so `start`, `bundle` and
native release builds all produce the Storybook app.

Fixes #944

(cherry picked from commit aeddb44)
@changeset-bot

changeset-bot Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8f1b853

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 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-ui 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 commented Nov 8, 2026

Copy link
Copy Markdown
Member Author

leave it for v11

@dannyhw dannyhw closed this Nov 8, 2026
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