diff --git a/.changeset/big-geese-act.md b/.changeset/big-geese-act.md new file mode 100644 index 0000000000..08e1e29d15 --- /dev/null +++ b/.changeset/big-geese-act.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: only throw bind error when not passing a value diff --git a/packages/svelte/src/internal/client/runtime.js b/packages/svelte/src/internal/client/runtime.js index 21abccf38e..1fe72efa41 100644 --- a/packages/svelte/src/internal/client/runtime.js +++ b/packages/svelte/src/internal/client/runtime.js @@ -1567,16 +1567,20 @@ export function is_store(val) { export function prop(props, key, flags, initial) { var immutable = (flags & PROPS_IS_IMMUTABLE) !== 0; var runes = (flags & PROPS_IS_RUNES) !== 0; - - var setter = get_descriptor(props, key)?.set; - if (DEV && setter && runes && initial !== undefined) { - // TODO consolidate all these random runtime errors - throw new Error('Cannot use fallback values with bind:'); - } - var prop_value = /** @type {V} */ (props[key]); + var setter = get_descriptor(props, key)?.set; if (prop_value === undefined && initial !== undefined) { + if (setter && runes) { + // TODO consolidate all these random runtime errors + throw new Error( + 'ERR_SVELTE_BINDING_FALLBACK' + + (DEV + ? `: Cannot pass undefined to bind:${key} because the property contains a fallback value. Pass a different value than undefined to ${key}.` + : '') + ); + } + // @ts-expect-error would need a cumbersome method overload to type this if ((flags & PROPS_IS_LAZY_INITIAL) !== 0) initial = initial(); diff --git a/packages/svelte/tests/runtime-runes/samples/props-bound-fallback/_config.js b/packages/svelte/tests/runtime-runes/samples/props-bound-fallback/_config.js index 6dc700cee5..f382120e88 100644 --- a/packages/svelte/tests/runtime-runes/samples/props-bound-fallback/_config.js +++ b/packages/svelte/tests/runtime-runes/samples/props-bound-fallback/_config.js @@ -14,5 +14,5 @@ export default test({ assert.htmlEqual(target.innerHTML, `1`); }, - error: `Cannot use fallback values with bind:` + error: `ERR_SVELTE_BINDING_FALLBACK: Cannot pass undefined to bind:count because the property contains a fallback value. Pass a different value than undefined to count.` });