feat: enhance Storybook server configuration with environment variable support#894
Conversation
…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.
🦋 Changeset detectedLatest commit: 246880f The changes in this PR will be included in the next version bump. This PR includes changesets to release 9 packages
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 |
There was a problem hiding this comment.
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
envVariableToBooleanin Metro and Re.Pack Storybook wrappers/plugins. - Gate
createChannelServer(...)behindSTORYBOOK_SERVER(defaulting totrue). - Ensure the channel server is only started when
STORYBOOK_SERVERevaluates totrue.
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.
| const disableTelemetry = optionalEnvToBoolean(process.env.STORYBOOK_DISABLE_TELEMETRY); | ||
| const server = envVariableToBoolean(process.env.STORYBOOK_SERVER, true); | ||
|
|
| } = options; | ||
|
|
||
| const disableTelemetry = optionalEnvToBoolean(process.env.STORYBOOK_DISABLE_TELEMETRY); | ||
| const server = envVariableToBoolean(process.env.STORYBOOK_SERVER, true); |
There was a problem hiding this comment.
why wouldnt we use existing channelWebsocketsEnabled?
There was a problem hiding this comment.
That's an option that's set/can be set at runtime. We'll want to have an env-variable based override for chromatic
There was a problem hiding this comment.
The reasoning is to make the old setup easier to set up with Chromatic as well.
feat: respect
STORYBOOK_SERVERenv variable in legacy metro and repack config wrappersWhat I did
The
STORYBOOK_SERVER=falseenv variable was already supported in the newer entrypoint-swappingwithStorybookpath, but was not being respected in the legacymetro/withStorybookandrepack/withStorybookconfig wrappers. This meant customers using the legacy setup who setSTORYBOOK_SERVER=falsewould still have the channel server attempt to start — causing SSL errors when no cert/key was configured:Added
envVariableToBooleansupport forSTORYBOOK_SERVERin both legacy wrappers, defaulting totruefor full backwards compatibility. The channel server is now skipped entirely whenSTORYBOOK_SERVER=false, rather than attempting to start and failing on SSL validation.How to test
STORYBOOK_SERVER=falsein your environment when using themetro/withStorybookconfig wrapper — the channel server should not start, and no SSL error should appear.STORYBOOK_SERVERset continue to work as before (default istrue).Validated via canary release
10.4.5-canary-20260529144515— multiple customers confirmed the fix resolves the SSL error without needing to remove env vars.