fix(core): replace nested CSS selectors with flat selectors in preview iframe#34057
fix(core): replace nested CSS selectors with flat selectors in preview iframe#34057mibragimov wants to merge 145 commits into
Conversation
…test-mocker-resolution Builder-Webpack5: Fix @vitest/mocker resolution issue (cherry picked from commit abd4b01)
…-init-telemetry CLI: Add init telemetry for CLI integrations (cherry picked from commit 94f79bf)
…rom-10.2.0 Release: Patch 10.2.1
…ent-agent-detection-telemetry Telemetry: Add agent detection (cherry picked from commit 945a876)
…-factories-monorepo Docs: Add FAQ about sharing config in monorepos for CSF Next (cherry picked from commit 90b7abb)
…-loginurl Composition: Handle 401 responses with loginUrl from Chromatic (cherry picked from commit afdf02a)
…vitest-prevent-double-nesting Addon-Vitest: Append Storybook project to existing test.projects array without double nesting (cherry picked from commit 5bbb915)
…vitest-support-simple-workspace-config Addon Vitest: Support simple vite.config without defineConfig helper (cherry picked from commit 751f18f)
…ckage-benchmarking Build: Fix package benchmarking (cherry picked from commit 48cecda)
…st-flake E2E: Fix flakey test (cherry picked from commit ac039aa)
…vitest-requireassertions Addon-Vitest: Update Vitest plugin configuration to disable requireAssertions for expect (cherry picked from commit b18d12e)
…rom-10.2.1 Release: Patch 10.2.2
Core: Fix `previewHref` when current path does not end with a slash (cherry picked from commit 00f506c)
…s-addon-vitest-31768 Addon-Vitest: Normalize Windows paths in addon-vitest automigration (cherry picked from commit 3802b16)
…rom-10.2.2 Release: Patch 10.2.3
…mod-windows Codemod: Fix glob pattern handling on Windows (cherry picked from commit 4d07f57)
…ories-non-interactive-mode CSFFactories: Add non-interactive mode and --glob flag (cherry picked from commit e9c8a87)
…rom-10.2.14 Release: Patch 10.2.15
…figfile-parser-warning
CSF-Factories: Fix ConfigFile parser false warning on `definePreview({...}).type<T>()` export default
(cherry picked from commit 011e081)
…etadata Core: Add vike metadata frameworks (cherry picked from commit 1fe47b7)
…et-resolution Core: Resolve builder preset path correctly in pnpm strict mode (cherry picked from commit 5c8e0ea)
…on-docs Docs: Add `allowedHosts` core config option (cherry picked from commit e81fd16)
Core: Add host/origin validation to requests and websocket connections (cherry picked from commit 7284b33)
…-hosts Core: Update default allowed hosts in host validation middleware (cherry picked from commit 0bd0483)
…rom-10.2.15 Release: Patch 10.2.16
…w iframe
The CSS nested selector syntax `* { ... }` inside `.sb-errordisplay_main`
was being incorrectly flattened by some CSS post-processors and build tools
(e.g. Vite, PostCSS) into a global `* { background: #fff; color: #000; }`
rule that leaked into the story iframe and overrode user styles.
Replace all nested CSS selectors in base-preview-head.html with flat,
fully-qualified selectors that are unambiguous and safe across all CSS
processors. The same issue applied to `.sb-nopreview_main`'s `& *` rule.
Fixes storybookjs#34036
Fixes storybookjs#33947
Fixes storybookjs#33735
📝 WalkthroughWalkthroughCSS selectors in the nopreview and error display blocks are refactored from broad/nested patterns to scoped class-specific variants. Changes target Changes
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. Comment |
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 `@code/core/assets/server/base-preview-head.html`:
- Around line 225-228: The CSS selector targeting the error stack doesn't match
the actual markup: update the rule that currently targets ".sb-errordisplay_main
.sb-errordisplay pre" so it actually matches the <pre> which has class
"sb-errordisplay_code" directly under ".sb-errordisplay_main"; change the
selector to target ".sb-errordisplay_main pre.sb-errordisplay_code" (or
".sb-errordisplay_main .sb-errordisplay_code") and keep the existing white-space
properties to ensure the error stack override is applied to the correct element.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ab0a5d23-4a98-46cf-be29-f60b2f5f6119
📒 Files selected for processing (1)
code/core/assets/server/base-preview-head.html
| .sb-errordisplay_main .sb-errordisplay pre { | ||
| white-space: pre-wrap; | ||
| white-space: revert; | ||
| } |
There was a problem hiding this comment.
Fix the pre selector; it no longer matches the error markup.
In code/core/assets/server/base-preview-body.html:84-119, the <pre> itself has class="sb-errordisplay_code" and sits directly under .sb-errordisplay_main, so .sb-errordisplay_main .sb-errordisplay pre never applies. That leaves the error stack white-space override unscoped again.
Suggested fix
- .sb-errordisplay_main .sb-errordisplay pre {
+ .sb-errordisplay_main .sb-errordisplay_code {
white-space: pre-wrap;
white-space: revert;
}📝 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.
| .sb-errordisplay_main .sb-errordisplay pre { | |
| white-space: pre-wrap; | |
| white-space: revert; | |
| } | |
| .sb-errordisplay_main .sb-errordisplay_code { | |
| white-space: pre-wrap; | |
| white-space: revert; | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@code/core/assets/server/base-preview-head.html` around lines 225 - 228, The
CSS selector targeting the error stack doesn't match the actual markup: update
the rule that currently targets ".sb-errordisplay_main .sb-errordisplay pre" so
it actually matches the <pre> which has class "sb-errordisplay_code" directly
under ".sb-errordisplay_main"; change the selector to target
".sb-errordisplay_main pre.sb-errordisplay_code" (or ".sb-errordisplay_main
.sb-errordisplay_code") and keep the existing white-space properties to ensure
the error stack override is applied to the correct element.
|
Hi @mibragimov, Due to a recent high volume of unreviewed AI-generated PRs, we are randomly requesting verification and proof that the implemented fix actually works. Please provide a simple GIF/Video or image of how the bugfix works, optimally with before-and-after comparisons. Thank you for your understanding! |
|
I am closing this PR due to the huge number of changes. Could you please open a new PR and address the feedback I had? Thank you so much for your contribution so far! |
Summary
Replace all nested CSS selectors in
base-preview-head.htmlwith flat, fully-qualified selectors to prevent a global*style leak caused by incorrect CSS nesting flattening.Root Cause
The CSS nested selector
* { background: white; color: black; }inside.sb-errordisplay_mainwas being incorrectly flattened by some CSS post-processors and build tools (e.g. Vite with CSS minification, PostCSS) into a global* { background: #fff; color: #000; }rule. This leaked out of the Storybook error display block and overrode all user styles in the preview iframe.The same problem affected
.sb-nopreview_main's& * { ... }nested rule.This is a CSS nesting syntax issue: while modern browsers support
@layer-nested CSS natively, many CSS post-processing tools (including some versions of PostCSS/cssnano/lightningcss used by Vite) do not correctly handle arbitrary nesting and may de-nest the*selector to the root scope.Fix
Replace all nested CSS selectors in
base-preview-head.htmlwith flat, explicit selectors:.sb-errordisplay_main * { ... }instead of nesting* { ... }inside.sb-errordisplay_main.sb-errordisplay_main ol { ... },.sb-errordisplay_main h1 { ... }, etc. instead of& ol,& h1nested forms.sb-nopreview_main * { ... }instead of& * { ... }inside.sb-nopreview_mainThe flat selector approach is unambiguous, universally supported, and safe across all CSS processors.
Testing
This is a static HTML/CSS file with no associated unit tests. The fix can be verified by:
base-preview-head.html* { background: ... }rule appears in the built CSSCloses #34036
Closes #33947
Closes #33735
Summary by CodeRabbit