<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>304555</bug_id>
          
          <creation_ts>2025-12-20 16:26:41 -0800</creation_ts>
          <short_desc>Named Style Container Queries on :host fail for Slotted Elements</short_desc>
          <delta_ts>2026-11-19 07:22:38 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>CSS</component>
          <version>Safari 26</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>macOS 26</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=289868</see_also>
    
    <see_also>https://bugs.webkit.org/show_bug.cgi?id=295838</see_also>
    
    <see_also>https://github.com/web-platform-tests/wpt/pull/64559</see_also>
          <bug_file_loc>https://lit.dev/playground/#gist=8601556f4a13e49eb85743791f21157d</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>148695</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter>oscar7600</reporter>
          <assigned_to name="Ahmad Saleem">ahmad.saleem792</assigned_to>
          <cc>afrehner.work</cc>
    
    <cc>karlcow</cc>
    
    <cc>koivisto</cc>
    
    <cc>rniwa</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>woodlxf00</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2167583</commentid>
    <comment_count>0</comment_count>
    <who name="">oscar7600</who>
    <bug_when>2025-12-20 16:26:41 -0800</bug_when>
    <thetext>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</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2168094</commentid>
    <comment_count>1</comment_count>
    <who name="Anthony Frehner">afrehner.work</who>
    <bug_when>2025-12-24 11:51:41 -0800</bug_when>
    <thetext>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</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2168374</commentid>
    <comment_count>2</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2025-12-27 16:27:12 -0800</bug_when>
    <thetext>&lt;rdar://problem/167244007&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2168377</commentid>
    <comment_count>3</comment_count>
    <who name="Anthony Frehner">afrehner.work</who>
    <bug_when>2025-12-27 16:51:40 -0800</bug_when>
    <thetext>Also I plan on fixing this once the WPT addition is merged.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2246596</commentid>
    <comment_count>4</comment_count>
    <who name="Woody Lee">woodlxf00</who>
    <bug_when>2026-09-02 18:44:38 -0700</bug_when>
    <thetext>The WPT PR appears to be making no progress.
Could you consider fix the issue first?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2265305</commentid>
    <comment_count>5</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2026-10-16 15:53:11 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/77329</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2272951</commentid>
    <comment_count>6</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2026-11-02 07:35:46 -0800</bug_when>
    <thetext>Committed 325470@main (a83e135fd2f0): &lt;https://commits.webkit.org/325470@main&gt;

Reviewed commits have been landed. Closing PR #77329 and removing active labels.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2272957</commentid>
    <comment_count>7</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2026-11-02 07:55:51 -0800</bug_when>
    <thetext>Submitted web-platform-tests pull request: https://github.com/web-platform-tests/wpt/pull/64559</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2274570</commentid>
    <comment_count>8</comment_count>
    <who name="Anthony Frehner">afrehner.work</who>
    <bug_when>2026-11-04 15:28:35 -0800</bug_when>
    <thetext>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: 

```
&lt;div&gt;
  &lt;template shadowrootmode=&quot;open&quot;&gt;
    &lt;style&gt;
      :host { display: block; width: 300px; container: --foo / inline-size; }
    &lt;/style&gt;
    &lt;slot&gt;&lt;/slot&gt;
  &lt;/template&gt;
  &lt;div&gt;
    &lt;template shadowrootmode=&quot;open&quot;&gt;
      &lt;style&gt;
        div { width: 100px; height: 100px; background-color: red; }
        @container --foo (width &gt; 0) {
          div { background-color: green; }
        }
      &lt;/style&gt;
      &lt;div&gt;&lt;/div&gt;
    &lt;/template&gt;
  &lt;/div&gt;
&lt;/div&gt;
```</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2282762</commentid>
    <comment_count>9</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2026-11-19 00:17:46 -0800</bug_when>
    <thetext>(In reply to Anthony Frehner from comment #8)
&gt; Ahmad -- thanks for you work here! However, I was testing this out with a
&gt; local build and noticed that a _named_ container still fails! E.g. see this
&gt; example below: 
&gt; 
&gt; ```
&gt; &lt;div&gt;
&gt;   &lt;template shadowrootmode=&quot;open&quot;&gt;
&gt;     &lt;style&gt;
&gt;       :host { display: block; width: 300px; container: --foo / inline-size; }
&gt;     &lt;/style&gt;
&gt;     &lt;slot&gt;&lt;/slot&gt;
&gt;   &lt;/template&gt;
&gt;   &lt;div&gt;
&gt;     &lt;template shadowrootmode=&quot;open&quot;&gt;
&gt;       &lt;style&gt;
&gt;         div { width: 100px; height: 100px; background-color: red; }
&gt;         @container --foo (width &gt; 0) {
&gt;           div { background-color: green; }
&gt;         }
&gt;       &lt;/style&gt;
&gt;       &lt;div&gt;&lt;/div&gt;
&gt;     &lt;/template&gt;
&gt;   &lt;/div&gt;
&gt; &lt;/div&gt;
&gt; ```

(In reply to Anthony Frehner from comment #8)
&gt; Ahmad -- thanks for you work here! However, I was testing this out with a
&gt; local build and noticed that a _named_ container still fails! E.g. see this
&gt; example below: 
&gt; 
&gt; ```
&gt; &lt;div&gt;
&gt;   &lt;template shadowrootmode=&quot;open&quot;&gt;
&gt;     &lt;style&gt;
&gt;       :host { display: block; width: 300px; container: --foo / inline-size; }
&gt;     &lt;/style&gt;
&gt;     &lt;slot&gt;&lt;/slot&gt;
&gt;   &lt;/template&gt;
&gt;   &lt;div&gt;
&gt;     &lt;template shadowrootmode=&quot;open&quot;&gt;
&gt;       &lt;style&gt;
&gt;         div { width: 100px; height: 100px; background-color: red; }
&gt;         @container --foo (width &gt; 0) {
&gt;           div { background-color: green; }
&gt;         }
&gt;       &lt;/style&gt;
&gt;       &lt;div&gt;&lt;/div&gt;
&gt;     &lt;/template&gt;
&gt;   &lt;/div&gt;
&gt; &lt;/div&gt;
&gt; ```

Is it something you are going to tackle or is it up for grab? Happy to look into it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2282886</commentid>
    <comment_count>10</comment_count>
    <who name="Anthony Frehner">afrehner.work</who>
    <bug_when>2026-11-19 07:22:38 -0800</bug_when>
    <thetext>(In reply to Ahmad Saleem from comment #9)
&gt; (In reply to Anthony Frehner from comment #8)
&gt; &gt; Ahmad -- thanks for you work here! However, I was testing this out with a
&gt; &gt; local build and noticed that a _named_ container still fails! E.g. see this
&gt; &gt; example below: 
&gt; &gt; 
&gt; &gt; ```
&gt; &gt; &lt;div&gt;
&gt; &gt;   &lt;template shadowrootmode=&quot;open&quot;&gt;
&gt; &gt;     &lt;style&gt;
&gt; &gt;       :host { display: block; width: 300px; container: --foo / inline-size; }
&gt; &gt;     &lt;/style&gt;
&gt; &gt;     &lt;slot&gt;&lt;/slot&gt;
&gt; &gt;   &lt;/template&gt;
&gt; &gt;   &lt;div&gt;
&gt; &gt;     &lt;template shadowrootmode=&quot;open&quot;&gt;
&gt; &gt;       &lt;style&gt;
&gt; &gt;         div { width: 100px; height: 100px; background-color: red; }
&gt; &gt;         @container --foo (width &gt; 0) {
&gt; &gt;           div { background-color: green; }
&gt; &gt;         }
&gt; &gt;       &lt;/style&gt;
&gt; &gt;       &lt;div&gt;&lt;/div&gt;
&gt; &gt;     &lt;/template&gt;
&gt; &gt;   &lt;/div&gt;
&gt; &gt; &lt;/div&gt;
&gt; &gt; ```
&gt; 
&gt; (In reply to Anthony Frehner from comment #8)
&gt; &gt; Ahmad -- thanks for you work here! However, I was testing this out with a
&gt; &gt; local build and noticed that a _named_ container still fails! E.g. see this
&gt; &gt; example below: 
&gt; &gt; 
&gt; &gt; ```
&gt; &gt; &lt;div&gt;
&gt; &gt;   &lt;template shadowrootmode=&quot;open&quot;&gt;
&gt; &gt;     &lt;style&gt;
&gt; &gt;       :host { display: block; width: 300px; container: --foo / inline-size; }
&gt; &gt;     &lt;/style&gt;
&gt; &gt;     &lt;slot&gt;&lt;/slot&gt;
&gt; &gt;   &lt;/template&gt;
&gt; &gt;   &lt;div&gt;
&gt; &gt;     &lt;template shadowrootmode=&quot;open&quot;&gt;
&gt; &gt;       &lt;style&gt;
&gt; &gt;         div { width: 100px; height: 100px; background-color: red; }
&gt; &gt;         @container --foo (width &gt; 0) {
&gt; &gt;           div { background-color: green; }
&gt; &gt;         }
&gt; &gt;       &lt;/style&gt;
&gt; &gt;       &lt;div&gt;&lt;/div&gt;
&gt; &gt;     &lt;/template&gt;
&gt; &gt;   &lt;/div&gt;
&gt; &gt; &lt;/div&gt;
&gt; &gt; ```
&gt; 
&gt; Is it something you are going to tackle or is it up for grab? Happy to look
&gt; into it.

I&apos;m on it: 

325656 and 331279 are both filed, and both have associated PRs up for them. :)</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>