Skip to content

Commit b6bf735

Browse files
fix: correctly ssr component in svelte:head with $props.id() or css='injected' (#15291)
1 parent 21dadfc commit b6bf735

File tree

6 files changed

+29
-3
lines changed

6 files changed

+29
-3
lines changed

.changeset/thirty-feet-tap.md

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: correctly ssr component in `svelte:head` with `$props.id()` or `css='injected'`

packages/svelte/src/internal/server/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ export function copy_payload({ out, css, head, uid }) {
3434
css: new Set(css),
3535
head: {
3636
title: head.title,
37-
out: head.out
37+
out: head.out,
38+
css: new Set(head.css),
39+
uid: head.uid
3840
},
3941
uid
4042
};
@@ -99,12 +101,13 @@ function props_id_generator() {
99101
* @returns {RenderOutput}
100102
*/
101103
export function render(component, options = {}) {
104+
const uid = options.uid ?? props_id_generator();
102105
/** @type {Payload} */
103106
const payload = {
104107
out: '',
105108
css: new Set(),
106-
head: { title: '', out: '' },
107-
uid: options.uid ?? props_id_generator()
109+
head: { title: '', out: '', css: new Set(), uid },
110+
uid
108111
};
109112

110113
const prev_on_destroy = on_destroy;

packages/svelte/src/internal/server/types.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export interface Payload {
1717
head: {
1818
title: string;
1919
out: string;
20+
uid: () => string;
21+
css: Set<{ hash: string; code: string }>;
2022
};
2123
/** Function that generates a unique ID */
2224
uid: () => string;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script>
2+
let id = $props.id();
3+
</script>
4+
5+
<meta name="id" content={id} />
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { test } from '../../test';
2+
3+
export default test({});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<script>
2+
import HeadNested from './HeadNested.svelte';
3+
</script>
4+
5+
<svelte:head>
6+
<HeadNested />
7+
</svelte:head>
8+

0 commit comments

Comments
 (0)