Skip to content

fix: only throw bind error when not passing a value #10090

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 6 commits into from
Feb 12, 2024
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/big-geese-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: only throw bind error when not passing a value
18 changes: 11 additions & 7 deletions packages/svelte/src/internal/client/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ export default test({
assert.htmlEqual(target.innerHTML, `<button>1</button><span>1</span>`);
},

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.`
});