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

>> 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.
>
> Again, *how is that accidental?* You don't slip on the keyboard and, whoops, a `::slotted()` shows up in your selector. You write a selector like that *on purpose*. You are *trying* to target something outside your shadow. Why is it useful to prevent libraries from using this, when they can just walk outside the tree on their own? In the cases where a library *explicitly* wants to allow targeting inside/outside a shadow tree, without this it would have to provide a side-channel for communicating that you want to hop into/out of a shadow before applying a selector, or do selector parsing on its own.

Well, the person who wrote `::slotted(~)` was almost certainly not doing so accidentally. The problem here is that it's very easy for some code to accidentally pass such a selector to an existing library that's not designed to work across shadow boundaries.

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

> This is substantially different from supporting the selectors in stylesheets?

Yes. For selectors like `::slotted`, we have a specialized code path where we collect & apply them within the node tree they appear instead of making selector code match across shadow boundaries since the latter approach is way too expensive and complicated to implement.

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

Received on Sunday, 20 August 2017 06:31:38 UTC