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

Commit b14c0bd

Browse files
authored
Fix getAncestry handling with null root (#487)
In the case that the root is null, getAncestry shouldn't pierce through the shadow DOM. This only happens when `node.parentNode` is null, which only happens when the node is a document fragment or ShadowRoot.
1 parent a8e8764 commit b14c0bd

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/dom_util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function getAncestry(node: Node, root: Node | null) {
4646
ancestry.push(n);
4747
// If `node` is inside of a ShadowRoot, then it needs to pierce the
4848
// ShadowRoot boundary in order to reach `root`.
49-
cur = n.parentNode || (n as ShadowRoot).host;
49+
cur = n.parentNode || (root ? (n as ShadowRoot).host : null);
5050
}
5151

5252
return ancestry;

0 commit comments

Comments
 (0)