mirror of https://github.com/sveltejs/svelte
fix: improve indexed each array reconcilation (#10422)
* fix: improve indexed each array reconcilation * simplifypull/10430/head
parent
623340a1de
commit
0e011add4e
@ -0,0 +1,5 @@
|
||||
---
|
||||
"svelte": patch
|
||||
---
|
||||
|
||||
fix: improve indexed each array reconcilation
|
@ -0,0 +1,43 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
html: `<ul><li><button>Delete</button>\na\na</li><li><button>Delete</button>\nb\nb</li><li><button>Delete</button>\nc\nc</li><li><button>Delete</button>\nd\nd</li></ul>`,
|
||||
|
||||
async test({ assert, target }) {
|
||||
/**
|
||||
* @type {{ click: () => void; }}
|
||||
*/
|
||||
let btn1;
|
||||
|
||||
[btn1] = target.querySelectorAll('button');
|
||||
|
||||
flushSync(() => {
|
||||
btn1.click();
|
||||
});
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`<ul><li><button>Delete</button>\nb\nb</li><li><button>Delete</button>\nc\nc</li><li><button>Delete</button>\nd\nd</li></ul>`
|
||||
);
|
||||
|
||||
[btn1] = target.querySelectorAll('button');
|
||||
|
||||
flushSync(() => {
|
||||
btn1.click();
|
||||
});
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`<ul><li><button>Delete</button>\nc\nc</li><li><button>Delete</button>\nd\nd</li></ul>`
|
||||
);
|
||||
|
||||
[btn1] = target.querySelectorAll('button');
|
||||
|
||||
flushSync(() => {
|
||||
btn1.click();
|
||||
});
|
||||
|
||||
assert.htmlEqual(target.innerHTML, `<ul><li><button>Delete</button>\nd\nd</li></ul>`);
|
||||
}
|
||||
});
|
@ -0,0 +1,36 @@
|
||||
<script>
|
||||
let entries = $state([
|
||||
{
|
||||
id: 'a',
|
||||
subitems: ['a'],
|
||||
},
|
||||
{
|
||||
id: 'b',
|
||||
subitems: ['b'],
|
||||
},
|
||||
{
|
||||
id: 'c',
|
||||
subitems: ['c'],
|
||||
},
|
||||
{
|
||||
id: 'd',
|
||||
subitems: ['d'],
|
||||
},
|
||||
]);
|
||||
|
||||
function onDeleteEntry(entry) {
|
||||
entries = entries.filter((innerEntry) => innerEntry.id !== entry.id);
|
||||
}
|
||||
</script>
|
||||
|
||||
<ul>
|
||||
{#each entries as entry}
|
||||
<li>
|
||||
<button on:click={() => onDeleteEntry(entry)}>Delete</button>
|
||||
{entry.id}
|
||||
{#each entry.subitems as subitem}
|
||||
{subitem}
|
||||
{/each}
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
Loading…
Reference in new issue