mirror of https://github.com/sveltejs/svelte
fix: detect store in each block expression regardless of AST shape (#17636)
The store invalidation detection in each blocks only checked for
Identifier and MemberExpression AST node types. This caused bind:
on iteration variables to silently fail when the expression used
logical operators (e.g. `{#each $store.items ?? [] as item}`).
Use expression metadata dependencies instead of AST type checking
to find store_sub bindings, which correctly handles all expression
shapes.
Fixes #14625
pull/17640/head
parent
660c4c12b1
commit
a75866f34d
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: detect store in each block expression regardless of AST shape
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
import { flushSync } from 'svelte';
|
||||||
|
import { ok, test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
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,13 @@
|
|||||||
|
<script>
|
||||||
|
import { writable } from 'svelte/store';
|
||||||
|
|
||||||
|
const items = writable([
|
||||||
|
{ id: 0, text: 'initial' }
|
||||||
|
]);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#each $items ?? [] as item}
|
||||||
|
<input bind:value={item.text}>
|
||||||
|
{/each}
|
||||||
|
|
||||||
|
<p>{$items[0].text}</p>
|
||||||
Loading…
Reference in new issue