Add --open-url flag to storybook dev#34671
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a new Changes
Sequence Diagram(s)sequenceDiagram
participant CLI as CLI
participant Dev as Dev Server
participant Env as Env (STORYBOOK_OPEN_URL)
participant Open as openInBrowser
participant Browser as Browser
CLI->>Dev: start (args may include --open-url)
Dev->>Env: read STORYBOOK_OPEN_URL
Dev->>Dev: targetUrl = options.openUrl ?? envUrl ?? defaultUrl
Dev->>Open: open(targetUrl)
Open->>Browser: attempt to open URL
Browser-->>Open: success / error
alt error and options.openUrl set
Open-->>Dev: return error
Dev->>Dev: log warning with URL and error
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Review rate limit: 6/8 reviews remaining, refill in 10 minutes and 22 seconds.Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
docs/api/cli-options.mdx (1)
56-56: ⚡ Quick winDocument
--no-openprecedence in this row too.This row explains CLI vs env precedence, but not that
--no-opendisables opening entirely. Adding that here removes ambiguity for users scanning only this option.Suggested doc tweak
-| `--open-url <url>` | Open a custom URL instead of the default local address. Useful when running a local HTTPS reverse proxy. Can also be set via the `STORYBOOK_OPEN_URL` environment variable (CLI flag takes precedence).<br />`storybook dev --open-url https://myapp.localhost` | +| `--open-url <url>` | Open a custom URL instead of the default local address. Useful when running a local HTTPS reverse proxy. It can also be set via the `STORYBOOK_OPEN_URL` environment variable (CLI flag takes precedence). Ignored when `--no-open` is set.<br />`storybook dev --open-url https://myapp.localhost` |🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@docs/api/cli-options.mdx` at line 56, Add clarification to the `--open-url <url>` docs row: state that while the CLI flag `--open-url` takes precedence over the `STORYBOOK_OPEN_URL` environment variable, the `--no-open` flag disables opening entirely and will override both `--open-url` and the env var, so users know `--no-open` wins when present; update the text for the `--open-url <url>` entry to mention `--no-open` explicitly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@code/core/src/core-server/dev-server.ts`:
- Around line 191-193: The current catch on openInBrowser(url) swallows all
errors; change it to emit a warning when the URL came from a user-provided
source (the --open-url option or STORYBOOK_OPEN_URL), so failures for custom
URLs are visible. In the catch block for openInBrowser(url) detect whether the
url was user-specified (check the flag/ENV used to set the url) and call the
project's logger (e.g., processLogger.warn) or console.warn with a short message
including the url and the caught error; keep swallowing the error for
default/open-internal cases but ensure custom URL failures produce a warning.
---
Nitpick comments:
In `@docs/api/cli-options.mdx`:
- Line 56: Add clarification to the `--open-url <url>` docs row: state that
while the CLI flag `--open-url` takes precedence over the `STORYBOOK_OPEN_URL`
environment variable, the `--no-open` flag disables opening entirely and will
override both `--open-url` and the env var, so users know `--no-open` wins when
present; update the text for the `--open-url <url>` entry to mention `--no-open`
explicitly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 66d26d8c-4385-4c1d-bd26-50f86f7a2b60
📒 Files selected for processing (4)
code/core/src/bin/core.tscode/core/src/core-server/dev-server.tscode/core/src/types/modules/core-common.tsdocs/api/cli-options.mdx
Adds a --open-url CLI flag (and STORYBOOK_OPEN_URL env var) to override the URL opened in the browser during storybook dev. Warns when the user-specified URL fails to open instead of silently swallowing the error.
c2bce65 to
9e1d8ba
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@docs/api/cli-options.mdx`:
- Line 56: The option description for `--open-url <url>` contains a sentence
fragment; revise the text so the fragment "Can also be set via the
`STORYBOOK_OPEN_URL` environment variable (CLI flag takes precedence)." is a
full sentence — e.g., change it to "It can also be set via the
`STORYBOOK_OPEN_URL` environment variable (the CLI flag takes precedence)."
Ensure the note about `--no-open` remains unchanged and keep references to
`--open-url <url>` and `STORYBOOK_OPEN_URL` intact.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 70bc7f37-c413-4676-a5a3-938a1f34ae15
📒 Files selected for processing (4)
code/core/src/bin/core.tscode/core/src/core-server/dev-server.tscode/core/src/types/modules/core-common.tsdocs/api/cli-options.mdx
🚧 Files skipped from review as they are similar to previous changes (1)
- code/core/src/core-server/dev-server.ts
| | `--smoke-test` | Exit after successful start.<br />`storybook dev --smoke-test` | | ||
| | `--ci` | CI mode (skip interactive prompts, don't open browser).<br />`storybook dev --ci` | | ||
| | `--no-open` | Do not open Storybook automatically in the browser.<br />`storybook dev --no-open` | | ||
| | `--open-url <url>` | Open a custom URL instead of the default local address. Useful when running a local HTTPS reverse proxy. Can also be set via the `STORYBOOK_OPEN_URL` environment variable (CLI flag takes precedence). Note: `--no-open` disables opening entirely and overrides both `--open-url` and the environment variable.<br />`storybook dev --open-url https://myapp.localhost` | |
There was a problem hiding this comment.
Fix sentence fragment in option description.
Line 56 has a fragment: “Can also be set via...”. Make it a complete sentence for docs clarity.
✏️ Suggested edit
-| `--open-url <url>` | Open a custom URL instead of the default local address. Useful when running a local HTTPS reverse proxy. Can also be set via the `STORYBOOK_OPEN_URL` environment variable (CLI flag takes precedence). Note: `--no-open` disables opening entirely and overrides both `--open-url` and the environment variable.<br />`storybook dev --open-url https://myapp.localhost` |
+| `--open-url <url>` | Open a custom URL instead of the default local address. Useful when running a local HTTPS reverse proxy. It can also be set via the `STORYBOOK_OPEN_URL` environment variable (CLI flag takes precedence). Note: `--no-open` disables opening entirely and overrides both `--open-url` and the environment variable.<br />`storybook dev --open-url https://myapp.localhost` |📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| | `--open-url <url>` | Open a custom URL instead of the default local address. Useful when running a local HTTPS reverse proxy. Can also be set via the `STORYBOOK_OPEN_URL` environment variable (CLI flag takes precedence). Note: `--no-open` disables opening entirely and overrides both `--open-url` and the environment variable.<br />`storybook dev --open-url https://myapp.localhost` | | |
| | `--open-url <url>` | Open a custom URL instead of the default local address. Useful when running a local HTTPS reverse proxy. It can also be set via the `STORYBOOK_OPEN_URL` environment variable (CLI flag takes precedence). Note: `--no-open` disables opening entirely and overrides both `--open-url` and the environment variable.<br />`storybook dev --open-url https://myapp.localhost` | |
🧰 Tools
🪛 LanguageTool
[style] ~56-~56: To form a complete sentence, be sure to include a subject.
Context: ...en running a local HTTPS reverse proxy. Can also be set via the `STORYBOOK_OPEN_URL...
(MISSING_IT_THERE)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@docs/api/cli-options.mdx` at line 56, The option description for `--open-url
<url>` contains a sentence fragment; revise the text so the fragment "Can also
be set via the `STORYBOOK_OPEN_URL` environment variable (CLI flag takes
precedence)." is a full sentence — e.g., change it to "It can also be set via
the `STORYBOOK_OPEN_URL` environment variable (the CLI flag takes precedence)."
Ensure the note about `--no-open` remains unchanged and keep references to
`--open-url <url>` and `STORYBOOK_OPEN_URL` intact.
|
unsure about the logging comment by 🐇, i would personally prefer having a log |
|
Also, I don't mean to create AI noise in the repo. Feel free to close this if it's adding noise. |
Summary
Adds support for a custom browser open URL in
storybook dev, so users running a local HTTPS reverse proxy (e.g. portless) can have Storybook open the proxied URL instead of the defaulthttp://localhost:<port>.--open-url <url>CLI flag tostorybook devSTORYBOOK_OPEN_URLenv var as fallback (CLI flag takes precedence)--no-openstill disables opening entirely (takes precedence over--open-url)Closes #34669
Changes
code/core/src/types/modules/core-common.ts— AddedopenUrl?: stringtoCLIOptionscode/core/src/bin/core.ts— Added CLI flag + env var fallbackcode/core/src/core-server/dev-server.ts— Use custom URL when opening browserdocs/api/cli-options.mdx— Documented the new flagTest plan
opener.test.tstests pass (6/6)build-dev.onboarding.test.tstests pass (4/4)storybook dev --open-url https://myapp.localhostopens the custom URLSTORYBOOK_OPEN_URL=https://myapp.localhost storybook devopens the custom URLstorybook dev --no-open --open-url https://myapp.localhostdoes NOT open a browserDisclosure
This PR was authored with AI assistance (Claude).
Summary by CodeRabbit
New Features
--open-url <url>CLI option to specify a custom URL when starting devSTORYBOOK_OPEN_URLenvironment variable (CLI flag takes precedence)--no-opendisables automatic opening and overrides both--open-urland the env varBug Fixes
Documentation