Skip to content

Commit 72a6c72

Browse files
fix: don't throw bind_invalid_export if there's also a bindable prop with the same name (#14813)
1 parent cd1adbc commit 72a6c72

File tree

5 files changed

+64
-1
lines changed

5 files changed

+64
-1
lines changed

.changeset/tidy-dragons-thank.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: don't throw `bind_invalid_export` if there's also a bindable prop with the same name

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export function validate_prop_bindings($$props, bindable, exports, component) {
5050
var name = component.name;
5151

5252
if (setter) {
53-
if (exports.includes(key)) {
53+
if (exports.includes(key) && !bindable.includes(key)) {
5454
e.bind_invalid_export(component[FILENAME], key, name);
5555
}
5656

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script>
2+
let { open: is_open = $bindable() } = $props();
3+
4+
export function open(){
5+
is_open = !is_open;
6+
}
7+
</script>
8+
9+
<button onclick={open}>{is_open}</button>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { ok, test } from '../../test';
2+
import { flushSync } from 'svelte';
3+
4+
export default test({
5+
compileOptions: {
6+
dev: true
7+
},
8+
html: `<button>true</button><button>true</button><input type="checkbox" />`,
9+
ssrHtml: `<button>true</button><button>true</button><input type="checkbox" checked=""/>`,
10+
11+
async test({ assert, target, instance }) {
12+
const [btn1, btn2] = target.querySelectorAll('button');
13+
const input = target.querySelector('input');
14+
flushSync(() => {
15+
btn1.click();
16+
});
17+
assert.equal(btn1.innerHTML, 'false');
18+
assert.equal(btn2.innerHTML, 'false');
19+
assert.equal(input?.checked, false);
20+
21+
flushSync(() => {
22+
btn2.click();
23+
});
24+
assert.equal(btn1.innerHTML, 'true');
25+
assert.equal(btn2.innerHTML, 'true');
26+
assert.equal(input?.checked, true);
27+
28+
flushSync(() => {
29+
input?.click();
30+
});
31+
assert.equal(btn1.innerHTML, 'false');
32+
assert.equal(btn2.innerHTML, 'false');
33+
assert.equal(input?.checked, false);
34+
}
35+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<script>
2+
import Component from "./Component.svelte";
3+
4+
let open = $state(true);
5+
let comp;
6+
</script>
7+
8+
<Component bind:this={comp} bind:open />
9+
10+
<button onclick={()=>{
11+
comp.open();
12+
}}>{open}</button>
13+
14+
<input type="checkbox" bind:checked={open} />

0 commit comments

Comments
 (0)