Closed Bug 1805048 Opened 3 years ago Closed 3 years ago

CSS selectors do not pierce the shadow root created by the SVG <use> element

Categories

(Core :: SVG, defect)

Firefox 107
defect

Tracking

()

RESOLVED INVALID

People

(Reporter: jed, Unassigned)

Details

Attachments

(1 file)

Steps to reproduce:

I attempted to apply some CSS styles to SVG elements included via the <use> SVG element with a selector that includes elements both outside and inside the <use> shadow root. The minimal example attached demonstrates this with the selector svg rect, but the same issue applies to my real use case where I was selecting an element inside of the SVG and then using the space combinator to descend into the <use> to an element I wanted to target there.

Actual results:

The rect element included inside of the <use> doesn’t get the CSS rule applied to it in Firefox. If you open the SVG, you’ll find that the left square is green, and the right square (which is a copy of the left square using <use>) is red.

Firefox: 107.0.1 (64-bit)
macOS: 12.6.1 (21G217)

Expected results:

On Chrome (108.0.5359.98 (Official Build) (arm64)) and Safari (Technology Preview Release 159 (Safari 16.4, WebKit 17615.1.12.130.1)), both squares show up in green as I expected.

Note that changing the CSS rule from svg rect { to rect { results in the correct behavior in all 3 browsers.

The Bugbug bot thinks this bug should belong to the 'Core::SVG' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → SVG
Product: Firefox → Core

I'm afraid we're right and Chrome is wrong here. Per https://www.w3.org/TR/SVG2/struct.html#UseStyleInheritance

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

Status: UNCONFIRMED → RESOLVED
Closed: 3 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: