Skip to content

Commit a6abcf1

Browse files
committed
address feedback
1 parent 116de3e commit a6abcf1

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

packages/svelte/src/internal/client/dom/blocks/snippet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export function wrap_snippet(component, fn) {
6767
* @param {{
6868
* mount: (...params: any[]) => Element,
6969
* hydrate?: (element: Element, ...params: any[]) => void,
70-
* render: (...params: any[]) => string
70+
* render: (...params: any[]) => { head: string, body: string }
7171
* }} options
7272
*/
7373
export function createRawSnippet({ mount, hydrate }) {

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,18 @@ export function head(payload, fn) {
160160
* @param {{
161161
* mount: (...params: any[]) => Element,
162162
* hydrate?: (element: Element, ...params: any[]) => void,
163-
* render: (...params: any[]) => string
163+
* render: (...params: any[]) => { head: string, body: string }
164164
* }} options
165165
*/
166166
export function createRawSnippet({ render }) {
167167
const snippet_fn = (/** @type {Payload} */ payload, /** @type {any[]} */ ...args) => {
168-
payload.out += render(...args);
168+
const { head, body } = render(...args);
169+
if (body) {
170+
payload.out += body;
171+
}
172+
if (head) {
173+
payload.head.out += body;
174+
}
169175
};
170176
add_snippet_symbol(snippet_fn);
171177
return snippet_fn;
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script>
2-
import { createRawSnippet } from 'svelte';
2+
import { createRawSnippet } from 'svelte';
33
44
let count = $state(0);
55
@@ -14,19 +14,16 @@
1414
return div;
1515
},
1616
hydrate(element, count) {
17-
1817
$effect(() => {
1918
element.textContent = count();
2019
});
21-
2220
},
2321
render(count) {
24-
return `<div>${count}</div>`;
22+
return { body: `<div>${count}</div>` };
2523
}
2624
});
2725
</script>
2826

29-
<div>
30-
{@render snippet(count)}
31-
</div>
27+
{@render snippet(count)}
28+
3229
<button onclick={() => count++}>+</button>

packages/svelte/tests/runtime-runes/samples/snippet-raw/main.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
return p;
99
},
1010
render() {
11-
return '<p>hello world</p>';
11+
return { body: '<p>hello world</p>' };
1212
}
1313
});
1414
</script>

0 commit comments

Comments
 (0)