From 857ba60c16e9e78a72d43481f900a48a05989b5d Mon Sep 17 00:00:00 2001 From: jdecroock Date: Thu, 7 Sep 2023 20:35:58 +0200 Subject: [PATCH 1/2] skip comment nodes for placeChild --- src/diff/children.js | 7 ++++++- test/browser/hydrate.test.js | 11 ++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) 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()']); }); }); From 0f12d8d184d62e13709f6e88c496f917b56cfb62 Mon Sep 17 00:00:00 2001 From: Jovi De Croock Date: Fri, 10 Nov 2023 08:06:54 +0100 Subject: [PATCH 2/2] golf --- src/diff/children.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/diff/children.js b/src/diff/children.js index e03618110b..41112d2161 100644 --- a/src/diff/children.js +++ b/src/diff/children.js @@ -367,12 +367,11 @@ function insert(parentVNode, oldDom, parentDom) { oldDom = parentVNode._dom; } - let nextDom = oldDom; do { - nextDom = nextDom && nextDom.nextSibling; - } while (nextDom != null && nextDom.nodeType === 8); + oldDom = oldDom && oldDom.nextSibling; + } while (oldDom != null && oldDom.nodeType === 8); - return nextDom + return oldDom; } /**