Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

ghengeveld
Copy link
Member

@ghengeveld ghengeveld commented Oct 7, 2025

Closes #32658

What I did

Ensure the QR code URL is a valid URL by using URL constructor rather than concatenating strings.

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>

Summary by CodeRabbit

  • UI

    • QR/share panel wording updated: title now reads "Scan to open" and description adapts by environment — a "same network" notice in development and a "view on another device" prompt in production. Tooltip layout adjusted for consistent display.
  • Tests

    • Storybook stories added/updated to preview and verify both development and production QR messaging.

Copy link
Contributor

coderabbitai bot commented Oct 7, 2025

📝 Walkthrough

Walkthrough

Threaded an isDevelopment boolean (derived from global.CONFIG_TYPE) into ShareMenu; changed QR title/description and memoization; prefer network address when building story URL; set TooltipLinkList width to 210; updated stories to set/restore CONFIG_TYPE and added a Production story.

Changes

Cohort / File(s) Change Summary
Share tool UI and behavior
code/core/src/manager/components/preview/tools/share.tsx
Added isDevelopment: boolean to ShareMenu props and invocation; changed QR title to "Scan to open"; QR description conditional on isDevelopment ("Device must be on the same network." when true, "View story on another device." when false); included isDevelopment in memoization deps; when global.STORYBOOK_NETWORK_ADDRESS exists, construct story URL via new URL(window.location.search, global.STORYBOOK_NETWORK_ADDRESS).href; set TooltipLinkList style width to 210.
Share tool stories
code/core/src/manager/components/preview/tools/share.stories.tsx
Default story beforeEach now saves original global.CONFIG_TYPE, sets it to 'DEVELOPMENT', and restores on cleanup; added Production: Story (spreads ...Default) with beforeEach that sets global.CONFIG_TYPE = 'PRODUCTION' and restores the original value; updated play assertions to expect "Scan to open".

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Global as global (CONFIG_TYPE, STORYBOOK_NETWORK_ADDRESS)
    participant Tool as Share Tool
    participant Menu as ShareMenu
    participant User as User

    Note over Global,Tool: render share tool at runtime
    Global->>Tool: provide CONFIG_TYPE & STORYBOOK_NETWORK_ADDRESS
    Tool->>Tool: isDevelopment = (CONFIG_TYPE === "DEVELOPMENT")
    alt network address present
        Tool->>Tool: url = new URL(window.location.search, STORYBOOK_NETWORK_ADDRESS).href
    else no network address
        Tool->>Tool: url = window.location.search (fallback)
    end
    Tool->>Menu: render({ isDevelopment, url, ..., tooltipStyle: { width: 210 } })
    alt isDevelopment == true
        Menu->>User: show QR + "Scan to open" + "Device must be on the same network."
    else isDevelopment == false
        Menu->>User: show QR + "Scan to open" + "View story on another device."
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-qr-url

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b7753dc and 3614922.

📒 Files selected for processing (1)
  • code/core/src/manager/components/preview/tools/share.stories.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • code/core/src/manager/components/preview/tools/share.stories.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: normal
  • GitHub Check: Core Unit Tests, windows-latest

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
code/core/src/manager/components/preview/tools/share.tsx (1)

155-157: LGTM! The URL constructor correctly fixes the invalid URL bug.

The change from string concatenation to using the URL constructor properly handles the case where STORYBOOK_NETWORK_ADDRESS already contains query parameters. When you pass a query string (e.g., ?path=/story/...) as the first argument to the URL constructor, it correctly replaces any existing query string in the base URL, preventing malformed URLs like http://host/?old=query?new=query.

Consider adding error handling for robustness.

The URL constructor throws a TypeError if STORYBOOK_NETWORK_ADDRESS is malformed. While this is likely a configuration error that should surface, consider wrapping this in a try-catch to provide a more graceful fallback:

 const storyUrl = global.STORYBOOK_NETWORK_ADDRESS
-  ? new URL(window.location.search, global.STORYBOOK_NETWORK_ADDRESS).href
+  ? (() => {
+      try {
+        return new URL(window.location.search, global.STORYBOOK_NETWORK_ADDRESS).href;
+      } catch {
+        return window.location.href;
+      }
+    })()
   : window.location.href;

Consider adding tests for this fix.

Given that this addresses a specific bug (#32658), adding tests would help prevent regressions:

  • Test with STORYBOOK_NETWORK_ADDRESS containing query params
  • Test with empty window.location.search
  • Test with malformed URLs (if error handling is added)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2e08667 and f5e412b.

📒 Files selected for processing (1)
  • code/core/src/manager/components/preview/tools/share.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Adhere to ESLint and Prettier rules across all JS/TS source files

Files:

  • code/core/src/manager/components/preview/tools/share.tsx
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Fix type errors and prefer precise typings instead of using any or suppressions, consistent with strict mode

Files:

  • code/core/src/manager/components/preview/tools/share.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Danger JS
  • GitHub Check: normal
  • GitHub Check: Core Unit Tests, windows-latest

Copy link

nx-cloud bot commented Oct 7, 2025

View your CI Pipeline Execution ↗ for commit 3614922

Command Status Duration Result
nx run-many -t build --parallel=3 ✅ Succeeded 46s View ↗

☁️ Nx Cloud last updated this comment at 2025-10-08 07:36:54 UTC

@yannbf
Copy link
Member

yannbf commented Oct 7, 2025

Awesome! While you're here, I think it would make sense to change the text when in production mode, because "Must be on the same network as this device" doesn't make a lot of sense

cc @MichaelArestad

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
code/core/src/manager/components/preview/tools/share.tsx (1)

147-147: Add isDevelopment to the useMemo dependency array.

The isDevelopment variable is used inside the useMemo hook (line 126) but is missing from the dependency array. This will cause React to use stale values when CONFIG_TYPE changes, resulting in incorrect QR section text.

Apply this diff:

-  }, [baseUrl, storyId, queryParams, copied, qrUrl, enableShortcuts, copyStoryLink]);
+  }, [baseUrl, storyId, queryParams, copied, qrUrl, enableShortcuts, copyStoryLink, isDevelopment]);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f5e412b and d405672.

📒 Files selected for processing (2)
  • code/core/src/manager/components/preview/tools/share.stories.tsx (2 hunks)
  • code/core/src/manager/components/preview/tools/share.tsx (4 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Adhere to ESLint and Prettier rules across all JS/TS source files

Files:

  • code/core/src/manager/components/preview/tools/share.stories.tsx
  • code/core/src/manager/components/preview/tools/share.tsx
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Fix type errors and prefer precise typings instead of using any or suppressions, consistent with strict mode

Files:

  • code/core/src/manager/components/preview/tools/share.stories.tsx
  • code/core/src/manager/components/preview/tools/share.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: normal
  • GitHub Check: Core Unit Tests, windows-latest
🔇 Additional comments (6)
code/core/src/manager/components/preview/tools/share.tsx (5)

85-91: LGTM!

The isDevelopment parameter is correctly typed and integrated into the function signature.


126-139: LGTM!

The conditional QR section text improves the user experience by providing context-appropriate messaging for development vs. production environments. This directly addresses the feedback about the network requirement message not making sense in production.


162-162: LGTM!

Using the URL constructor correctly handles cases where STORYBOOK_NETWORK_ADDRESS includes query paths, preventing the generation of malformed QR code URLs. This directly addresses the issue described in #32658.


164-164: LGTM!

The isDevelopment flag is correctly computed from global.CONFIG_TYPE.


170-172: LGTM!

The isDevelopment prop is correctly passed to ShareMenu via the spread syntax.

code/core/src/manager/components/preview/tools/share.stories.tsx (1)

44-50: LGTM!

The cleanup pattern correctly captures and restores the original CONFIG_TYPE, ensuring proper test isolation.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
code/core/src/manager/components/preview/tools/share.tsx (1)

149-149: Consider using styled component for consistency.

While the inline style prop works, the rest of this file uses styled components (e.g., QRContainer, QRTitle). For consistency, consider creating a styled wrapper or adding the width constraint to the styled component pattern.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4bf26dc and b7753dc.

📒 Files selected for processing (1)
  • code/core/src/manager/components/preview/tools/share.tsx (3 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Adhere to ESLint and Prettier rules across all JS/TS source files

Files:

  • code/core/src/manager/components/preview/tools/share.tsx
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Fix type errors and prefer precise typings instead of using any or suppressions, consistent with strict mode

Files:

  • code/core/src/manager/components/preview/tools/share.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: normal
  • GitHub Check: Core Unit Tests, windows-latest
🔇 Additional comments (6)
code/core/src/manager/components/preview/tools/share.tsx (6)

85-85: LGTM: isDevelopment prop properly typed.

The new prop is correctly typed and clearly named, supporting the conditional QR description logic.

Also applies to: 91-91


134-139: LGTM: Conditional QR text improves UX.

The conditional description appropriately distinguishes between development (network requirement) and production (general device access) contexts, addressing the feedback about production messaging making more sense.


147-147: LGTM: useMemo dependencies correctly updated.

The isDevelopment dependency is correctly included since it affects the QR description rendering.


161-161: LGTM: isDevelopment computation is straightforward.

The equality check against 'DEVELOPMENT' is clear. If CONFIG_TYPE is undefined or any other value, isDevelopment defaults to false, which is a sensible fallback for production-like behavior.


162-164: Excellent fix using URL constructor!

This correctly resolves the bug where string concatenation produced malformed QR URLs when STORYBOOK_NETWORK_ADDRESS contained query parameters (e.g., ?path=/onboarding).

The URL constructor properly handles:

  • Replacing the base URL's query with window.location.search when present
  • Preserving the network address scheme, host, and port
  • Avoiding malformed URLs like http://host:port/?path=/onboarding?path=/story/example

Example scenarios:

  • Base: http://192.168.1.100:6006/?path=/onboarding, Search: ?path=/story/example--default
    → Result: http://192.168.1.100:6006/?path=/story/example--default
  • Base: http://192.168.1.100:6006, Search: ?path=/story/example--default
    → Result: http://192.168.1.100:6006/?path=/story/example--default

170-172: LGTM: isDevelopment correctly passed to ShareMenu.

The prop is properly threaded through the tooltip to ShareMenu, completing the feature implementation.

@yannbf yannbf merged commit e679e44 into next Oct 8, 2025
58 checks passed
@yannbf yannbf deleted the fix-qr-url branch October 8, 2025 08:12
@github-actions github-actions bot mentioned this pull request Oct 8, 2025
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Invalid QR code URL when onboarding

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.