Skip to content

Commit 4958d97

Browse files
committed
fix: improve transition outro effect
1 parent 456cf84 commit 4958d97

4 files changed

Lines changed: 13 additions & 18 deletions

File tree

.changeset/smart-waves-march.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 transition outro effect

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -437,21 +437,21 @@ function create_transition(dom, init, direction, effect) {
437437
dispatch_event(dom, 'outrostart');
438438
if (needs_reverse) {
439439
const payload = transition.p;
440-
const current_animation = /** @type {Animation} */ (animation);
441440
// If we are working with CSS animations, then before we call reverse, we also need to ensure
442441
// that we reverse the easing logic. To do this we need to re-create the keyframes so they're
443442
// in reverse with easing properly reversed too.
444-
if (
445-
payload !== null &&
446-
payload.css !== undefined &&
447-
current_animation.playState === 'idle'
448-
) {
443+
if (payload !== null && payload.css !== undefined) {
449444
const duration = payload.duration ?? 300;
450445
const css_fn = payload.css;
451446
const easing_fn = payload.easing || linear;
452447
const keyframes = create_keyframes(easing_fn, css_fn, duration, direction, true);
448+
const current_animation = /** @type {Animation} */ (animation);
453449
const effect = current_animation.effect;
454-
if (effect !== null) {
450+
if (effect != null) {
451+
// If we have an existing animation, we need to pause it and create a new animation
452+
// with the new frames.
453+
animation.pause();
454+
create_animation();
455455
// @ts-ignore
456456
effect.setKeyframes(keyframes);
457457
}

packages/svelte/tests/animation-helpers.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,11 @@ class Animation {
5353
this.onfinish = () => {};
5454
this.pending = true;
5555
this.currentTime = 0;
56-
this.playState = 'running';
57-
this.effect = {
58-
setKeyframes: (/** @type {Keyframe[]} */ keyframes) => {
59-
this.#keyframes = keyframes;
60-
}
61-
};
6256
}
6357

6458
play() {
6559
this.#paused = false;
6660
raf.animations.add(this);
67-
this.playState = 'running';
6861
this._update();
6962
}
7063

@@ -114,7 +107,6 @@ class Animation {
114107
if (this.#reversed) {
115108
raf.animations.delete(this);
116109
}
117-
this.playState = 'idle';
118110
}
119111

120112
cancel() {
@@ -126,13 +118,11 @@ class Animation {
126118

127119
pause() {
128120
this.#paused = true;
129-
this.playState = 'paused';
130121
}
131122

132123
reverse() {
133124
this.#timeline_offset = this.currentTime;
134125
this.#reversed = !this.#reversed;
135-
this.playState = 'running';
136126
}
137127
}
138128

packages/svelte/tests/runtime-legacy/samples/class-shortcut-with-transition/_config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default test({
1818
raf.tick(150);
1919
assert.htmlEqual(
2020
target.innerHTML,
21-
'<p>foo</p><p class="red svelte-1yszte8 border" style="overflow: hidden; opacity: 0; border-top-width: 0.5000600024000317px; border-bottom-width: 0.5000600024000317px;">bar</p>'
21+
'<p>foo</p><p class="red svelte-1yszte8 border" style="overflow: hidden; opacity: 0; border-top-width: 3.4999399975999683px; border-bottom-width: 3.4999399975999683px;">bar</p>'
2222
);
2323
component.open = true;
2424
raf.tick(250);

0 commit comments

Comments
 (0)