[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 09:26:17 PST 2021
https://bugs.webkit.org/show_bug.cgi?id=233380
--- Comment #3 from Ryosuke Niwa <rniwa at webkit.org> ---
(In reply to Andrei Anischevici from comment #2)
> (In reply to Ryosuke Niwa from comment #1)
> > As mentioned in Mozilla bug, this seems working as intended. If this
> > behavior is desirable, perhaps you need to open a spec issue for CSS WG.
>
> As I also mentioned in the Mozilla bug, this is not working as intended and
> the comment with which that bug was initially resolved does not apply, as
> we're not crossing the shadow boundary with a single selector, but instead
> doing the selection from the shadow root node, which is expected to be
> working, similarly to how it's working for the document root node. That
> ticket has since been reopened and being looked into.
Well, :scope is spec'ed to behave like this. node.querySelector is defined here:
https://dom.spec.whatwg.org/#dom-parentnode-queryselector
which invokes the algorithm "to scope-match a selectors string" with "this", which is shadow root in this case:
https://dom.spec.whatwg.org/#scope-match-a-selectors-string
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)"
Now take a look at the definition of a scoping root:
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"
And now the definition of ":scope":
https://drafts.csswg.org/selectors-4/#the-scope-pseudo
>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.
Now, it's possible that this is an editorial error in CSS selectors 4 and we want to say that it matches the root node (i.e. shadow root in the case). But as far as I read the current set of specifications, the current behavior of WebKit and Gecko are correct and Chrome's behavior is the one that is not spec compliant.
--
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/63ffea02/attachment.htm>
More information about the webkit-unassigned
mailing list