fix: hydrate multiple `<svelte:head>` elements correctly (#12475)

The head hydration anchor didn't update after hydrating the contents of one `<svelte:head>` element, which meant subsequent `<svelte:head>` elements would always start at the beginning of the head. This PR fixes that. The test was updated such that the shape of each `<svelte:head>` content is sufficiently different to throw an error if this wasn't fixed.

fixes #12458
pull/12478/head
Simon H 5 months ago committed by GitHub
parent 4fd6d29227
commit bc9907aa1c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: hydrate multiple `<svelte:head>` elements correctly

@ -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));
}
}

@ -1,2 +1,2 @@
{@html '<meta name="head_nested_html" content="head_nested_html">'}
<meta name="head_nested" content="head_nested">
<meta name="head_nested" content="head_nested" />

@ -1,5 +1,9 @@
<script>
let text = $state('foo');
</script>
<svelte:head>
{@html '<meta name="nested_html" content="nested_html">'}
<meta name="nested" content="nested">
<meta name="nested" content="nested" />
<meta name="foo" content={text} />
</svelte:head>

@ -4,9 +4,12 @@
</script>
<svelte:head>
<!-- the if block forces a comment node; tests that the nested head starts at the correct node -->
{#if true}
{@html '<meta name="main_html" content="main_html">'}
<meta name="main" content="main">
<meta name="main" content="main" />
<HeadNested />
{/if}
</svelte:head>
<Nested/>
<Nested />

Loading…
Cancel
Save