Fix Node.contains ancestor traversal - #688
Open
olavoasantos wants to merge 1 commit into
Open
olavoasantos wants to merge 1 commit into
olavoasantos wants to merge 1 commit into
Conversation
olavoasantos
force-pushed
the
fix-node-contains
branch
from
September 3, 2026 15:30
e7b401a to
5173a3a
Compare
olavoasantos
changed the base branch from
parse-closing-tags-and-svg
to
main
September 3, 2026 15:30
olavoasantos
force-pushed
the
fix-node-contains
branch
from
September 4, 2026 14:31
5173a3a to
3c57e5b
Compare
olavoasantos
marked this pull request as ready for review
September 4, 2026 15:29
JoviDeCroock
approved these changes
Sep 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Node.contains()is supposed to walk from the candidate node toward the root until it finds the receiver. The previous loop repeatedly read the original candidate’s parent instead of advancing from the current node, so it stopped making progress after the first hop.As a result, checks such as
parent.contains(grandchild)and checks against a node in another attached subtree never returned.Impact
Critical. This is a synchronous infinite loop. Because the polyfill is intended for non-browser environments such as Web Workers, one affected
contains()call can block that worker’s event loop indefinitely instead of returning a boolean.Reproduction
Before this change, the final call never returned. It now returns
true. The equivalent check against a node in another subtree now terminates and returnsfalse.Change
Advance through
currentNode.parentNodeon each iteration and returnfalseafter reaching the root. This preserves the expected results for the receiver itself and direct children while allowing deeper and unrelated-node checks to terminate.Tests
Regression coverage verifies the receiver itself, a direct child, a deep descendant, a node in another subtree, a detached node, and
null. The deep-descendant and other-subtree cases exercise the paths that previously hung.Stack
mainCoverage includes both the explicit detached-node case and a node attached to another subtree.
Validation
Fresh GitHub CI on restacked head
3c57e5bpasses: