fix: scope getRoot to the comment tree so the shadow walk doesn't collect reddit chrome (closes task/getroot-comment-tree-scope)
Source: task/getroot-comment-tree-scope (plan/steward-linker-design) — getRoot's union querySelector resolved to <main> on new reddit, so the shadow-piercing walk over-collected reddit chrome. - getRoot now tries shreddit-comment-tree, then .commentarea, then main/body sequentially (narrow-first) instead of one union querySelector, so the comment tree wins when present. - collectInto takes an allowShadow flag: a narrow comment root pierces every open shadow host; a broad fallback root descends only into comment-component hosts (tagName SHREDDIT-COMMENT*), so chrome shadow roots (nav/sidebar/composer) are never walked. - README + AGENTS shadow-DOM notes updated to describe the two-layer scoping. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -24,16 +24,21 @@ is tracked in the **towl** work-item store under project **`reddit-spotify-linke
|
||||
phrases for albums) — node-testable via `extract.test.cjs`. Album links render
|
||||
italicised (`.rsl-album`).
|
||||
- **shreddit shadow DOM:** `collectTextNodes` is shadow-piercing. A TreeWalker can't
|
||||
cross a shadow boundary, so it walks the comment-tree `root`'s light DOM AND
|
||||
recursively descends into the **open** shadow roots of elements within that subtree.
|
||||
New reddit's `shreddit-*` components may encapsulate comment bodies in a shadow root;
|
||||
this reaches them whether reddit slots (light DOM) or encapsulates (shadow DOM), with
|
||||
no need to know which. It is scoped to the comment-tree root (never the whole
|
||||
document's shadow roots, which would pull in reddit chrome) and is a no-op on old
|
||||
reddit (no shadow roots). Slotted light-DOM nodes are not double-collected (a shadow
|
||||
walker sees the shadow tree's own nodes, not a `<slot>`'s assigned light nodes; a
|
||||
Set de-dupes belt-and-braces). **Closed** shadow roots are unreachable from a content
|
||||
script — a documented limitation.
|
||||
cross a shadow boundary, so it walks the chosen `root`'s light DOM AND recursively
|
||||
descends into the **open** shadow roots of elements within that subtree. New reddit's
|
||||
`shreddit-*` components may encapsulate comment bodies in a shadow root; this reaches
|
||||
them whether reddit slots (light DOM) or encapsulates (shadow DOM). Scope is two-layer:
|
||||
`getRoot` tries the narrow comment containers first (`shreddit-comment-tree`, then old
|
||||
reddit's `.commentarea`) before the broad `main`/`body`, so on a new-reddit comment page
|
||||
the root is the comment tree and the walk stays within it; and when `getRoot` falls back
|
||||
to a broad root (no comment tree present) the recursion descends only into comment-component
|
||||
shadow hosts (`tagName` starting `SHREDDIT-COMMENT`), so reddit's chrome shadow roots (nav,
|
||||
sidebar, composer) are never walked. (A single union `querySelector` could not do this — it
|
||||
returns the first match in document order, and `<main>` is an ancestor of the comment tree,
|
||||
so it would always win.) It is a no-op on old reddit (no shadow roots). Slotted light-DOM
|
||||
nodes are not double-collected (a shadow walker sees the shadow tree's own nodes, not a
|
||||
`<slot>`'s assigned light nodes; a Set de-dupes belt-and-braces). **Closed** shadow roots
|
||||
are unreachable from a content script — a documented limitation.
|
||||
- `scripts/check.sh` — the local check gate.
|
||||
|
||||
## How work lands (IMPORTANT — this is NOT the towl repo)
|
||||
|
||||
Reference in New Issue
Block a user