Bug 327165

Summary: @scope rules in a shadow root don't apply to elements slotted into a nested shadow host
Product: WebKit Reporter: 709922234
Component: CSSAssignee: Nobody <webkit-unassigned>
Status: NEW    
Severity: Normal CC: ahmad.saleem792, koivisto, nipun_shukla, rniwa, webkit-bug-importer
Priority: P2 Keywords: BrowserCompat, InRadar
Version: Safari 27   
Hardware: All   
OS: All   
URL: https://software.hixie.ch/utilities/js/live-dom-viewer/?saved=14964
Bug Depends on:    
Bug Blocks: 148695    

709922234
Reported 2026-10-11 12:03:43 PDT
Follow-up to bug 308330 (fixed in 311333@main). That fix works when the @scope rule is in a document-level stylesheet, but the same problem still happens when the @scope rule is in a stylesheet of a shadow root and the matched element is slotted into another shadow host inside that shadow root. Testcase: ```html <!DOCTYPE html> <script> customElements.define('x-page', class extends HTMLElement { constructor() { super(); this.attachShadow({ mode: 'open' }).innerHTML = '<slot></slot>'; } }); </script> <div id="host"></div> <script> const root = host.attachShadow({ mode: 'open' }); root.innerHTML = ` <style>@scope (.a) { .t { color: red; } }</style> <div class="a"> <x-page><span class="t" id="slotted">Slotted: should be red</span></x-page> <span class="t" id="plain">Not slotted: red</span> </div>`; console.log( getComputedStyle(root.getElementById('slotted')).color, getComputedStyle(root.getElementById('plain')).color, ); </script> ``` Expected: both spans are red (as in Chrome). Actual: the slotted span is not styled (rgb(0, 0, 0)); the non-slotted one is red. Notes: - Same result with adoptedStyleSheets on the shadow root instead of <style>. - Same result with `@scope (.a) { :scope .t {} }`, with a scope limit (`to (...)`), and when the scoping root is the shadow host x-page itself. Descendants of the slotted element are not styled either. - A plain descendant selector (`.a .t { color: red }`) in the same shadow root works. - The same markup at the document level (no outer shadow root) works, i.e. the 308330 fix. Reproduced on macOS 27.0.1 (WKWebView) and seen on iOS 27 in a WKWebView app. Real-world impact: frameworks that compile light DOM component styles to @scope (e.g. Gem) lose all component styles when those components are rendered inside a shadow root and slotted into another component, e.g. content of a bottom sheet component.
Attachments
Radar WebKit Bug Importer
Comment 1 2026-10-18 12:04:15 PDT
Ahmad Saleem
Comment 2 2026-12-02 19:47:19 PST

It reproduces on Safari Technology Preview 257 as well.

Ahmad Saleem
Comment 3 2026-12-02 19:48:15 PST

Firefox Nightly 163 (20261201213352) and Chrome Canary 161.0.8196.0 (Official Build) canary (arm64) does not have this bug.

Nipun Shukla
Comment 4 2026-12-03 10:53:42 PST
Note You need to log in before you can comment on or make changes to this bug.