[Webkit-unassigned] [Bug 233380] CSS :scope pseudo selector doesn't work in shadowRoot.querySelectorAll

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Sat Nov 20 11:31:58 PST 2021


--- Comment #4 from Andrei Anischevici <andrei002 at gmail.com> ---
(In reply to Ryosuke Niwa from comment #3)

Thank you for the prompt response, I really appreciate the detailed reply!

> This algorithm in turn does this:
> "Return the result of match a selector against a tree with s (the parsed
> selector) and node’s root (shadow root's root is itself) using scoping root
> node (shadow root)"

> >The :scope pseudo-class represents any element that is a :scope element. If the :scope elements are not explicitly specified, but the selector is scoped and the scoping root is an element, then :scope represents the scoping root; otherwise, it represents the root of the document (equivalent to :root). Specifications intending for this pseudo-class to match specific elements rather than the document’s root element must define either a scoping root (if using scoped selectors) or an explicit set of :scope elements.
> Here, the spec says that if the scoping root is not an element, we must use
> the root of the document, which is a document. Since shadow root is not a
> document, we would not match.

Please allow me to politely disagree and suggest that this a misinterpretation of the spec, specifically this part:
> "but the selector is scoped and the scoping root is an element, then :scope represents the scoping root"

The shadow root IS an element, although it's a virtual element (since it's a DocumentFragment), it's still an element, according to the scoping root definition here https://drafts.csswg.org/selectors-4/#scoping-root

"The root of the scoping subtree is called the scoping root, and may be either a true element (the scoping element) or a virtual one (such as a DocumentFragment)"

"virtual one" == "virtual element"

I totally agree that this "and the scoping root is an element" part in the ":scope" spec is somewhat confusing and should've been excluded altogether, since from the "scoping root" definition it's clear that it can't be anything else than an element..

Furthermore, if we look away from the specs for a bit and take a look at it from a purely logical standpoint:
 - Given a node tree, in this case a DocumentFragment (which supports querySelectorAll() in its API https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment/querySelectorAll) I need to be able to select the direct descendants of the tree root, i.e. the top-level elements using some selector. Currently ':scope > ...' is the only selector that can accomplish this and it's a real pain to work around this if it's not supported..

I see that there's a new ::shadow pseudo-element proposed that would allow an alternate solution to this issue
however, none of the browsers seem to implement it at this point..

You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20211120/89e3edeb/attachment-0001.htm>

More information about the webkit-unassigned mailing list