fix(scope-css): process layer selectors - #6858
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The change is narrowly scoped, consistent with existing grouping-rule handling, and includes targeted unit tests for both scoping and selector-annotation recursion.
Pull request overview
This PR fixes scopeCss scoping and selector-annotation behavior inside @layer blocks so that scoped CSS is generated consistently and hydration can correctly restore original selectors (e.g., :host) even when rules are nested inside grouping at-rules.
Changes:
- Extend selector scoping to recurse into
@layerusing the same grouping-rule handling as@media/@supports/@page/@document. - Make “original selector” annotations recursive through nested supported grouping rules so
convertScopedToShadowcan restore selectors during hydration. - Add unit tests covering
@layerscoping and nested grouping-rule selector preservation.
File summaries
| File | Description |
|---|---|
| src/utils/shadow-css.ts | Adds @layer to the set of grouping at-rules traversed during scoping and recursively annotates selectors through nested grouping rules. |
| src/utils/test/scope-css.spec.ts | Adds unit coverage for scoping inside @layer and preserving original selectors through nested grouping rules. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
1d7d0b0 to
943c462
Compare
There was a problem hiding this comment.
🟢 Approval recommended
The change is narrowly scoped, uses a single shared predicate for grouping rules, and is backed by both unit tests and an SSR hydration fixture update covering the reported failure mode.
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 0 new
- Review effort level: Lite
Recurse through cascade layer blocks when scoping component CSS and preserve original selector annotations through nested grouping rules. This lets scoped SSR hydration restore selectors such as :host. fixes: stenciljs#6857
943c462 to
3da65af
Compare
There was a problem hiding this comment.
🟢 Approval recommended
The change is narrowly scoped, aligns with existing at-rule traversal behavior, and is backed by focused unit tests for the reported failure mode.
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0 new
- Review effort level: Lite
Runtime Benchmark
|
What is the current behavior?
scopeCssdoes not traverse@layerblocks. Selectors for elements inside a layer are therefore left unscoped.This also affects shadow components rendered with
serializeShadowRoot: 'scoped'. Their server generated CSS omits the original selector annotation inside@layer. During client hydration,convertScopedToShadowcannot restore selectors such as:host, so the shadow stylesheet retains a scoped class that cannot match the host and its styles stop applying.GitHub Issue Number: #6857
What is the new behavior?
scopeCssnow processes@layeralongside its other supported grouping rules. The same predicate is used when scoping selectors and preserving original selector annotations. Annotation also recurses through nested supported grouping rules, so combinations such as@layercontaining@mediarestore correctly during client hydration.Documentation
N/A
Does this introduce a breaking change?
Testing
scope-csstest suite, repository lint, and production build.Other information
Minimal reproduction: https://github.com/wessmeister/stencil-scoped-layer-repro