mirror of https://github.com/sveltejs/svelte
fix: link offscreen items and last effect in each block correctly (#17240)
* fix: link offscreen items and last effect in each block correctly It's possible that due to how new elements are inserted into the array that `effect.last` is wrong. We need to ensure it is really the last item to keep items properly connected to the graph. In addition we link offscreen items after all onscreen items, to ensure they don't have wrong pointers. Fixes #17201 * revert #17244 * add testpull/17253/head
parent
1bc3ae7cbf
commit
da4cd0e359
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: link offscreen items and last effect in each block correctly
|
||||
@ -0,0 +1,32 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
async test({ assert, target }) {
|
||||
const [add4, add5, modify3] = target.querySelectorAll('button');
|
||||
|
||||
add4.click();
|
||||
flushSync();
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`<button>add 4</button> <button>add 5</button> <button>modify 3</button>
|
||||
1423`
|
||||
);
|
||||
|
||||
add5.click();
|
||||
flushSync();
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`<button>add 4</button> <button>add 5</button> <button>modify 3</button>
|
||||
14523`
|
||||
);
|
||||
|
||||
modify3.click();
|
||||
flushSync();
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`<button>add 4</button> <button>add 5</button> <button>modify 3</button>
|
||||
1452updated`
|
||||
);
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,11 @@
|
||||
<script>
|
||||
let list = $state([{ id: 1, text: '1' }, { id: 2, text: '2' }, { id: 3, text: '3' }]);
|
||||
</script>
|
||||
|
||||
<button onclick={() => list = [list[0], { id: 4, text: '4' }, ...list.slice(1)]}>add 4</button>
|
||||
<button onclick={() => list = [list[0], list[1], { id: 5, text: '5' }, ...list.slice(2)]}>add 5</button>
|
||||
<button onclick={() => list.at(-1).text = 'updated'}>modify 3</button>
|
||||
|
||||
{#each list as item (item.id)}
|
||||
{item.text}
|
||||
{/each}
|
||||
Loading…
Reference in new issue