Skip to content

UI: Fix args not preserved in isolation mode#35055

Merged
Sidnioulz merged 13 commits into
storybookjs:nextfrom
sijie-Z:fix/isolation-mode-args
Jun 16, 2026
Merged

UI: Fix args not preserved in isolation mode#35055
Sidnioulz merged 13 commits into
storybookjs:nextfrom
sijie-Z:fix/isolation-mode-args

Conversation

@sijie-Z

@sijie-Z sijie-Z commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

fixes #35047

What I did

Fixed the "Open in isolation mode" button to preserve the args query parameter when opening the iframe URL. Added
inheritArgs: true to the getStoryHrefs call in share.tsx.

Manual testing

  1. Run a sandbox: yarn task --task sandbox --start-from auto --template react-vite/default-ts
  2. Open Storybook in your browser
  3. Select a story and modify its args
  4. Click "Open in isolation mode" from the top right menu
  5. Verify the iframe URL contains the args parameter

Summary by CodeRabbit

  • Bug Fixes

    • Isolation mode now includes inherited arguments when opening a story in isolation, so shared/opened pages reflect current control values.
  • Tests

    • Added end-to-end test verifying that editing controls updates the preview URL and that the opened isolation page preserves those args and rendered content.

@sijie-Z sijie-Z changed the title fix: preserve args when opening story in isolation mode UI: Fix args not preserved in isolation mode Jun 4, 2026
@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Isolation mode tool now requests origin hrefs with inherited args enabled. A new e2e test verifies that opening a story in isolation mode preserves the story's updated argument values in both the isolated window URL and rendered content.

Changes

Isolation Mode Tool + Test

Layer / File(s) Summary
Isolation mode tool — inherit args in href generation
code/core/src/manager/components/preview/tools/share.tsx
The api.getStoryHrefs call adds inheritArgs: true to the options, ensuring the generated origin preview href includes inherited argument values in the isolation-mode action payload.
E2E test: isolation mode preserves args
code/e2e-sandbox/manager.spec.ts
New Playwright test updates a story control value, opens the story in isolation mode, and verifies the isolated window URL and rendered content both preserve the updated argument.

Sequence Diagram(s)

sequenceDiagram
  participant Manager
  participant API
  participant Window
  Manager->>API: getStoryHrefs(storyId, { base: 'origin', refId, inheritArgs: true })
  API-->>Manager: originHrefs (previewHref includes inherited args)
  Manager->>Window: window.open(originHrefs.previewHref, ...)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • storybookjs/storybook#33766: The share.tsx change to generate originHrefs.previewHref with inherited args directly affects the SHARE_ISOLATE_MODE event payload emitted by telemetry tracking.

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.

❤️ Share

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

@sijie-Z

sijie-Z commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

Hi maintainers! This is my first contribution. I don't have permission to add labels. Could you please add the
following labels:

  • bug
  • ci:normal
  • qa:needed

The manual testing section is already included in the PR description. Thank you!

@Sidnioulz Sidnioulz self-assigned this Jun 5, 2026
@Sidnioulz Sidnioulz added the ci:normal Run our default set of CI jobs (choose this for most PRs). label Jun 5, 2026

@Sidnioulz Sidnioulz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the PR. Could you please add an E2E test to the test suite in core, that shows this bug is fixed?

@Sidnioulz Sidnioulz added bug qa:skip Pull Requests that do not need any QA. labels Jun 5, 2026
@Sidnioulz Sidnioulz moved this to On Hold in Core Team Projects Jun 5, 2026
@storybook-app-bot

storybook-app-bot Bot commented Jun 5, 2026

Copy link
Copy Markdown

Package Benchmarks

Commit: 129c631, ran on 15 June 2026 at 06:55:41 UTC

No significant changes detected, all good. 👏

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@code/e2e-tests/manager.spec.ts`:
- Line 252: The test's page.waitForURL call assumes spaces are encoded as '+'
(e.g. 'args=label:Hello+world') which can be '%20' in some environments; update
the wait/assertion around page.waitForURL to be encoding-agnostic by retrieving
the URL (via page.url() or by using page.waitForURL with a predicate), decoding
the query component (using decodeURIComponent on the query or parsing with
URLSearchParams), and then asserting that the decoded 'args' value equals or
includes 'label:Hello world' (or alternatively use a regex in page.waitForURL
that accepts both '\\+' and '%20' for the page.waitForURL call referencing the
same 'args=label:Hello+world' literal).
🪄 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: c033ebc3-9fe3-4b20-aaa3-d0959fa50896

📥 Commits

Reviewing files that changed from the base of the PR and between e97d99b and cb7c3be.

📒 Files selected for processing (1)
  • code/e2e-tests/manager.spec.ts

Comment thread code/e2e-tests/manager.spec.ts Outdated
@sijie-Z

sijie-Z commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai Fixed the URL encoding assumption. Now using decodeURIComponent to handle both + and %20
encodings.

@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
cat code/e2e-tests/manager.spec.ts | grep -A 50 -B 5 "isolation mode preserves\|Isolation mode\|decodeURIComponent\|inheritArgs\|args"

Length of output: 3802



@sijie-Z Thanks for the update! The fix looks good — decodeURIComponent is applied consistently in both the waitForURL callback and the final assertion, which correctly handles percent-encoded spaces (%20). Note that URLSearchParams.get() already decodes both + and %20 to plain spaces, so the decodeURIComponent call is a safe extra layer that makes the intent explicit without any side effects. The test logic is solid.


🧠 Learnings used
Learnt from: psychobolt
Repo: storybookjs/storybook PR: 0
File: :0-0
Timestamp: 2026-03-21T17:23:03.931Z
Learning: In storybookjs/storybook PR `#34025`, `code/addons/vitest/src/vitest-plugin/index.ts` has a Windows-specific bug: `previewOrConfigFile` (an absolute filesystem path like `d:\...\preview.ts`) is incorrectly passed through `import.meta.resolve()`, which only accepts package specifiers or `file://` URLs, causing `TypeError: The URL must be of scheme file` on Windows with CSF4 setups. The fix is to check `path.isAbsolute(filePath)` and return absolute paths as-is, only calling `fileURLToPath(import.meta.resolve(filePath))` for package specifiers.

Learnt from: Sidnioulz
Repo: storybookjs/storybook PR: 32458
File: code/core/src/components/components/Tabs/Tabs.stories.tsx:222-227
Timestamp: 2025-11-05T09:36:55.944Z
Learning: Repo: storybookjs/storybook PR: 32458 — In code/core/src/components/components/Button/Button.tsx (React/TypeScript), ButtonProps includes ariaLabel?: string | false and the component maps it to the DOM aria-label. Convention: ariaLabel is mandatory on all Button usages — provide a descriptive string for icon-only buttons; set ariaLabel=false when the button’s children already serve as the accessible name. Do not suggest using a raw aria-label prop on Button call sites.

If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

@sijie-Z

sijie-Z commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

@Sidnioulz Done! Added the E2E test. Also addressed the CodeRabbit feedback about URL encoding — now using
decodeURIComponent for robust assertions.

sijie-Z and others added 3 commits June 5, 2026 11:52
When clicking 'Open in isolation mode', the args query parameter was not
being passed to the iframe URL. This happened because getStoryHrefs
defaults inheritArgs to isCurrentStory, which could be false in certain
situations.

Fixed by explicitly passing inheritArgs: true when calling getStoryHrefs
from the isolation mode button.

Fixes storybookjs#35047
Updated URL handling to include robust decoding logic for args.
@Sidnioulz Sidnioulz force-pushed the fix/isolation-mode-args branch from 21c4340 to a964586 Compare June 5, 2026 09:52
@Sidnioulz Sidnioulz self-requested a review June 5, 2026 18:25

@Sidnioulz Sidnioulz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you please check the E2E test failures in CI? Thanks!

Replace waitForLoadState with waitForSelector to ensure button is rendered before proceeding.
@sijie-Z

sijie-Z commented Jun 6, 2026

Copy link
Copy Markdown
Contributor Author

@Sidnioulz Thanks for catching that. The issue was waitForLoadState() — it only waits for the HTML to load, not for the Storybook preview JS to render the story. Fixed by explicitly waiting for #storybook-root button to appear before asserting.

sijie-Z added 3 commits June 6, 2026 16:06
- Replace strict 'button' tag selectors with generic text locators (`getByText`) to support multi-framework sandboxes (Lit, Angular, etc.).
- Update isolation page wait condition to look for any child element under `#storybook-root` to prevent CI timeouts.
- Clean up internal comments to maintain project linting rules.
@sijie-Z

sijie-Z commented Jun 7, 2026

Copy link
Copy Markdown
Contributor Author

@Sidnioulz Hi! I've fixed the E2E test failures. CI checks seem stuck — could you help re-trigger the workflow when you get a chance? Thanks!

Comment thread code/core/src/manager/components/preview/tools/share.tsx Outdated
@Sidnioulz

Copy link
Copy Markdown
Contributor

@Sidnioulz Hi! I've fixed the E2E test failures. CI checks seem stuck — could you help re-trigger the workflow when you get a chance? Thanks!

I'm on it! Thanks for the ping!

Comment thread code/e2e-sandbox/manager.spec.ts Outdated
@Sidnioulz

Copy link
Copy Markdown
Contributor

@sijie-Z did you manage to run the E2E tests locally, by the way? Would you like some help / instructions to know how to run them locally on your machine?

@sijie-Z sijie-Z force-pushed the fix/isolation-mode-args branch from 3f28ddf to ed26d4e Compare June 8, 2026 11:37
@sijie-Z

sijie-Z commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

Yep, just ran them. Looks like the test is failing because customQueryParams isn't updated yet when the button is clicked. I'll fix the test and push an update.

@sijie-Z

sijie-Z commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

@Sidnioulz I dug into this a bit more.

customQueryParams is updated from the STORY_ARGS_UPDATED handler via requestIdleCallback (with a 1000ms timeout), so the update is intentionally deferred.

I also noticed that the isolation link's mapper only subscribes to api, storyId, and refId, not customQueryParams. The href is then computed during render via getStoryHrefs(...) and reused from the click handler.

Given that, I think the failing test may be exposing a real issue in how updated args are propagated to the isolation link, rather than being purely a timing issue in the test.

Does that match your understanding, or am I missing another path that would cause the link to be recomputed?

sijie-Z added 2 commits June 14, 2026 21:17
The isolation URL could be generated before
customQueryParams had been updated from
STORY_ARGS_UPDATED.

Since getStoryHrefs() returns concrete URL strings,
the generated href could become stale and miss
recently updated args.

Compute the href when the button is clicked so it
always uses the latest query params from the store.
searchParams.get() already decodes percent-encoded
sequences, and decodeURIComponent does not decode
+ to space, causing the assertion to fail on
Storybook's URL encoding convention where spaces
are represented as +.
@sijie-Z

sijie-Z commented Jun 14, 2026

Copy link
Copy Markdown
Contributor Author

Fixed and updated.

The original isolation-mode issue is now resolved, and the related dev/e2e checks are passing.

The remaining CircleCI failure appears to be unrelated to this change and comes from SvelteKit sandbox creation (No svelte.config.js or svelte.config.ts found).

@Sidnioulz

Copy link
Copy Markdown
Contributor

Does that match your understanding, or am I missing another path that would cause the link to be recomputed?

Sorry I missed your reply! Don't hesitate to come have a discussion on https://discord.gg/invite/storybook (channel #contributing) if we miss your questions on an open PR. We get a lot of notifications so we occasionally miss a few.

I don't know this product area well enough. I can ask the rest of the team if you're stuck, but it looks like you've updated your PR since so I'm first gonna review that :)

@Sidnioulz Sidnioulz merged commit beab22c into storybookjs:next Jun 16, 2026
133 checks passed
@github-project-automation github-project-automation Bot moved this from On Hold to Done in Core Team Projects Jun 16, 2026
@sijie-Z sijie-Z deleted the fix/isolation-mode-args branch June 18, 2026 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-scan:automated bug ci:normal Run our default set of CI jobs (choose this for most PRs). qa:skip Pull Requests that do not need any QA.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Bug]: "Open in isolation mode" is broken with Storybook (a deployed / local versions)

3 participants