diff --git a/.changeset/clever-toys-laugh.md b/.changeset/clever-toys-laugh.md new file mode 100644 index 0000000000..d1f72545bd --- /dev/null +++ b/.changeset/clever-toys-laugh.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: hydrate multiple `` elements correctly diff --git a/packages/svelte/src/internal/client/dom/blocks/svelte-head.js b/packages/svelte/src/internal/client/dom/blocks/svelte-head.js index bfd4291728..0fc2efa1eb 100644 --- a/packages/svelte/src/internal/client/dom/blocks/svelte-head.js +++ b/packages/svelte/src/internal/client/dom/blocks/svelte-head.js @@ -51,6 +51,7 @@ export function head(render_fn) { block(() => render_fn(anchor), HEAD_EFFECT); } finally { if (was_hydrating) { + head_anchor = hydrate_node; // so that next head block starts from the correct node set_hydrate_node(/** @type {TemplateNode} */ (previous_hydrate_node)); } } diff --git a/packages/svelte/tests/hydration/samples/head-html-and-component/HeadNested.svelte b/packages/svelte/tests/hydration/samples/head-html-and-component/HeadNested.svelte index 33bbdd1fd1..e9872ad897 100644 --- a/packages/svelte/tests/hydration/samples/head-html-and-component/HeadNested.svelte +++ b/packages/svelte/tests/hydration/samples/head-html-and-component/HeadNested.svelte @@ -1,2 +1,2 @@ {@html ''} - + diff --git a/packages/svelte/tests/hydration/samples/head-html-and-component/Nested.svelte b/packages/svelte/tests/hydration/samples/head-html-and-component/Nested.svelte index 28f5371910..308f44de38 100644 --- a/packages/svelte/tests/hydration/samples/head-html-and-component/Nested.svelte +++ b/packages/svelte/tests/hydration/samples/head-html-and-component/Nested.svelte @@ -1,5 +1,9 @@ + {@html ''} - + + diff --git a/packages/svelte/tests/hydration/samples/head-html-and-component/main.svelte b/packages/svelte/tests/hydration/samples/head-html-and-component/main.svelte index 188ecace6b..f11f24e42d 100644 --- a/packages/svelte/tests/hydration/samples/head-html-and-component/main.svelte +++ b/packages/svelte/tests/hydration/samples/head-html-and-component/main.svelte @@ -4,9 +4,12 @@ - {@html ''} - - + + {#if true} + {@html ''} + + + {/if} - +