Re: [whatwg/dom] Match querySelector for pseudo elements (::slotted()) (#463)

> In general, we allowed access from inner to outer, such as `ShadowRoot.host` or `HTMLSlotElement.assignedNodes()`, whereas we are restrictive from outer to inner, especially for closed shadow trees, such as `Element.shadowRoot`.

With an explicit API. The problem here is that `querySelector` and `querySelectorAll` are existing API that used to never return a node outside its own tree regardless of what input was given to the functions. For example, you could have iterated over every CSS rule in the stylesheet and executed `querySelectorAll` on every selector, and you wouldn't have gotten any node that doesn't belong to its own node tree. If we made the proposed change to `querySelector` and `querySelectorAll`, however, they would start returning nodes outside its own node tree. I would consider that as a show stopper.

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 `::slotted()` and `::part()` to `querySelector` and `querySelectorAll` to return a node outside its own node tree, passing an arbitrary string to those two functions is a common scenario a lot of libraries and frameworks do implement. Now, such library/framework code can easily rely on the fact that the node returned by `querySelector` and `querySelectorAll` belong to the same node tree as the context object; e.g. library/framework might cache the results of `querySelectorAll` at the root node. The library could be adding properties returned by `querySelectorAll` for some processing. All these things are exactly the kind of things that ought to be avoided by the encapsulation shadow tree provides.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/463#issuecomment-323321253

Received on Friday, 18 August 2017 10:41:13 UTC