Skip to content
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

fix: don't throw bind_invalid_export if there's also a bindable prop with the same name #14813

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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/tidy-dragons-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: don't throw `bind_invalid_export` if there's also a bindable prop with the same name
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 @@ -50,7 +50,7 @@ export function validate_prop_bindings($$props, bindable, exports, component) {
var name = component.name;

if (setter) {
if (exports.includes(key)) {
if (exports.includes(key) && !bindable.includes(key)) {
e.bind_invalid_export(component[FILENAME], key, name);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script>
let { open: is_open = $bindable() } = $props();

export function open(){
is_open = !is_open;
}
</script>

<button onclick={open}>{is_open}</button>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { ok, test } from '../../test';
import { flushSync } from 'svelte';

export default test({
compileOptions: {
dev: true
},
html: `<button>true</button><button>true</button><input type="checkbox" />`,
ssrHtml: `<button>true</button><button>true</button><input type="checkbox" checked=""/>`,

async test({ assert, target, instance }) {
const [btn1, btn2] = target.querySelectorAll('button');
const input = target.querySelector('input');
flushSync(() => {
btn1.click();
});
assert.equal(btn1.innerHTML, 'false');
assert.equal(btn2.innerHTML, 'false');
assert.equal(input?.checked, false);

flushSync(() => {
btn2.click();
});
assert.equal(btn1.innerHTML, 'true');
assert.equal(btn2.innerHTML, 'true');
assert.equal(input?.checked, true);

flushSync(() => {
input?.click();
});
assert.equal(btn1.innerHTML, 'false');
assert.equal(btn2.innerHTML, 'false');
assert.equal(input?.checked, false);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<script>
import Component from "./Component.svelte";

let open = $state(true);
let comp;
</script>

<Component bind:this={comp} bind:open />

<button onclick={()=>{
comp.open();
}}>{open}</button>

<input type="checkbox" bind:checked={open} />
Loading