Skip to content

Commit ee1249b

Browse files
authored
fix: preserve renderer type in copy() during SSR (#18616)
Fixes #18404 `<svelte:head>` combined with two or more components that each use `bind:` on a child component's prop corrupts a renderer's `.type` during SSR, misplacing the head hydration marker in `<body>` instead of `<head>`. Reason: `copy()` (`packages/svelte/src/internal/server/renderer.js`) rebuilds via `new Renderer(this.global, this.#parent)`. That constructor defaults `.type` from the *parent's* current type, not from `this.type`. To fix it we therefore reassign it (like already do for the boundary elsewhere)
1 parent 9c2494b commit ee1249b

7 files changed

Lines changed: 31 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: don't corrupt renderer type during SSR's legacy `bind:` retry loop

‎packages/svelte/src/internal/server/renderer.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ export class Renderer {
451451
*/
452452
copy() {
453453
const copy = new Renderer(this.global, this.#parent);
454+
copy.type = this.type;
454455
copy.#out = this.#out.map((item) => (item instanceof Renderer ? item.copy() : item));
455456
copy.promise = this.promise;
456457
return copy;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<script>
2+
let { bar = $bindable() } = $props();
3+
</script>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<script>
2+
import Foo from './Foo.svelte';
3+
let bar = $state();
4+
</script>
5+
6+
<Foo bind:bar />

‎packages/svelte/tests/server-side-rendering/samples/head-with-multiple-binding-components/_expected.html‎

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<!--ssr:0-->
2+
<link rel="canonical" href="/test">
3+
<meta name="description" content="test">
4+
<!--ssr:0-->
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<script>
2+
import Wrapper from './Wrapper.svelte';
3+
</script>
4+
5+
<svelte:head>
6+
<link rel="canonical" href="/test" />
7+
<meta name="description" content="test" />
8+
</svelte:head>
9+
10+
<Wrapper />
11+
<Wrapper />
12+
<Wrapper />

0 commit comments

Comments
 (0)