Skip to content

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

Merged
ndelangen merged 6 commits into
nextfrom
norbert/add-server-diable-to-legacy-configwrappers
Jun 22, 2026
Merged

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

Conversation

@ndelangen

@ndelangen ndelangen commented May 29, 2026

Copy link
Copy Markdown
Member

feat: respect STORYBOOK_SERVER env variable in legacy metro and repack config wrappers

What I did

The STORYBOOK_SERVER=false env variable was already supported in the newer entrypoint-swapping withStorybook path, but was not being respected in the legacy metro/withStorybook and repack/withStorybook config wrappers. This meant customers using the legacy setup who set STORYBOOK_SERVER=false would still have the channel server attempt to start — causing SSL errors when no cert/key was configured:

Error: [Storybook] Secure channel server requires both `ssl.key` and `ssl.cert`.

Added envVariableToBoolean support for STORYBOOK_SERVER in both legacy wrappers, defaulting to true for full backwards compatibility. The channel server is now skipped entirely when STORYBOOK_SERVER=false, rather than attempting to start and failing on SSL validation.

How to test

  • Set STORYBOOK_SERVER=false in your environment when using the metro/withStorybook config wrapper — the channel server should not start, and no SSL error should appear.
  • Verify existing setups without STORYBOOK_SERVER set continue to work as before (default is true).

Validated via canary release 10.4.5-canary-20260529144515 — multiple customers confirmed the fix resolves the SSL error without needing to remove env vars.

…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

changeset-bot Bot commented May 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 246880f

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

Copilot AI left a comment

Copy link
Copy Markdown

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 thread packages/react-native/src/metro/withStorybook.ts
Comment thread packages/react-native/src/repack/withStorybook.ts
} = 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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That's an option that's set/can be set at runtime. We'll want to have an env-variable based override for chromatic

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The reasoning is to make the old setup easier to set up with Chromatic as well.

@ndelangen ndelangen added the bug Something isn't working label Jun 22, 2026
@ndelangen ndelangen requested a review from dannyhw June 22, 2026 06:58
@ndelangen ndelangen merged commit f1371a3 into next Jun 22, 2026
1 check passed
@ndelangen ndelangen deleted the norbert/add-server-diable-to-legacy-configwrappers branch June 22, 2026 06:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants