Skip to content

Commit 08d93a2

Browse files
authored
fix: improve each block with animate (#9839)
1 parent 388e3e6 commit 08d93a2

File tree

4 files changed

+96
-0
lines changed

4 files changed

+96
-0
lines changed

.changeset/twelve-dragons-join.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: improve each block with animate

packages/svelte/src/internal/client/each.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ function reconcile_tracked_array(
514514
a = sources[i];
515515
if (pos === MOVED_BLOCK && a !== LIS_BLOCK) {
516516
block = b_blocks[b_end];
517+
item = array[b_end];
517518
update_each_item_block(block, item, b_end, flags);
518519
}
519520
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { flushSync } from 'svelte';
2+
import { ok, test } from '../../test';
3+
4+
export default test({
5+
async test({ assert, target, window }) {
6+
const button = target.querySelector('button');
7+
ok(button);
8+
9+
assert.htmlEqual(
10+
target.innerHTML,
11+
`
12+
<button>Shuffle</button><div class="list"><label><input type="checkbox">
13+
write
14+
some
15+
docs</label><label><input type="checkbox">
16+
start
17+
writing
18+
JSConf
19+
talk</label><label><input type="checkbox">
20+
buy
21+
some
22+
milk</label><label><input type="checkbox">
23+
mow
24+
the
25+
lawn</label><label><input type="checkbox">
26+
feed
27+
the
28+
turtle</label><label><input type="checkbox">
29+
fix
30+
some
31+
bugs</label></div>`
32+
);
33+
34+
flushSync(() => {
35+
button.click();
36+
});
37+
38+
assert.htmlEqual(
39+
target.innerHTML,
40+
`
41+
<button>Shuffle</button><div class="list"><label><input type="checkbox">
42+
fix
43+
some
44+
bugs</label><label><input type="checkbox">
45+
feed
46+
the
47+
turtle</label><label><input type="checkbox">
48+
mow
49+
the
50+
lawn</label><label><input type="checkbox">
51+
buy
52+
some
53+
milk</label><label><input type="checkbox">
54+
start
55+
writing
56+
JSConf
57+
talk</label><label><input type="checkbox">
58+
write
59+
some
60+
docs</label></div>`
61+
);
62+
}
63+
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<script>
2+
import { flip } from 'svelte/animate';
3+
4+
let todos = [
5+
{ id: 1, done: false, description: 'write some docs' },
6+
{ id: 2, done: false, description: 'start writing JSConf talk' },
7+
{ id: 3, done: true, description: 'buy some milk' },
8+
{ id: 4, done: false, description: 'mow the lawn' },
9+
{ id: 5, done: false, description: 'feed the turtle' },
10+
{ id: 6, done: false, description: 'fix some bugs' }
11+
];
12+
13+
function update() {
14+
todos = Array.from(todos).reverse();
15+
}
16+
</script>
17+
18+
<button on:click={update}>Shuffle</button>
19+
20+
<div class="list">
21+
{#each todos as todo (todo.id)}
22+
<label animate:flip>
23+
<input type="checkbox" bind:checked={todo.done} />
24+
{todo.description}
25+
</label>
26+
{/each}
27+
</div>

0 commit comments

Comments
 (0)