Skip to content

Commit

Permalink
skip comment nodes for placeChild
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Nov 10, 2023
1 parent 51771f7 commit 857ba60
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/diff/children.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,12 @@ function insert(parentVNode, oldDom, parentDom) {
oldDom = parentVNode._dom;
}

return oldDom && oldDom.nextSibling;
let nextDom = oldDom;
do {
nextDom = nextDom && nextDom.nextSibling;
} while (nextDom != null && nextDom.nodeType === 8);

return nextDom
}

/**
Expand Down
11 changes: 10 additions & 1 deletion test/browser/hydrate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ describe('hydrate()', () => {
beforeEach(() => {
scratch = setupScratch();
attributesSpy = spyOnElementAttributes();
clearLog();
});

afterEach(() => {
teardown(scratch);
clearLog();
});

it('should reuse existing DOM', () => {
Expand Down Expand Up @@ -92,6 +92,7 @@ describe('hydrate()', () => {
scratch
);
expect(scratch.innerHTML).to.equal('<p><i>0</i><b>1</b></p>');
expect(getLog()).to.deep.equal(['Comment.remove()']);
});

it('should reuse existing DOM when given components', () => {
Expand Down Expand Up @@ -458,5 +459,13 @@ describe('hydrate()', () => {
scratch.innerHTML = '<p>hello <!-- c -->foo</p>';
hydrate(<p>hello {'foo'}</p>, scratch);
expect(scratch.innerHTML).to.equal('<p>hello foo</p>');
expect(getLog()).to.deep.equal(['Comment.remove()']);
});

it('should skip over multiple comment nodes', () => {
scratch.innerHTML = '<p>hello <!-- a --><!-- b -->foo</p>';
hydrate(<p>hello {'foo'}</p>, scratch);
expect(scratch.innerHTML).to.equal('<p>hello foo</p>');
expect(getLog()).to.deep.equal(['Comment.remove()', 'Comment.remove()']);
});
});

0 comments on commit 857ba60

Please sign in to comment.