diff --git a/src/diff/children.js b/src/diff/children.js index 40a038722f..e03618110b 100644 --- a/src/diff/children.js +++ b/src/diff/children.js @@ -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 } /** diff --git a/test/browser/hydrate.test.js b/test/browser/hydrate.test.js index 0b23c6f12c..b03c0e2a66 100644 --- a/test/browser/hydrate.test.js +++ b/test/browser/hydrate.test.js @@ -50,11 +50,11 @@ describe('hydrate()', () => { beforeEach(() => { scratch = setupScratch(); attributesSpy = spyOnElementAttributes(); + clearLog(); }); afterEach(() => { teardown(scratch); - clearLog(); }); it('should reuse existing DOM', () => { @@ -92,6 +92,7 @@ describe('hydrate()', () => { scratch ); expect(scratch.innerHTML).to.equal('

01

'); + expect(getLog()).to.deep.equal(['Comment.remove()']); }); it('should reuse existing DOM when given components', () => { @@ -458,5 +459,13 @@ describe('hydrate()', () => { scratch.innerHTML = '

hello foo

'; hydrate(

hello {'foo'}

, scratch); expect(scratch.innerHTML).to.equal('

hello foo

'); + expect(getLog()).to.deep.equal(['Comment.remove()']); + }); + + it('should skip over multiple comment nodes', () => { + scratch.innerHTML = '

hello foo

'; + hydrate(

hello {'foo'}

, scratch); + expect(scratch.innerHTML).to.equal('

hello foo

'); + expect(getLog()).to.deep.equal(['Comment.remove()', 'Comment.remove()']); }); });