- From: Mason Freed <notifications@github.com>
- Date: Wed, 06 Oct 2021 16:26:12 -0700
- To: WICG/webcomponents <webcomponents@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <WICG/webcomponents/issues/79/937320917@github.com>
> 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: ```javascript // 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); ``` 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. **What do developers think about this?** Perhaps the ergonomics aren't as bad as I think? Perhaps the concern (accidentally seeing nodes inside of "unknown" shadow roots) is a valid/good concern? Perhaps, if that turns out to be a common developer concern, we could add some API (subject to bikeshedding) to **optionally** restrict to just the provided roots? ```javascript let rangeInKnownElementsOnly = getComposedRange({onlyIncludeTheseRoots: roots}); let rangeAnywhere = getComposedRange(); ``` -- 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-937320917
Received on Wednesday, 6 October 2021 23:26:24 UTC