Re: [whatwg/dom] Should TreeWalker be expanded to support shadow roots in support of the selection API? (Issue #1189)

LeaVerou left a comment (whatwg/dom#1189)

> I personally consider `NodeIterator` and `TreeWalker` to be deprecated. 

What does that even mean? Either they should be publicly deprecated and authors should be aware of this, or they are not deprecated. Quietly deprecating web APIs, when only those *in the know* are aware of the deprecation harms both web authors and the vast majority of web stakeholders who are not browser vendors.

Additionally, this is not some niche API; as @zcorpan pointed out, tree walkers are used in **a fifth of all pages**, exactly because manual traversal of every single node on the page tends to be inefficient. I agree they are badly designed APIs, desperately in need of modernization, but if we want to deprecate them, we need to have a better alternative than "just rawdog it with `.childNodes`".

---

WRT a concrete proposal, assuming we make `TreeWalker` constructible, it seems reasonable (as a pattern for DOM APIs in general) to have an options dictionary with a `shadowRoots` property to pass specific shadow roots (open or closed) and a boolean to traverse all open roots (name TBB, `walkOpenShadowRoots` seems comically long) so that one doesn't have to keep track of them and pass them to every single method.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/1189#issuecomment-3530637362
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/dom/issues/1189/3530637362@github.com>

Received on Friday, 14 November 2025 03:16:06 UTC