Skip to content

Commit

Permalink
fix: improve each key animations (#9842)
Browse files Browse the repository at this point in the history
  • Loading branch information
trueadm authored Dec 7, 2023
1 parent 08d93a2 commit 8dfb289
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/fifty-rice-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: improve each key animations
8 changes: 7 additions & 1 deletion packages/svelte/src/internal/client/each.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ function reconcile_tracked_array(
while (i-- > 0) {
b_end = i + start;
a = sources[i];
if (pos === MOVED_BLOCK && a !== LIS_BLOCK) {
if (pos === MOVED_BLOCK) {
block = b_blocks[b_end];
item = array[b_end];
update_each_item_block(block, item, b_end, flags);
Expand Down Expand Up @@ -726,6 +726,12 @@ function update_each_item_block(block, item, index, type) {
if (prev_index !== index && /** @type {number} */ (index) < items.length) {
const from_dom = /** @type {Element} */ (get_first_element(block));
const from = from_dom.getBoundingClientRect();
// Cancel any existing key transitions
for (const transition of transitions) {
if (transition.r === 'key') {
transition.c();
}
}
schedule_task(() => {
trigger_transitions(transitions, 'key', from);
});
Expand Down
4 changes: 3 additions & 1 deletion packages/svelte/src/internal/client/transitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,9 @@ function create_transition(dom, init, direction, effect) {
},
// cancel
c() {
/** @type {Animation | TickAnimation} */ (animation).cancel();
if (animation !== null) {
/** @type {Animation | TickAnimation} */ (animation).cancel();
}
cancelled = true;
},
// cleanup
Expand Down

1 comment on commit 8dfb289

@vercel
Copy link

@vercel vercel bot commented on 8dfb289 Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

svelte-5-preview – ./sites/svelte-5-preview

svelte-5-preview-svelte.vercel.app
svelte-5-preview.vercel.app
svelte-octane.vercel.app
svelte-5-preview-git-main-svelte.vercel.app

Please sign in to comment.