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); } } 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
+
+ 1
+ 2
+
+ 1
+ {#if true}
+ 2
+ {/if}
+
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..c6d3ef3f2f76 --- /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