<?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>249080</bug_id>
          
          <creation_ts>2022-12-10 15:07:08 -0800</creation_ts>
          <short_desc>CSS selectors should not pierce the shadow root created by the SVG &lt;use&gt; element</short_desc>
          <delta_ts>2026-04-22 02:01:05 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>SVG</component>
          <version>Safari Technology Preview</version>
          <rep_platform>Mac (Apple Silicon)</rep_platform>
          <op_sys>macOS 12</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>179724</dup_id>
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=303998</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>BrowserCompat, InRadar, LayerBasedSVGEngine</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>148695</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Jed Fox">jed</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ahmad.saleem792</cc>
    
    <cc>arif.hossain.9213</cc>
    
    <cc>karlcow</cc>
    
    <cc>rniwa</cc>
    
    <cc>sabouhallawa</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>zimmermann</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1918220</commentid>
    <comment_count>0</comment_count>
      <attachid>463980</attachid>
    <who name="Jed Fox">jed</who>
    <bug_when>2022-12-10 15:07:08 -0800</bug_when>
    <thetext>Created attachment 463980
svg-use-shadow-piercing-selector.svg

I attempted to apply some CSS styles to SVG elements included via the &lt;use&gt; SVG element with a selector that includes elements both outside and inside the &lt;use&gt; shadow root. While this sort of style worked for me in both Chrome and Safari, I discovered that it does not work in Firefox. I first filed this bug against Firefox/Gecko but they clarified that FF matches the spec, while Chrome/Safari don’t. Specifically,

&gt; I&apos;m afraid we&apos;re right and Chrome is wrong here. Per https://www.w3.org/TR/SVG2/struct.html#UseStyleInheritance
&gt; &gt; ...if a CSS rule uses a complex selector to match an element based on its ancestors or siblings, and those ancestors or siblings are not cloned as part of the shadow tree, then that rule would no longer match the element instance.

See the attached SVG for a demonstration of this behavior. The SVG contains an inline &lt;style&gt; rule `svg rect { fill: red; }`, and, inside a &lt;defs&gt;, a &lt;rect&gt; with `fill=&quot;green&quot;`. The &lt;rect&gt; is then included via a &lt;use&gt; tag into the visible image. On Firefox, the `fill: red` rule is not applied, so the &lt;rect&gt; remains green. On Chrome and Safari, the rule is applied, changing the &lt;rect&gt; to be red.

Firefox bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1805048
Chrome bug: https://bugs.chromium.org/p/chromium/issues/detail?id=785246
possibly related: bug 78902</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1918222</commentid>
    <comment_count>1</comment_count>
    <who name="Jed Fox">jed</who>
    <bug_when>2022-12-10 15:14:50 -0800</bug_when>
    <thetext>Tested on macOS 12.6.1 (21G217).

fails:
Safari Technology Preview Release 159 (Safari 16.4, WebKit 17615.1.12.130.1)
WebKit 257686
Safari Version 16.1 (17614.2.9.1.13, 17614)
Chrome Version 108.0.5359.98 (Official Build) (arm64)

passes:
Firefox 107.0.1 (64-bit)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1920287</commentid>
    <comment_count>2</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2022-12-17 15:08:16 -0800</bug_when>
    <thetext>&lt;rdar://problem/103484715&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2046310</commentid>
    <comment_count>3</comment_count>
    <who name="Robert Longson">longsonr</who>
    <bug_when>2024-07-15 12:14:13 -0700</bug_when>
    <thetext>Are there any plans to fix this because we keep getting Firefox bugs that we keep resolving as invalid. We agreed this behaviour because it was supposed to be simple to implement given the rules on shadow trees and the desire to implement use using that technology.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2157794</commentid>
    <comment_count>4</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2025-11-10 17:16:18 -0800</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/53713</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2159156</commentid>
    <comment_count>5</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2025-11-16 18:37:07 -0800</bug_when>
    <thetext>So my first PR is too simplistic. It totally ignores the external style. This is not really the full issue. 

A summary:
The use element create a shadow tree which has for root elements the first element targeted in the defs by the use element. So the goal of the patch would be to make sure that the styles defined outside match in the context of the shadow tree.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2159186</commentid>
    <comment_count>6</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2025-11-16 21:49:34 -0800</bug_when>
    <thetext>This also fails https://wpt.fyi/results/svg/linking/reftests/use-descendant-combinator-003.html?label=experimental&amp;label=master&amp;aligned</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2165365</commentid>
    <comment_count>7</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2025-12-12 02:17:41 -0800</bug_when>
    <thetext>*** Bug 303998 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2190877</commentid>
    <comment_count>8</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2026-03-16 23:32:03 -0700</bug_when>
    <thetext>I closed my PR. I was not confident enough it was the right way. If someone else wants to give it a try.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2190879</commentid>
    <comment_count>9</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2026-03-16 23:33:58 -0700</bug_when>
    <thetext>Some of the issues encountered when trying to fix this. 

Solving the use inheritance is not the hardest part.
The hardest part is probably dealing with the failures around symbols, defs, and animation code related cascading from the fix.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2203104</commentid>
    <comment_count>10</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2026-04-22 01:49:23 -0700</bug_when>
    <thetext>This looks like a duplicate of Bug 179724</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2203110</commentid>
    <comment_count>11</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2026-04-22 02:00:36 -0700</bug_when>
    <thetext>

*** This bug has been marked as a duplicate of bug 179724 ***</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>463980</attachid>
            <date>2022-12-10 15:07:08 -0800</date>
            <delta_ts>2022-12-10 15:07:08 -0800</delta_ts>
            <desc>svg-use-shadow-piercing-selector.svg</desc>
            <filename>svg-use-shadow-piercing-selector.svg</filename>
            <type>image/svg+xml</type>
            <size>224</size>
            <attacher name="Jed Fox">jed</attacher>
            
              <data encoding="base64">PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgogIDxkZWZzPgogICAgPHJl
Y3QgaWQ9InJlY3QiIHg9IjEwIiB5PSIxMCIgd2lkdGg9IjEwMCIgaGVpZ2h0PSIxMDAiIGZpbGw9
ImdyZWVuIiAvPgogIDwvZGVmcz4KICA8dXNlIGhyZWY9IiNyZWN0IiAvPgogIDxzdHlsZT4KICAg
IHN2ZyByZWN0IHsKICAgICAgZmlsbDogcmVkOwogICAgfQogIDwvc3R5bGU+Cjwvc3ZnPgo=
</data>

          </attachment>
      

    </bug>

</bugzilla>