Commit 90fc4ae
committed
Fix Node#contains infinite loop for indirect descendants
The contains() walk re-read the ORIGINAL node's parentNode on every
iteration (currentNode = node.parentNode instead of
currentNode.parentNode), so it never advanced past the first step:
direct children happened to return true (the first step hits the
receiver), but any indirect descendant re-read the same middle node
forever. In a synchronous environment such as a Web Worker running the
remote DOM polyfill, that single call deadlocks the entire event loop
with no exception — reported downstream as a silent permanent freeze
in twenty's front component sandbox (twentyhq/twenty#24573).
Advance the walk with currentNode.parentNode, per the
Node.prototype.contains contract. New node.test.ts covers direct and
indirect descendants, self, detached nodes, sibling subtrees and null.
Differential: on the previous code the indirect-descendant case does
not merely fail — it hangs the test runner indefinitely (verified by
killing the run after several minutes and by an isolated child-process
repro that never terminates); with this change the whole suite passes
in under five seconds.1 parent 1780f15 commit 90fc4ae
2 files changed
Lines changed: 61 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
163 | | - | |
| 163 | + | |
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
0 commit comments