-
Notifications
You must be signed in to change notification settings - Fork 299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Match querySelector for pseudo elements (::slotted()) #463
Comments
Let me get back to this. For 1, I'd vote for NO for consistency with other pseudo elements. So if developers want |
I agree with NO on 1. I don't see what kind of object we could even return. I don't agree with 2 given the discussion in WICG/webcomponents#78 hasn't concluded favorably to such an addition. And 1 is tracked by #185 by the way, which is awaiting input from @tabatkins. |
@tabatkins ping? |
1 similar comment
@tabatkins ping? |
Until WICG/webcomponents#78 i s resolved, I'm okay with NO for 2 as a conservative option. If no one objects, I'd like to make necessary edits to the DOM spec, but before then, @niwa and @tabatkins could you sanity check? Also @tabatkins, any suggestion about the necessity for changing any of CSS selectors spec is welcome. |
What's the case where no.2 becomes relevant? Only shadow boundary piercing combinator? Then "no" since our position is to not support that. |
Yes, as far as I know only |
Ugh, sorry for not responding. So, there's definitely nothing capable of representing pseudo-elements in JS, so nothing to return if the selector is On the spec-language front, dbaron recently rewrote the "match a selector against a tree" algorithm, and I need to do a more detailed review of it now. I can make sure it handles this case. |
(For reference, Thanks Tab for the comment, so you think YES for 1, then it implies YES for 2 as well? If we allow not-in-the-same-tree element to be returned, implementation has to take care of each exceptional pseudo elements ( |
I don't think we should do that. It would mean it's a lot easier to accidentally access nodes outside your own shadow tree in the library code, etc... that takes an arbitrary selector and runs it against a DOM tree. |
You only "accidentally" access nodes that you explicitly ask for. It doesn't give you access to anything you don't already have access to; I don't know of any other way to "accidentally" access anything outside of your tree; any selectors other than those explicitly mentioned are always limited to just your current tree. Care would have to be taken with |
There is a lot of library/framework code that takes in an arbitrary selector as an input. Those code can then accidentally start traversing / mutating shadow tree if |
Yeah, but what part of that is "accidental"? Again, the only way to traverse the boundaries is using a selector that traverses the boundaries. There's only a handful of specific pseudos that do this; nothing else will. What's wrong with library/framework code being able to cross shadows when the user of the library explicitly asks them to? |
The problem is that accidentally passing a selector which crosses a shadow boundary isn't really explicit. Whether something is concerned as explicit is quite subjective so I'm not certain if we can come to an agreement on that. What I can say that is that we'd object to making querySelector returning a node outside of its own tree, and would not implement it in WebKit. |
I see the gap that @tabatkins asking any concrete example that can accidentally get the node outside the tree, while @rniwa saying it's technically possible that happens, without concrete example. My take on the gap is that where you are coming from, i.e. the world that "open" shadow root is the default or the world that "closed" shadow root is the default. But there is no such default for the current In general, we allowed access from inner to outer, such as So what is wrong with this?: allow cross-boundary element to be returned for querySelector() if the selector explicitly contains cross-boundary pseudos such as I think nothing is wrong, the only justification for not returning those that I can agree is at the last line in @rniwa's response, "querySelector returning a node outside of its own tree" (its = context object's). I haven't heard anyone requesting
I think it's fine to restrict
|
With an explicit API. The problem here is that In general, we shouldn't be modifying the behavior of an existing DOM API to start returning a node outside its own node tree without an explicit opt-in that doesn't conceivably come up as a part of existing use of the API. While the author must supply a selector string that contains |
I'd add one more reason that we'd object to this feature: implementation complexity. Making |
Again, how is that accidental? You don't slip on the keyboard and, whoops, a
This is substantially different from supporting the selectors in stylesheets?
I still don't understand the failure mode being alluded to here. Can you give a concrete example? |
In the case of Blink, usually querySelector/querySelectorAll first collects a set of elements that will be matched against the given selector, but for a selector which contains If we'd support |
Well, the person who wrote The scenario works like this. 1. there was a generic code written with shadow tree in mind which takes an arbitrary CSS selector and access & mutates the node returned by the selector. 2. an author uses that generic code in a shadow tree, or more likely some code which the author deployed ends up depending on such generic code. 3. The selector given to the generic code in (1) exposes a node outside its node tree, and breaks the code & causes unintended code effects. Note that step (3) doesn't necessarily invoke the author explicitly giving a selector that crosses shadow boundaries to the generic code (1). The generic code (1) itself could be traversing through selectors in every stylesheet in the node tree and automatically processing them to polyfill missing CSS features, etc...
Yes. For selectors like |
@tabatkins do you have any updates on this? Especially I'd like to hear if there is necessity or strong reason to make a selector work in a consistent way as much as possible in stylesheets and for querySelector API. |
There is a strong reason to make the querySelector API work the same - if the browser can run the selector in a stylesheet, there's no good reason to disallow giving authors access to the same matching capability in JS. Seemingly-arbitrary restrictions make APIs more complicated for authors, harder to learn and confusing to use. I guarantee you that if an author asks "Why can't I match an element with one of these selectors? The browser can!" there's no satisfying answer you can give them. "Rewrite your code to split the selector into two, with the tree-crossing done manually in JS between them" is a terrible answer that will just make them angry, and rightfully so. That said, if we really do think it's a necessity to impose a "must stay in starting tree" restriction, I won't oppose it if we couple it with an issue tracking adding a flag or new method that actually evaluates selectors properly, the same as the browser does. Before we impose this restriction in the spec I'd like to figure out what the new API will look like; I dont' want a
I read this as an argument for the exact opposite case. CSS polyfill code wants to faithfully polyfill CSS, which includes correctly evaluating selectors that people would use in CSS. I suspect this restriction would break as many cases as it fixes. I understand that we sometimes need to impose seemingly-arbitrary restrictions for implementation reasons, but let's defend it on those grounds, not pretend we're doing authors a favor here. Carving out pieces of the platform that UAs can use but authors can't isn't helpful to them. |
Okay, I still disagree with your arguments, but I would re-iterate that we're not willing to implement a feature where querySelector would return a node outside its own tree in WebKit due to the implementation complexity it would add. That is, whatever flag or new method you're proposing is not something we ever want to implement in WebKit due to the implementation complexity even as a separate API. |
Let me make sure one more thing. Putting aside pseudos, if I understand the whatwg DOM spec,
not returning elements outside the tree of the context object is status quo, right? Or, according to changes in
Is this change not applied to the DOM spec (but how we pass one or more root elements from querySelector()?)? |
Given the resolution of WICG/webcomponents#78 and likely resolution of w3c/csswg-drafts#640 I'm inclined to close this. The only thing we might need to clarify with pseudo-elements is that they're not returned. |
That's not a feature on offer at the moment. |
Let's close this as status quo. My understanding is that with the current state of the relevant specs, querySelector() works as Until we have something concrete that we can receive a pseudo element as a DOM object, |
(See crbug.com/710797 for the background)
The problem is, that
shadowRoot.querySelector('::slotted(div)')
(orquerySelectorAll
) will not return anything even when the context object (theshadowRoot
) contains<slot>
and a<div>
is slotted to it.Demo:
http://jsbin.com/jafetekipi/edit?html,js,output
(currently both Blink and WebKit fail)
MDN document of Document.querySelector() says:
Note that this "Selectors API" links to Selectors API level 1 (an old spec).
The latest draft as of today (Selectors Level4) doesn't say about how
querySelector()
should work for pseudo-elements, and neither does DOM spec.In the past,
::before
or::first-line
etc. never matched any real element in DOM tree, but::slotted(div)
can match a real element in DOM tree, even though it is in a different tree.Here I see the following problems in the current specs:
querySelector
can match some pseudo elements (::slotted()
).querySelector
can return an element outside the node tree of the context object.::slotted()
is a pseudo element, but can point to a real element.For 3, this is not a matter of DOM spec. The rationale for
::slotted()
being a pseudo element is that it points to an element in another tree, and we wanted to restrict the selector in parentheses to a simple/compound selector (not allowing complex selector). If it were a combinator, any selector would be allowed to the right side.Note that issue 2 is also relevant to
WICG/webcomponents#78 (Support
>>>
combinator in static profile).The text was updated successfully, but these errors were encountered: