Bug 304555

Summary: Named Style Container Queries on :host fail for Slotted Elements
Product: WebKit Reporter: oscar7600
Component: CSSAssignee: Ahmad Saleem <ahmad.saleem792>
Status: RESOLVED FIXED    
Severity: Normal CC: afrehner.work, karlcow, koivisto, rniwa, webkit-bug-importer, woodlxf00
Priority: P2 Keywords: InRadar
Version: Safari 26   
Hardware: Unspecified   
OS: macOS 26   
URL: https://lit.dev/playground/#gist=8601556f4a13e49eb85743791f21157d
See Also: https://bugs.webkit.org/show_bug.cgi?id=289868
https://bugs.webkit.org/show_bug.cgi?id=295838
https://github.com/web-platform-tests/wpt/pull/64559
Bug Depends on:    
Bug Blocks: 148695    

oscar7600
Reported 2025-12-20 16:26:41 PST
Safari 26.2 now resolves container-name matching regardless of origin, a discrepancy remains: named style container queries defined on :host are not applied to slotted elements. While unnamed queries were recently fixed for the composed tree, https://github.com/WebKit/WebKit/commit/a20439aa1afd56e3b8e0f4af7c899ac98237fa3d, the same logic fails in Safari when a container-name is involved. Currently, ✅Chrome correctly evaluates the query, but ❌Safari (26.2 and Safari Technology Preview 234) requires the container to be defined in the Light DOM to work. Reproduction: https://lit.dev/playground/#gist=8601556f4a13e49eb85743791f21157d Steps to reproduce: 1. Open the playground in **Safari** and **Chrome**. 2. Observe that in Safari, the background color is **not** applied to the slotted element. 3. In `index.html`, uncomment the following block: ```css parent-element { /* container-name: slotted; */ } ``` 4. Notice it now works in Safari. This confirms the issue only exists when the container is defined via `:host` in the Shadow DOM. - Expected Behavior: Slotted elements should resolve container queries against a named container defined on the `:host` - Actual Behavior (Safari): Slotted elements ignore named containers defined on `:host` References - Related Fix: https://github.com/WebKit/WebKit/commit/a20439aa1afd56e3b8e0f4af7c899ac98237fa3d - Relevant Commit: https://github.com/WebKit/WebKit/commit/efd4ebe98cab2bbb385ffe1e1e40d3870917727b - Container-names are tree-scoped: https://bugs.webkit.org/show_bug.cgi?id=289868
Attachments
Anthony Frehner
Comment 1 2025-12-24 11:51:41 PST
Was able to get this down to a bare reproduction; I have a PR up to WPT to add this test case here https://github.com/web-platform-tests/wpt/pull/56899
Radar WebKit Bug Importer
Comment 2 2025-12-27 16:27:12 PST
Anthony Frehner
Comment 3 2025-12-27 16:51:40 PST
Also I plan on fixing this once the WPT addition is merged.
Woody Lee
Comment 4 2026-09-02 18:44:38 PDT
The WPT PR appears to be making no progress. Could you consider fix the issue first?
Ahmad Saleem
Comment 5 2026-10-16 15:53:11 PDT
EWS
Comment 6 2026-11-02 07:35:46 PST
Committed 325470@main (a83e135fd2f0): <https://commits.webkit.org/325470@main> Reviewed commits have been landed. Closing PR #77329 and removing active labels.
Ahmad Saleem
Comment 7 2026-11-02 07:55:51 PST
Submitted web-platform-tests pull request: https://github.com/web-platform-tests/wpt/pull/64559
Anthony Frehner
Comment 8 2026-11-04 15:28:35 PST

Ahmad -- thanks for you work here! However, I was testing this out with a local build and noticed that a named container still fails! E.g. see this example below:

<div>
  <template shadowrootmode="open">
    <style>
      :host { display: block; width: 300px; container: --foo / inline-size; }
    </style>
    <slot></slot>
  </template>
  <div>
    <template shadowrootmode="open">
      <style>
        div { width: 100px; height: 100px; background-color: red; }
        @container --foo (width > 0) {
          div { background-color: green; }
        }
      </style>
      <div></div>
    </template>
  </div>
</div>
Ahmad Saleem
Comment 9 2026-11-19 00:17:46 PST

(In reply to Anthony Frehner from comment #8)

Ahmad -- thanks for you work here! However, I was testing this out with a
local build and noticed that a named container still fails! E.g. see this
example below:

<div>
  <template shadowrootmode="open">
    <style>
      :host { display: block; width: 300px; container: --foo / inline-size; }
    </style>
    <slot></slot>
  </template>
  <div>
    <template shadowrootmode="open">
      <style>
        div { width: 100px; height: 100px; background-color: red; }
        @container --foo (width > 0) {
          div { background-color: green; }
        }
      </style>
      <div></div>
    </template>
  </div>
</div>

(In reply to Anthony Frehner from comment #8)

Ahmad -- thanks for you work here! However, I was testing this out with a
local build and noticed that a named container still fails! E.g. see this
example below:

<div>
  <template shadowrootmode="open">
    <style>
      :host { display: block; width: 300px; container: --foo / inline-size; }
    </style>
    <slot></slot>
  </template>
  <div>
    <template shadowrootmode="open">
      <style>
        div { width: 100px; height: 100px; background-color: red; }
        @container --foo (width > 0) {
          div { background-color: green; }
        }
      </style>
      <div></div>
    </template>
  </div>
</div>

Is it something you are going to tackle or is it up for grab? Happy to look into it.

Anthony Frehner
Comment 10 2026-11-19 07:22:38 PST

(In reply to Ahmad Saleem from comment #9)

(In reply to Anthony Frehner from comment #8)

Ahmad -- thanks for you work here! However, I was testing this out with a
local build and noticed that a named container still fails! E.g. see this
example below:

<div>
  <template shadowrootmode="open">
    <style>
      :host { display: block; width: 300px; container: --foo / inline-size; }
    </style>
    <slot></slot>
  </template>
  <div>
    <template shadowrootmode="open">
      <style>
        div { width: 100px; height: 100px; background-color: red; }
        @container --foo (width > 0) {
          div { background-color: green; }
        }
      </style>
      <div></div>
    </template>
  </div>
</div>

(In reply to Anthony Frehner from comment #8)

Ahmad -- thanks for you work here! However, I was testing this out with a
local build and noticed that a named container still fails! E.g. see this
example below:

<div>
  <template shadowrootmode="open">
    <style>
      :host { display: block; width: 300px; container: --foo / inline-size; }
    </style>
    <slot></slot>
  </template>
  <div>
    <template shadowrootmode="open">
      <style>
        div { width: 100px; height: 100px; background-color: red; }
        @container --foo (width > 0) {
          div { background-color: green; }
        }
      </style>
      <div></div>
    </template>
  </div>
</div>

Is it something you are going to tackle or is it up for grab? Happy to look
into it.

I'm on it:

325656 and 331279 are both filed, and both have associated PRs up for them. :)

Note You need to log in before you can comment on or make changes to this bug.