feat: enhance Storybook server configuration with environment variable support#894
feat: enhance Storybook server configuration with environment variable support#894ndelangen wants to merge 5 commits into
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: 9b3ae30 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); | ||
|
|
| 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, |
| // 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); |
There was a problem hiding this comment.
why wouldnt we use existing channelWebsocketsEnabled?
envVariableToBooleanimport to bothwithStorybook.tsfiles.STORYBOOK_SERVERenvironment variable to control the creation of the channel server.STORYBOOK_SERVERvariable is true.Issue:
What I did
How to test
Please explain how to test your changes and consider the following questions
If your answer is yes to any of these, please make sure to include it in your PR.