mirror of https://github.com/sveltejs/svelte
fix: ensure each block consistency to internal mutations to the collection (#13614)
* fix: ensure bind_checked defers mutation to ensure reactive graph stability * better fix * better fix * better fix * better fix * lint * simplifypull/13621/head
parent
ed790ee166
commit
75fecf82a6
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: ensure each block consistency to internal mutations to the collection
|
@ -0,0 +1,16 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
async test({ assert, target }) {
|
||||
const button = target.querySelector('button');
|
||||
|
||||
button?.click();
|
||||
flushSync();
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`<button>Add</button><label><input type="checkbox"></label><label><input type="checkbox"></label>`
|
||||
);
|
||||
}
|
||||
});
|
@ -0,0 +1,7 @@
|
||||
<script>
|
||||
let { value = $bindable() } = $props();
|
||||
</script>
|
||||
|
||||
<label>
|
||||
<input type="checkbox" bind:checked={value} />
|
||||
</label>
|
@ -0,0 +1,28 @@
|
||||
<script>
|
||||
import Checkbox from './checkbox.svelte';
|
||||
|
||||
let foo = $state({})
|
||||
|
||||
const schema = $state({
|
||||
foo: true,
|
||||
})
|
||||
|
||||
function retrieveSchema() {
|
||||
const cloned = { ...schema }
|
||||
for (const key of Object.keys(foo)) {
|
||||
cloned[key] = key
|
||||
}
|
||||
return cloned
|
||||
}
|
||||
|
||||
const keys = $derived(Object.keys(retrieveSchema()));
|
||||
let nextKey = 1;
|
||||
</script>
|
||||
|
||||
<button onclick={() => {
|
||||
foo[nextKey++] = true
|
||||
}}>Add</button>
|
||||
|
||||
{#each keys as key (key)}
|
||||
<Checkbox bind:value={foo[key]} />
|
||||
{/each}
|
Loading…
Reference in new issue