From 3d05e18bf77d31808d73f27d1b3920f7d3dae135 Mon Sep 17 00:00:00 2001 From: haveyaseen Date: Sun, 2 May 2021 13:28:09 +0200 Subject: [PATCH 1/3] fix broken order of nodes during hydration --- src/runtime/internal/dom.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/runtime/internal/dom.ts b/src/runtime/internal/dom.ts index b0cc2c584181..39af01a7c3b6 100644 --- a/src/runtime/internal/dom.ts +++ b/src/runtime/internal/dom.ts @@ -22,7 +22,7 @@ export function append(target: Node, node: Node) { if (is_hydrating) { nodes_to_detach.delete(node); } - if (node.parentNode !== target) { + if (node.parentNode !== target || node.parentNode !== null) { target.appendChild(node); } } @@ -31,7 +31,7 @@ export function insert(target: Node, node: Node, anchor?: Node) { if (is_hydrating) { nodes_to_detach.delete(node); } - if (node.parentNode !== target || (anchor && node.nextSibling !== anchor)) { + if (node.parentNode !== target || node.parentNode !== null || (anchor && node.nextSibling !== anchor)) { target.insertBefore(node, anchor || null); } } From 78564dbcc2189d87c4d047c94893c4107328a8ef Mon Sep 17 00:00:00 2001 From: haveyaseen Date: Sun, 2 May 2021 15:44:46 +0200 Subject: [PATCH 2/3] add test for hydration of nested element with expression sibling --- .../samples/expression-sibling/_after.html | 1 + .../samples/expression-sibling/_before.html | 1 + .../samples/expression-sibling/_config.js | 19 +++++++++++++++++++ .../samples/expression-sibling/main.svelte | 1 + 4 files changed, 22 insertions(+) create mode 100644 test/hydration/samples/expression-sibling/_after.html create mode 100644 test/hydration/samples/expression-sibling/_before.html create mode 100644 test/hydration/samples/expression-sibling/_config.js create mode 100644 test/hydration/samples/expression-sibling/main.svelte diff --git a/test/hydration/samples/expression-sibling/_after.html b/test/hydration/samples/expression-sibling/_after.html new file mode 100644 index 000000000000..9c0a0b57788f --- /dev/null +++ b/test/hydration/samples/expression-sibling/_after.html @@ -0,0 +1 @@ +

1 2 3

diff --git a/test/hydration/samples/expression-sibling/_before.html b/test/hydration/samples/expression-sibling/_before.html new file mode 100644 index 000000000000..9c0a0b57788f --- /dev/null +++ b/test/hydration/samples/expression-sibling/_before.html @@ -0,0 +1 @@ +

1 2 3

diff --git a/test/hydration/samples/expression-sibling/_config.js b/test/hydration/samples/expression-sibling/_config.js new file mode 100644 index 000000000000..9cc05547769c --- /dev/null +++ b/test/hydration/samples/expression-sibling/_config.js @@ -0,0 +1,19 @@ +export default { + snapshot(target) { + const p = target.querySelector("p"); + + return { + p, + text: p.childNodes[0], + span: p.querySelector("span"), + }; + }, + + test(assert, target, snapshot) { + const p = target.querySelector("p"); + + assert.equal(p, snapshot.p); + assert.equal(p.childNodes[0], snapshot.text); + assert.equal(p.querySelector("span"), snapshot.span); + }, +}; diff --git a/test/hydration/samples/expression-sibling/main.svelte b/test/hydration/samples/expression-sibling/main.svelte new file mode 100644 index 000000000000..65aa541e9cc0 --- /dev/null +++ b/test/hydration/samples/expression-sibling/main.svelte @@ -0,0 +1 @@ +

{1} 2 3

From 95235f2be5ed2a51880ab747ef743cf583a31630 Mon Sep 17 00:00:00 2001 From: haveyaseen Date: Sun, 2 May 2021 16:19:11 +0200 Subject: [PATCH 3/3] add test for hydration of nested element with if-block element sibling --- .../element-nested-sibling/_after.html | 4 ++++ .../element-nested-sibling/_before.html | 4 ++++ .../samples/element-nested-sibling/_config.js | 19 +++++++++++++++++++ .../element-nested-sibling/main.svelte | 6 ++++++ .../samples/expression-sibling/_config.js | 10 +++++----- 5 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 test/hydration/samples/element-nested-sibling/_after.html create mode 100644 test/hydration/samples/element-nested-sibling/_before.html create mode 100644 test/hydration/samples/element-nested-sibling/_config.js create mode 100644 test/hydration/samples/element-nested-sibling/main.svelte diff --git a/test/hydration/samples/element-nested-sibling/_after.html b/test/hydration/samples/element-nested-sibling/_after.html new file mode 100644 index 000000000000..d011cf6e3867 --- /dev/null +++ b/test/hydration/samples/element-nested-sibling/_after.html @@ -0,0 +1,4 @@ +

+ 1 + 2 +

diff --git a/test/hydration/samples/element-nested-sibling/_before.html b/test/hydration/samples/element-nested-sibling/_before.html new file mode 100644 index 000000000000..d011cf6e3867 --- /dev/null +++ b/test/hydration/samples/element-nested-sibling/_before.html @@ -0,0 +1,4 @@ +

+ 1 + 2 +

diff --git a/test/hydration/samples/element-nested-sibling/_config.js b/test/hydration/samples/element-nested-sibling/_config.js new file mode 100644 index 000000000000..8410fc189d95 --- /dev/null +++ b/test/hydration/samples/element-nested-sibling/_config.js @@ -0,0 +1,19 @@ +export default { + snapshot(target) { + const p = target.querySelector('p'); + + return { + p, + span: p.querySelector('span'), + code: p.querySelector('code') + }; + }, + + test(assert, target, snapshot) { + const p = target.querySelector('p'); + + assert.equal(p, snapshot.p); + assert.equal(p.querySelector('span'), snapshot.span); + assert.equal(p.querySelector('code'), snapshot.code); + } +}; diff --git a/test/hydration/samples/element-nested-sibling/main.svelte b/test/hydration/samples/element-nested-sibling/main.svelte new file mode 100644 index 000000000000..d6e02107e2c2 --- /dev/null +++ b/test/hydration/samples/element-nested-sibling/main.svelte @@ -0,0 +1,6 @@ +

+ 1 + {#if true} + 2 + {/if} +

diff --git a/test/hydration/samples/expression-sibling/_config.js b/test/hydration/samples/expression-sibling/_config.js index 9cc05547769c..c6d3ef3f2f76 100644 --- a/test/hydration/samples/expression-sibling/_config.js +++ b/test/hydration/samples/expression-sibling/_config.js @@ -1,19 +1,19 @@ export default { snapshot(target) { - const p = target.querySelector("p"); + const p = target.querySelector('p'); return { p, text: p.childNodes[0], - span: p.querySelector("span"), + span: p.querySelector('span') }; }, test(assert, target, snapshot) { - const p = target.querySelector("p"); + const p = target.querySelector('p'); assert.equal(p, snapshot.p); assert.equal(p.childNodes[0], snapshot.text); - assert.equal(p.querySelector("span"), snapshot.span); - }, + assert.equal(p.querySelector('span'), snapshot.span); + } };