Skip to content

Commit

Permalink
fix(html): properly walk parent nodes for ShadyDOM polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
smalluban committed Jan 8, 2020
1 parent 4771605 commit 0b000ed
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/template/core.js
Expand Up @@ -110,7 +110,13 @@ export function createInternalWalker(context) {
} else if (node.nextSibling) {
node = node.nextSibling;
} else {
node = node.parentNode.nextSibling;
let parentNode = node.parentNode;
node = parentNode.nextSibling;

while (!node && parentNode !== context) {
parentNode = parentNode.parentNode;
node = parentNode.nextSibling;
}
}

return !!node;
Expand Down
4 changes: 2 additions & 2 deletions test/spec/html.js
Expand Up @@ -694,15 +694,15 @@ describe('html:', () => {
describe('ShadyDOM polyfill', () => {
it('uses internal TreeWalker', () => {
const el = document.createElement('div');
el.innerHTML = '<div><div>text</div><div>text<div>text</div></div></div>';
el.innerHTML = '<div><div>text</div><div>text<div>text</div></div>text</div>';

const walker = createInternalWalker(el);
let index = 0;
while (walker.nextNode()) {
expect(walker.currentNode).not.toBeNull();
index += 1;
}
expect(index).toBe(7);
expect(index).toBe(8);
});
});

Expand Down

0 comments on commit 0b000ed

Please sign in to comment.