Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/thirty-feet-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: correctly ssr component in `svelte:head` with `$props.id()` or `css='injected'`
9 changes: 6 additions & 3 deletions packages/svelte/src/internal/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export function copy_payload({ out, css, head, uid }) {
css: new Set(css),
head: {
title: head.title,
out: head.out
out: head.out,
css: new Set(head.css),
uid: head.uid
},
uid
};
Expand Down Expand Up @@ -99,12 +101,13 @@ function props_id_generator() {
* @returns {RenderOutput}
*/
export function render(component, options = {}) {
const uid = options.uid ?? props_id_generator();
/** @type {Payload} */
const payload = {
out: '',
css: new Set(),
head: { title: '', out: '' },
uid: options.uid ?? props_id_generator()
head: { title: '', out: '', css: new Set(), uid },
uid
};

const prev_on_destroy = on_destroy;
Expand Down
2 changes: 2 additions & 0 deletions packages/svelte/src/internal/server/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export interface Payload {
head: {
title: string;
out: string;
uid: () => string;
css: Set<{ hash: string; code: string }>;
};
/** Function that generates a unique ID */
uid: () => string;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
let id = $props.id();
</script>

<meta name="id" content={id} />
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { test } from '../../test';

export default test({});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script>
import HeadNested from './HeadNested.svelte';
</script>

<svelte:head>
<HeadNested />
</svelte:head>