Skip to content

add snippet symbol to children prop #9395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 12, 2023
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/tall-shrimps-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: add snippet marker symbol to children prop
Original file line number Diff line number Diff line change
Expand Up @@ -819,15 +819,21 @@ function serialize_inline_component(node, component_name, context) {
const body = create_block(node, `${node.name}_${slot_name}`, children[slot_name], context);
if (body.length === 0) continue;

const fn = b.arrow(
const slot_fn = b.arrow(
[b.id('$$anchor'), b.id('$$slotProps')],
b.block([...(slot_name === 'default' ? default_lets : []), ...body])
);

if (slot_name === 'default') {
push_prop(b.prop('init', b.id('children'), fn));
push_prop(
b.prop(
'init',
b.id('children'),
context.state.options.dev ? b.call('$.add_snippet_symbol', slot_fn) : slot_fn
)
);
} else {
serialized_slots.push(b.prop('init', b.key(slot_name), fn));
serialized_slots.push(b.prop('init', b.key(slot_name), slot_fn));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -847,26 +847,21 @@ function serialize_inline_component(node, component_name, context) {
const body = create_block(node, children[slot_name], context);
if (body.length === 0) continue;

const slot_fn = b.arrow(
[b.id('$$payload'), b.id('$$slotProps')],
b.block([...(slot_name === 'default' ? default_lets : []), ...body])
);

if (slot_name === 'default') {
push_prop(
b.prop(
'init',
b.id('children'),
b.arrow(
[b.id('$$payload'), b.id('$$slotProps')],
b.block([...(slot_name === 'default' ? default_lets : []), ...body])
)
context.state.options.dev ? b.call('$.add_snippet_symbol', slot_fn) : slot_fn
)
);
} else {
const slot = b.prop(
'init',
b.literal(slot_name),
b.arrow(
[b.id('$$payload'), b.id('$$slotProps')],
b.block([...(slot_name === 'default' ? default_lets : []), ...body])
)
);
const slot = b.prop('init', b.literal(slot_name), slot_fn);
serialized_slots.push(slot);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/src/internal/client/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export function add_snippet_symbol(fn) {
export function validate_snippet(snippet_fn) {
if (snippet_fn[symbol] !== true) {
throw new Error(
'The argument to `{@html ...}` must be a snippet function, not a component or some other kind of function. ' +
'The argument to `{@render ...}` must be a snippet function, not a component or some other kind of function. ' +
'If you want to dynamically render one snippet or another, use `$derived` and pass its result to `{@render ...}`.'
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ export default test({
dev: true
},
error:
'The argument to `{@html ...}` must be a snippet function, not a component or some other kind of function. ' +
'The argument to `{@render ...}` must be a snippet function, not a component or some other kind of function. ' +
'If you want to dynamically render one snippet or another, use `$derived` and pass its result to `{@render ...}`.'
});