Re: [whatwg/dom] A faster way to find open shadow roots (or shadow hosts) (#665)

> F2F discussion: it's unclear what the use cases for this API are and to what extent libraries have tried to work around it (or implemented it themselves). This needs more use cases to progress.

Couple of example use cases from Chromium's code.

* Find placeholder strings in the DOM (at runtime) and replace them with localized strings, [see here](https://cs.chromium.org/chromium/src/ui/webui/resources/js/i18n_template_no_process.js?l=124-127).
* Test that all icons in a page are properly rendered, [see here](https://cs.chromium.org/chromium/src/chrome/test/data/webui/polymer_browser_test_base.js?type=cs&q=polymer_bro&sq=package:chromium&g=0&l=112).
* Disable all animations and transitions during automated tests, [see here](https://cs.chromium.org/chromium/src/chrome/test/data/webui/test_api.js?type=cs&q=disableAnimations+-file:third_party+-file:infra+-file:out/Debug+-file:out/chromium-android/Debug+-file:out/android-Debug+-file:src/v8+-file:src/native_client-sdk+-file:src/out/&g=0&l=65).
* Implement custom search, as done in chrome://settings page. "/deep/" was previously used to find and remove all "search bubbles" when the user clears the search results. See example screenshot
![search_bubbles](https://user-images.githubusercontent.com/7547039/47517173-34300600-d83c-11e8-87d3-dd18ca111d46.png). That code has now been updated to not use /deep/, but [the workaround](https://chromium-review.googlesource.com/c/chromium/src/+/1100102) was heavily involved for something seemingly so simple. Basically we are now caching a reference to all "search bubbles" so that we can remove them later without having to search the DOM.

Overall, being able to query the entire DOM via JS using querySelector is very useful, and does not necessarily mean that the developer is doing something wrong (again, this is not about CSS penetrating shadow roots). By providing no such built-in way, developers are forced to keep implementing their own recursive search solutions in JS, which have poor performance and are cumbersome.



-- 
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/665#issuecomment-433130017

Received on Thursday, 25 October 2018 17:04:21 UTC