Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

core(preview-web): restore documentElement when entering Docs to prevent decorator bleed (#33112)#33213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
sarahhassaballa wants to merge1 commit intostorybookjs:next
base:next
Choose a base branch
Loading
fromsarahhassaballa:fix/webview-restore-docs-33112

Conversation

@sarahhassaballa
Copy link

Closes#33112

What I did

Fixed an issue where decorators that mutate document.documentElement (e.g., for theming or RTL support) were bleeding into Docs view when navigating from Canvas to Docs.

The fix:

  • WebView now snapshots documentElement attributes (dir, lang, class, data-theme, style) on initialization (clean state).
  • When switching to Docs view via prepareForDocs(), it restores the snapshot to prevent decorator mutations from bleeding through.
  • Added execution safety checks (typeof document !== 'undefined') to ensure this logic is skipped in SSR or non-browser test environments.
  • This is a framework-agnostic core fix that applies to all renderers.

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!

Manual testing performed:

  1. Created decorators in sandbox that mutate document.documentElement:
  • Set dir="rtl" for RTL layout
  • Set data-theme="dark" for dark theme
  • Applied only in Canvas view (story mode)
  1. Verified in Canvas:
  • Dark background appears
  • RTL layout is active
  • Browser console shows document.documentElement.dir === "rtl"
  1. Switched to Docs tab:
  • Light background (no dark theme bleed)
  • LTR layout (no RTL bleed)
  • Browser console shows document.documentElement.dir === "" (clean)
  1. Switched back to Canvas:
  • Dark theme and RTL persist correctly

Visual Verification of Fix:

1. Canvas View (Dirty State)
Decorators applydir="rtl" anddata-theme="dark". Verified in DevTools.
Screenshot 2025-11-27 233822
Screenshot 2025-11-27 234010

2. Docs View (Clean State)
Switched to Docs tab. Verified thatdir anddata-theme were removed from<html> by the cleanup logic.
Screenshot 2025-11-27 233732
Screenshot 2025-11-27 234033

Unit test verification:

  • PreviewWeb.test.ts: Test validates that prepareForDocs() is called on view-mode transitions
  • Locally: yarn vitest runPreviewWeb.test.ts -t "cleans up document.documentElement"

Documentation

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

No documentation changes needed, as this is an internal fix that prevents unintended side effects. No API changes or user-facing configuration required.

Checklist for Maintainers

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

  • [] Make sure this PR containsone 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: Documentationonly 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.

Suggested label: bug - This fixes incorrect behavior where decorator mutations were bleeding into Docs view.

🦋 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 releasehere or locally withgh workflow run --repo storybookjs/storybook publish.yml --field pr=<PR_NUMBER>

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[Bug]: Decorator modifying document.documentElement affects Docs UI when switching from Playground

1 participant

@sarahhassaballa

[8]ページ先頭

©2009-2025 Movatter.jp