Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lazy-masks-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: ensure transitions properly cancel on completion
9 changes: 6 additions & 3 deletions packages/svelte/src/internal/client/transitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,12 @@ class TickAnimation {
}

cancel() {
const t = this.#reversed ? 1 : 0;
active_tick_animations.delete(this);
this.#tick_fn(t, 1 - t);
const current = this.#current / this.#duration;
if (current > 0 && current < 1) {
const t = this.#reversed ? 1 : 0;
this.#tick_fn(t, 1 - t);
}
}

finish() {
Expand Down Expand Up @@ -322,7 +325,7 @@ function create_transition(dom, init, direction, effect) {

animation.onfinish = () => {
const is_outro = curr_direction === 'out';
/** @type {Animation | TickAnimation} */ (animation).pause();
/** @type {Animation | TickAnimation} */ (animation).cancel();
if (is_outro) {
run_all(subs);
subs = [];
Expand Down
8 changes: 5 additions & 3 deletions packages/svelte/tests/animation-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,18 @@ class Animation {
}

finish() {
this.onfinish();
this.currentTime = this.#reversed ? 0 : this.#duration;
if (this.#reversed) {
raf.animations.delete(this);
}
this.onfinish();
}

cancel() {
this._applyKeyFrame(this.#reversed ? this.#keyframes.length - 1 : 0);
raf.animations.delete(this);
this.#paused = true;
if (this.currentTime > 0 && this.currentTime < this.#duration) {
this._applyKeyFrame(this.#reversed ? this.#keyframes.length - 1 : 0);
}
}

pause() {
Expand Down