Skip to content

Commit 7a84e78

Browse files
authored
fix: add snippet symbol to children prop (#9395)
* add snippet symbol to children prop * fix error message for snippet validation * changeset
1 parent 304a29e commit 7a84e78

File tree

5 files changed

+23
-17
lines changed

5 files changed

+23
-17
lines changed

.changeset/tall-shrimps-worry.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: add snippet marker symbol to children prop

packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -819,15 +819,21 @@ function serialize_inline_component(node, component_name, context) {
819819
const body = create_block(node, `${node.name}_${slot_name}`, children[slot_name], context);
820820
if (body.length === 0) continue;
821821

822-
const fn = b.arrow(
822+
const slot_fn = b.arrow(
823823
[b.id('$$anchor'), b.id('$$slotProps')],
824824
b.block([...(slot_name === 'default' ? default_lets : []), ...body])
825825
);
826826

827827
if (slot_name === 'default') {
828-
push_prop(b.prop('init', b.id('children'), fn));
828+
push_prop(
829+
b.prop(
830+
'init',
831+
b.id('children'),
832+
context.state.options.dev ? b.call('$.add_snippet_symbol', slot_fn) : slot_fn
833+
)
834+
);
829835
} else {
830-
serialized_slots.push(b.prop('init', b.key(slot_name), fn));
836+
serialized_slots.push(b.prop('init', b.key(slot_name), slot_fn));
831837
}
832838
}
833839

packages/svelte/src/compiler/phases/3-transform/server/transform-server.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -847,26 +847,21 @@ function serialize_inline_component(node, component_name, context) {
847847
const body = create_block(node, children[slot_name], context);
848848
if (body.length === 0) continue;
849849

850+
const slot_fn = b.arrow(
851+
[b.id('$$payload'), b.id('$$slotProps')],
852+
b.block([...(slot_name === 'default' ? default_lets : []), ...body])
853+
);
854+
850855
if (slot_name === 'default') {
851856
push_prop(
852857
b.prop(
853858
'init',
854859
b.id('children'),
855-
b.arrow(
856-
[b.id('$$payload'), b.id('$$slotProps')],
857-
b.block([...(slot_name === 'default' ? default_lets : []), ...body])
858-
)
860+
context.state.options.dev ? b.call('$.add_snippet_symbol', slot_fn) : slot_fn
859861
)
860862
);
861863
} else {
862-
const slot = b.prop(
863-
'init',
864-
b.literal(slot_name),
865-
b.arrow(
866-
[b.id('$$payload'), b.id('$$slotProps')],
867-
b.block([...(slot_name === 'default' ? default_lets : []), ...body])
868-
)
869-
);
864+
const slot = b.prop('init', b.literal(slot_name), slot_fn);
870865
serialized_slots.push(slot);
871866
}
872867
}

packages/svelte/src/internal/client/validate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export function add_snippet_symbol(fn) {
119119
export function validate_snippet(snippet_fn) {
120120
if (snippet_fn[symbol] !== true) {
121121
throw new Error(
122-
'The argument to `{@html ...}` must be a snippet function, not a component or some other kind of function. ' +
122+
'The argument to `{@render ...}` must be a snippet function, not a component or some other kind of function. ' +
123123
'If you want to dynamically render one snippet or another, use `$derived` and pass its result to `{@render ...}`.'
124124
);
125125
}

packages/svelte/tests/runtime-runes/samples/snippet-validation-error/_config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ export default test({
55
dev: true
66
},
77
error:
8-
'The argument to `{@html ...}` must be a snippet function, not a component or some other kind of function. ' +
8+
'The argument to `{@render ...}` must be a snippet function, not a component or some other kind of function. ' +
99
'If you want to dynamically render one snippet or another, use `$derived` and pass its result to `{@render ...}`.'
1010
});

0 commit comments

Comments
 (0)