Skip to content

Commit 8dfb289

Browse files
authored
fix: improve each key animations (#9842)
1 parent 08d93a2 commit 8dfb289

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

.changeset/fifty-rice-wait.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 key animations

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ function reconcile_tracked_array(
512512
while (i-- > 0) {
513513
b_end = i + start;
514514
a = sources[i];
515-
if (pos === MOVED_BLOCK && a !== LIS_BLOCK) {
515+
if (pos === MOVED_BLOCK) {
516516
block = b_blocks[b_end];
517517
item = array[b_end];
518518
update_each_item_block(block, item, b_end, flags);
@@ -726,6 +726,12 @@ function update_each_item_block(block, item, index, type) {
726726
if (prev_index !== index && /** @type {number} */ (index) < items.length) {
727727
const from_dom = /** @type {Element} */ (get_first_element(block));
728728
const from = from_dom.getBoundingClientRect();
729+
// Cancel any existing key transitions
730+
for (const transition of transitions) {
731+
if (transition.r === 'key') {
732+
transition.c();
733+
}
734+
}
729735
schedule_task(() => {
730736
trigger_transitions(transitions, 'key', from);
731737
});

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,9 @@ function create_transition(dom, init, direction, effect) {
376376
},
377377
// cancel
378378
c() {
379-
/** @type {Animation | TickAnimation} */ (animation).cancel();
379+
if (animation !== null) {
380+
/** @type {Animation | TickAnimation} */ (animation).cancel();
381+
}
380382
cancelled = true;
381383
},
382384
// cleanup

0 commit comments

Comments
 (0)