BuilderIO / partytown

Relocate resource intensive third-party scripts off of the main thread and into a web worker. 🎉
https://partytown.builder.io
MIT License
12.97k stars 427 forks source link

TreeWalker traversal does not advance in web worker #254

Open MasonPinZ opened 1 year ago

MasonPinZ commented 1 year ago

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:

  1. In a script block of type text/partytown, get a TreeWalker instance by calling document.createTreeWalker()
  2. 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());
  3. 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.

linuxd3v commented 1 year ago

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?