partytown
partytown copied to clipboard
TreeWalker traversal does not advance in web worker
- [x] I am interested in helping provide a fix!
Describe the bug When executed in Partytown web worker, DOM node traversal using TreeWalker never advances and falls into infinite loops.
To Reproduce Steps to reproduce the behavior:
- In a script block of type
text/partytown
, get a TreeWalker instance by callingdocument.createTreeWalker()
- Traverse DOM nodes using the TreeWalker instance by:
const treeWalker = document.createTreeWalker(document.body, 1); do { // some code like: console.log(treeWalker.currentNode.nodeName); } while (treeWalker.nextNode());
- Observation: the loop above never ends and
treeWalker.currentNode
is always the initial DOM node.
Reproduction link A test case has been created in this PR. To run the test case:
npx playwright test tests/platform/tree-walker --browser=chromium
Expected behavior The DOM tree traversal should advance and complete normally as being executed on main thread.
Partytown version 0.6.4
Screenshots N/A.
Additional context None.
interesting - I think this is caused by the same issue as iterable bug I'm seeing:https://github.com/BuilderIO/partytown/issues/257 any idea what causing this?