Skip to content
This repository was archived by the owner on Jun 20, 2025. It is now read-only.

Commit a8e8764

Browse files
authored
Pierce ShadowRoot boundary when getting ancestry (#486)
* Pierce ShadowRoot boundary when getting ancestry With on-demand ShadyDOM, the DOM is rendered without shadow nodes, but the API acts as if these shadow nodes exist. This can cause issues with getFocusedPath calls where the activeElement is inside of a "shadow node", thus getting the ancestry of the activeElement to the root results in an assertion error because `n.parentNode` returns undefined. We can get around this by piercing through the shadow node boundary. This should only affect on-demand ShadyDOM since for regular ShadowDOM, the `!node.contains(activeElement)` check would be true causing getFocusedPath to short circuit. * Remove unecessary optional chaining
1 parent febf3c9 commit a8e8764

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/dom_util.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ function getAncestry(node: Node, root: Node | null) {
4444
while (cur !== root) {
4545
const n: Node = assert(cur);
4646
ancestry.push(n);
47-
cur = n.parentNode;
47+
// If `node` is inside of a ShadowRoot, then it needs to pierce the
48+
// ShadowRoot boundary in order to reach `root`.
49+
cur = n.parentNode || (n as ShadowRoot).host;
4850
}
4951

5052
return ancestry;

0 commit comments

Comments
 (0)