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

> So I'm in the process of updating the explainer with the points mentioned in my prior comment. And I ran across a set of issues that I don't see an immediate (good) solution for. Both can be seen using the [last part of example #2](https://github.com/mfreed7/shadow-dom-selection#2-editor-component-inside-shadow-dom) from the explainer. In that example, an editor Web Component (`<x-editor>`) that does **not** use shadow DOM is nested inside another Web Component (`<parent-component>`) that **does** use shadow DOM.
> 
> ## Problem #1
> Since the editor component itself, which needs selection info, does not contain a shadow root, what should it pass in to the shadowRoots argument here: `selection.getComposedRange({shadowRoots: [what?]})`? I suppose it could walk up the shadow-including tree from `this`, and pass in the first shadow root it finds? That feels a bit odd, for a component that really doesn't want to use Shadow DOM, but finds itself located inside one.

You can just use container.getRootNode()? This problem needs to be resolved regardless if it's a problem for open shadow root since the same problem will exist for a closed shadow root. So this isn't a good argument that open shadow roots should be automatically included in this API.

> ## Problem #2
> This brings up another issue in the definition of exactly **which** shadow roots are required in the call to `getComposedRange({shadowRoots: []})`. When we discussed this, and in the explainer, only the "deepest" shadow root was needed, which was enough to reveal knowledge of that shadow root and all ancestor shadow roots. But that will necessarily reveal selections in the entire shadow-including tree above the component, which might be deeply nested. If the purpose of the `shadowRoots` parameter to `getComposedRange()` is to limit selections to "known" shadow roots, then it doesn't really work in this case.

Again, this is a problem with this particular API shape regardless of whether open shadow roots are automatically included or not since it would be an issue for closed shadow roots. Perhaps we need an optional parameter specifying the root node under which the selection end points need to be found. e.g. `getComposedRange({shadowRoots: [editor.getRootNode()], root: editor})`.

> A fix to this would be to require **all** shadow roots to be included, but then that's ambiguous. What gets returned if you only provide "your" shadow root, but the selection surrounds "you" but begins and ends in a shadow root above you?

This is problematic regardless. It's not an argument for including just open shadow roots.

> Both of these point (me at least) back to the original proposal which doesn't require passing in `open` shadow roots.

Decidedly not.

Generally, any problems you've raised about open shadow roots are also applicable to closed shadow roots so I don't find any of those points remotely close to supporting the argument for automatically including all open shadow roots.

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

Received on Friday, 5 November 2021 02:01:22 UTC