partytown icon indicating copy to clipboard operation
partytown copied to clipboard

TreeWalker traversal does not advance in web worker

Open MasonPinZ opened this issue 2 years ago • 1 comments

  • [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:

  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.

MasonPinZ avatar Sep 12 '22 03:09 MasonPinZ

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?

linuxd3v avatar Sep 21 '22 18:09 linuxd3v