Skip to content

fix(scope-css): process layer selectors - #6858

Merged
johnjenkins merged 1 commit into
stenciljs:mainfrom
wessmeister:fix/scoped-css-layer-selectors
Sep 3, 2026
Merged

fix(scope-css): process layer selectors#6858
johnjenkins merged 1 commit into
stenciljs:mainfrom
wessmeister:fix/scoped-css-layer-selectors

Conversation

@wessmeister

@wessmeister wessmeister commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

What is the current behavior?

scopeCss does not traverse @layer blocks. 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, convertScopedToShadow cannot 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?

scopeCss now processes @layer alongside 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 @layer containing @media restore correctly during client hydration.

Documentation

N/A

Does this introduce a breaking change?

  • Yes
  • No

Testing

  • Added focused unit coverage for layer scoping and nested original selector annotations.
  • Ran the focused scope-css test suite, repository lint, and production build.
  • Reproduced the failure with Stencil 4.44.2 and verified the locally packed fix in Chrome 152 using the standalone reproduction.

Other information

Minimal reproduction: https://github.com/wessmeister/stencil-scoped-layer-repro

Copilot AI lite review requested due to automatic review settings September 2, 2026 16:40
@wessmeister
wessmeister requested a review from a team as a code owner September 2, 2026 16:40

Copilot AI 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.

🟢 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 @layer using the same grouping-rule handling as @media/@supports/@page/@document.
  • Make “original selector” annotations recursive through nested supported grouping rules so convertScopedToShadow can restore selectors during hydration.
  • Add unit tests covering @layer scoping 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.

Copilot AI review requested due to automatic review settings September 2, 2026 17:00
@wessmeister
wessmeister force-pushed the fix/scoped-css-layer-selectors branch from 1d7d0b0 to 943c462 Compare September 2, 2026 17:00

Copilot AI 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.

🟢 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
@wessmeister
wessmeister force-pushed the fix/scoped-css-layer-selectors branch from 943c462 to 3da65af Compare September 2, 2026 17:02
Copilot AI review requested due to automatic review settings September 2, 2026 17:02

Copilot AI 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.

🟢 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

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Runtime Benchmark

  • 9 untouched benchmarks
  • 0 improved benchmarks
  • 0 regressed benchmarks

@codspeed-hq

codspeed-hq Bot commented Sep 2, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 2 untouched benchmarks


Comparing wessmeister:fix/scoped-css-layer-selectors (3da65af) with main (7a8cc6e)

Open in CodSpeed

@johnjenkins johnjenkins 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.

lgtm - tysm!

@johnjenkins
johnjenkins added this pull request to the merge queue Sep 3, 2026
Merged via the queue into stenciljs:main with commit 635f1d4 Sep 3, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants