mirror of https://github.com/sveltejs/svelte
breaking: disallow binding to component exports in runes mode (#11238)
* breaking: disallow binding to component exports in runes mode Svelte 4 allowed you to have `export const foo = ..` in component A and then do `<A bind:foo />`. This is confusing because it's not clear whether the binding is for a property or an export, and we have to sanitize rest props from the export bindings. This PR therefore introduces a breaking change in runes mode: You cannot bind to these exports anymore. Instead use `<A bind:this={a} />` and then do `a.foo` - makes things easier to reason about. * Update sites/svelte-5-preview/src/routes/docs/content/03-appendix/02-breaking-changes.md Co-authored-by: Rich Harris <rich.harris@vercel.com> * tweak messages * fix tests * use component.name * oops --------- Co-authored-by: Rich Harris <rich.harris@vercel.com>pull/11296/head
parent
e3c8589737
commit
2d378bb762
@ -0,0 +1,5 @@
|
||||
---
|
||||
"svelte": patch
|
||||
---
|
||||
|
||||
breaking: disallow binding to component exports in runes mode
|
@ -1,12 +0,0 @@
|
||||
<script>
|
||||
let { ...rest } = $props();
|
||||
let count = $state(0);
|
||||
export function increment() {
|
||||
count++;
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- test that the binding isn't inside rest -->
|
||||
{Object.keys(rest).length}
|
||||
|
||||
{count}
|
@ -0,0 +1,8 @@
|
||||
<script>
|
||||
let count = $state(0);
|
||||
export function increment() {
|
||||
count++;
|
||||
}
|
||||
</script>
|
||||
|
||||
{count}
|
@ -1,7 +1,7 @@
|
||||
<script>
|
||||
import Counter from './Counter.svelte';
|
||||
import Counter from './counter/index.svelte';
|
||||
let increment;
|
||||
</script>
|
||||
|
||||
<Counter bind:increment={increment} />
|
||||
<button onclick={increment}>increment</button>
|
||||
<button onclick={increment}>increment</button>
|
||||
|
Loading…
Reference in new issue