mirror of https://github.com/sveltejs/svelte
parent
23484d6875
commit
7d62528f7a
@ -0,0 +1,5 @@
|
||||
---
|
||||
"svelte": patch
|
||||
---
|
||||
|
||||
fix: ensure correct each block element is moved during reconcilation
|
@ -0,0 +1,27 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
html: `<ul><li>test (1) <span style="background-color: red; width: 20px; height: 20px; display: inline-block;"></span></li><li>test 2 (2)</li><li>test 3 (3)</li></ul><button>Swap items 1 & 3</button>`,
|
||||
|
||||
async test({ assert, target }) {
|
||||
const [btn1] = target.querySelectorAll('button');
|
||||
|
||||
flushSync(() => {
|
||||
btn1.click();
|
||||
});
|
||||
|
||||
flushSync(() => {
|
||||
btn1.click();
|
||||
});
|
||||
|
||||
flushSync(() => {
|
||||
btn1.click();
|
||||
});
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`<ul><li>test (1) <span style="background-color: red; width: 20px; height: 20px; display: inline-block;"></span></li><li>test 2 (2)</li><li>test 3 (3)</li></ul><button>Swap items 1 & 3</button>`
|
||||
);
|
||||
}
|
||||
});
|
@ -0,0 +1,26 @@
|
||||
<script>
|
||||
const items = $state([
|
||||
{ name: 'test', id: 1, color: 'red' },
|
||||
{ name: 'test 2', id: 2 },
|
||||
{ name: 'test 3', id: 3 },
|
||||
]);
|
||||
const onclick = () => {
|
||||
const from = 0;
|
||||
const to = 2;
|
||||
items.splice(to, 0, items.splice(from, 1)[0]);
|
||||
};
|
||||
</script>
|
||||
|
||||
{#snippet renderItem(item)}
|
||||
<li>
|
||||
{item.name} ({item.id})
|
||||
{#if item.color}<span style="background-color: {item.color}; width: 20px; height: 20px; display: inline-block;"></span>{/if}
|
||||
</li>
|
||||
{/snippet}
|
||||
|
||||
<ul>
|
||||
{#each items as item (item.id)}
|
||||
{@render renderItem(item)}
|
||||
{/each}
|
||||
</ul>
|
||||
<button {onclick}>Swap items 1 & 3</button>
|
Loading…
Reference in new issue