mirror of https://github.com/sveltejs/svelte
When the each block expression is a $derived that wraps a store subscription, the compiler now traces through the derived binding's init expression to detect the underlying store. This enables proper store invalidation on mutation and prevents setting EACH_ITEM_IMMUTABLE, ensuring bind: works correctly. Additionally, store-backed $derived declarations now use safe equality instead of strict reference equality, so mutations to same-reference objects are detected and propagated to all subscribers. Closes #13569pull/17637/head
parent
660c4c12b1
commit
a2df7336af
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
Fixed `bind:` not working in `{#each}` blocks when the expression is a `$derived` that references a store (e.g. `{#each $derived($store) as item}`). The compiler now traces through derived bindings to detect underlying store subscriptions, ensuring proper store invalidation and mutable item tracking.
|
||||
@ -0,0 +1,25 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { ok, test } from '../../test';
|
||||
|
||||
export default test({
|
||||
html: `<input> <p>initial</p>`,
|
||||
ssrHtml: `<input value="initial"> <p>initial</p>`,
|
||||
|
||||
test({ assert, target, window }) {
|
||||
const input = target.querySelector('input');
|
||||
ok(input);
|
||||
|
||||
const event = new window.Event('input');
|
||||
input.value = 'changed';
|
||||
input.dispatchEvent(event);
|
||||
flushSync();
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<input>
|
||||
<p>changed</p>
|
||||
`
|
||||
);
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,12 @@
|
||||
<script>
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
const store = writable([{ text: 'initial' }]);
|
||||
const items = $derived($store);
|
||||
</script>
|
||||
|
||||
{#each items as item}
|
||||
<input bind:value={item.text} />
|
||||
{/each}
|
||||
|
||||
<p>{items[0].text}</p>
|
||||
Loading…
Reference in new issue