diff --git a/.changeset/shaggy-comics-jog.md b/.changeset/shaggy-comics-jog.md new file mode 100644 index 000000000000..cb5d956eb8e6 --- /dev/null +++ b/.changeset/shaggy-comics-jog.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: ensure `$$slots` returns a record of booleans diff --git a/packages/svelte/src/internal/client/dom/blocks/slot.js b/packages/svelte/src/internal/client/dom/blocks/slot.js index 6ef1885e007c..7db3aa114b9f 100644 --- a/packages/svelte/src/internal/client/dom/blocks/slot.js +++ b/packages/svelte/src/internal/client/dom/blocks/slot.js @@ -13,3 +13,17 @@ export function slot(anchor, slot_fn, slot_props, fallback_fn) { slot_fn(anchor, slot_props); } } + +/** + * @param {Record} props + * @returns {Record} + */ +export function sanitize_slots(props) { + /** @type {Record} */ + const sanitized = {}; + if (props.children) sanitized.default = true; + for (const key in props.$$slots) { + sanitized[key] = true; + } + return sanitized; +} diff --git a/packages/svelte/src/internal/client/index.js b/packages/svelte/src/internal/client/index.js index 4575f75f0dc8..a847cebe27b3 100644 --- a/packages/svelte/src/internal/client/index.js +++ b/packages/svelte/src/internal/client/index.js @@ -15,7 +15,7 @@ export { key_block as key } from './dom/blocks/key.js'; export { css_props } from './dom/blocks/css-props.js'; export { index, each } from './dom/blocks/each.js'; export { html } from './dom/blocks/html.js'; -export { slot } from './dom/blocks/slot.js'; +export { sanitize_slots, slot } from './dom/blocks/slot.js'; export { snippet, wrap_snippet } from './dom/blocks/snippet.js'; export { component } from './dom/blocks/svelte-component.js'; export { element } from './dom/blocks/svelte-element.js'; @@ -119,7 +119,7 @@ export { update_pre_store, update_store } from './reactivity/store.js'; -export { append_styles, sanitize_slots, set_text } from './render.js'; +export { append_styles, set_text } from './render.js'; export { get, invalidate_inner_signals, diff --git a/packages/svelte/src/internal/client/render.js b/packages/svelte/src/internal/client/render.js index 7dfa69585162..4e1fba2bd4a7 100644 --- a/packages/svelte/src/internal/client/render.js +++ b/packages/svelte/src/internal/client/render.js @@ -267,16 +267,6 @@ export function unmount(component) { fn?.(); } -/** - * @param {Record} props - * @returns {Record} - */ -export function sanitize_slots(props) { - const sanitized = { ...props.$$slots }; - if (props.children) sanitized.default = props.children; - return sanitized; -} - /** * @param {Node} target * @param {string} style_sheet_id diff --git a/packages/svelte/src/internal/server/index.js b/packages/svelte/src/internal/server/index.js index fc3ad10d30f2..6597755fef7f 100644 --- a/packages/svelte/src/internal/server/index.js +++ b/packages/svelte/src/internal/server/index.js @@ -446,11 +446,15 @@ export function sanitize_props(props) { /** * @param {Record} props - * @returns {Record} + * @returns {Record} */ export function sanitize_slots(props) { - const sanitized = { ...props.$$slots }; - if (props.children) sanitized.default = props.children; + /** @type {Record} */ + const sanitized = {}; + if (props.children) sanitized.default = true; + for (const key in props.$$slots) { + sanitized[key] = true; + } return sanitized; } diff --git a/packages/svelte/tests/runtime-legacy/samples/slot/A.svelte b/packages/svelte/tests/runtime-legacy/samples/slot/A.svelte index ad125d182382..35a05a209a94 100644 --- a/packages/svelte/tests/runtime-legacy/samples/slot/A.svelte +++ b/packages/svelte/tests/runtime-legacy/samples/slot/A.svelte @@ -1,21 +1,20 @@ @@ -24,9 +23,9 @@ $$slots: {toString($$slots)} {#if $$slots.b} -
- -
+
+ +
{:else} - Slot b is not available + Slot b is not available {/if}