Skip to content

docs: document ENTRY_FILE for Storybook release builds on React Native CLI - #951

Merged
dannyhw merged 6 commits into
nextfrom
dannyhw/fix/bundle-entry-swap
Nov 10, 2026
Merged

dannyhw merged 6 commits into
nextfrom
dannyhw/fix/bundle-entry-swap

Conversation

@dannyhw

@dannyhw dannyhw commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Issue: #944

What I did

With the entry-point-swapping withStorybook, STORYBOOK_ENABLED=true react-native bundle produces the app bundle, not Storybook. Xcode and Gradle run react-native bundle for release builds, so this affects Storybook release builds in React Native CLI projects. Metro's Server.build() takes the entry file as an absolute path and never calls resolveRequest for it, so the resolver swap cannot apply there. The dev server and Expo are not affected.

This PR previously fixed that by taking over Metro's transformerPath with a Storybook worker. That put a new worker in front of every transform for every entry-swap user, including the setups that already work, and needed a lot of code to do safely (finding the right Metro in isolated installs, chaining to Expo's and other wrappers' workers, cache keys). I've dropped that in favour of documenting what React Native already supports:

  • ENTRY_FILE=.rnstorybook/index.tsx is honoured by both react-native-xcode.sh and the React Native Gradle plugin, relative to the project root.
  • --entry-file .rnstorybook/index.tsx when calling react-native bundle directly.

Changes:

  • New "Storybook release builds on React Native CLI" section in the Metro configuration docs, plus a troubleshooting entry.
  • A pointer to it from the React Native CLI scripts in the entry-point swapping migration guide.

No package code changes, so no changeset.

How to test

  • Read the new section in docs/docs/intro/configuration/metro-configuration.md.
  • In a React Native CLI app, run STORYBOOK_ENABLED=true npx react-native bundle --entry-file .rnstorybook/index.tsx --platform ios --dev false --bundle-output /tmp/sb.js and check the output contains getStorybookUI.

Fixes #944

`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
@changeset-bot

changeset-bot Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 712436b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

next now resolves metro 0.87.1 everywhere, so keeping the 0.84.6 pin would
install a second metro just for the bundle entry swap tests. This also
regenerates the lockfile, which the merge left without the metro entries.
…e CLI

Replace the transform-worker entry swap with documentation. Metro's
`react-native bundle` path does not resolve the entry file through the
resolver, so entry-point swapping cannot apply there. Taking over
`transformerPath` to work around it put a Storybook worker in front of every
transform for all users to fix a case that only affects React Native CLI
release builds, which React Native already lets you solve with `ENTRY_FILE`.
@dannyhw dannyhw changed the title fix: apply Storybook entry-point swapping to react-native bundle builds docs: document ENTRY_FILE for Storybook release builds on React Native CLI Nov 10, 2026
@dannyhw
dannyhw merged commit 674753e into next Nov 10, 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.

Entry-point swapping doesn't apply to react-native bundle / bare RN release builds

1 participant