Re: [WICG/webcomponents] Selection APIs for Shadow DOM (#79)

> > Like I've stated elsewhere, `getComposedRange` should take shadow roots as arguments regardless of whether they're open or not. This is particularly important because otherwise, a code which is supposed to work with nodes within a given shadow root (of a specific component) can accidentally stumble upon nodes inside other shadow roots.
> 
> Thanks for the comment. The reason I didn't want to do that was ergonomics. It seems like it would make this API very hard to use:
> 
> ```js
> // Do full tree walk to find all shadow roots
> let allRoots = [];
> document.body.querySelectorAll('elements-that-support-shadowroots').forEach(e => {
>   if (e.shadowRoot)
>     allRoots.push(e.shadowRoot);
> });
> 
> // Now, see where the selection is
> let range = getComposedRange(allRoots);
> ```

What is a concrete use case for doing this?

> I can definitely see the case for needing to provide **closed** roots, to avoid leaking them. But requiring the developer to "tell" us where all of the open roots are just seems like extra work, to avoid leaking something that is already public.

The issue isn't so much about leaks in the case of open shadow roots but more about ergonomics & separations of concerns. If the only way to get the range of selection when its end points are in a shadow root is to get selection end points in any shadow root, then you're effectively back to not having shadow root encapsulation at all. You'd have to constantly check against end points to see if it's in your shadow root or not.


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/WICG/webcomponents/issues/79#issuecomment-937416019

Received on Thursday, 7 October 2021 03:35:11 UTC