Skip to content

feat: enhance Storybook server configuration with environment variable support#894

Open
ndelangen wants to merge 5 commits into
nextfrom
norbert/add-server-diable-to-legacy-configwrappers
Open

feat: enhance Storybook server configuration with environment variable support#894
ndelangen wants to merge 5 commits into
nextfrom
norbert/add-server-diable-to-legacy-configwrappers

Conversation

@ndelangen
Copy link
Copy Markdown
Member

  • Added envVariableToBoolean import to both withStorybook.ts files.
  • Introduced a conditional check for the STORYBOOK_SERVER environment variable to control the creation of the channel server.
  • Updated logic to ensure the server starts only when the STORYBOOK_SERVER variable is true.

Issue:

What I did

How to test

Please explain how to test your changes and consider the following questions

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

If your answer is yes to any of these, please make sure to include it in your PR.

…e support

- Added `envVariableToBoolean` import to both `withStorybook.ts` files.
- Introduced a conditional check for the `STORYBOOK_SERVER` environment variable to control the creation of the channel server.
- Updated logic to ensure the server starts only when the `STORYBOOK_SERVER` variable is true.
Copilot AI review requested due to automatic review settings May 29, 2026 14:42
@ndelangen ndelangen requested a review from dannyhw as a code owner May 29, 2026 14:42
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 29, 2026

🦋 Changeset detected

Latest commit: 9b3ae30

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/react-native-ui Patch
@storybook/react-native-ui-lite Patch
@storybook/react-native-ui-common Patch
@storybook/react-native-theming Patch
@storybook/addon-ondevice-actions Patch
@storybook/addon-ondevice-backgrounds Patch
@storybook/addon-ondevice-controls Patch
@storybook/addon-ondevice-notes 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

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds an environment-variable-controlled switch to prevent starting the Storybook channel server in the Metro and Re.Pack integration entrypoints, aligning server startup with STORYBOOK_SERVER being explicitly enabled.

Changes:

  • Import and use envVariableToBoolean in Metro and Re.Pack Storybook wrappers/plugins.
  • Gate createChannelServer(...) behind STORYBOOK_SERVER (defaulting to true).
  • Ensure the channel server is only started when STORYBOOK_SERVER evaluates to true.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
packages/react-native/src/metro/withStorybook.ts Adds STORYBOOK_SERVER boolean gate to control whether Metro starts the channel server.
packages/react-native/src/repack/withStorybook.ts Adds STORYBOOK_SERVER boolean gate to control whether the Re.Pack plugin starts the channel server.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 146 to 148
const disableTelemetry = optionalEnvToBoolean(process.env.STORYBOOK_DISABLE_TELEMETRY);
const server = envVariableToBoolean(process.env.STORYBOOK_SERVER, true);

Comment on lines +212 to +216
if (server) {
// note that in this case by passing an undefined host we only bind to the port and allow any connections i.e localhost, 127.0.0.1, 0.0.0.0, etc.
// in the generate function we try to get the ip address from the os and write it to the requires file for easier lan connection
createChannelServer({
port,
Comment on lines 185 to 190
// Start the channel server once (on first apply, not per-compilation)
if (
(experimental_mcp || websockets != null || process.env.STORYBOOK_WS_HOST) &&
!this.serverStarted
!this.serverStarted &&
server
) {
} = options;

const disableTelemetry = optionalEnvToBoolean(process.env.STORYBOOK_DISABLE_TELEMETRY);
const server = envVariableToBoolean(process.env.STORYBOOK_SERVER, true);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why wouldnt we use existing channelWebsocketsEnabled?

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.

3 participants