Skip to content

Commit ef3e072

Browse files
authored
fix: improve intro transitions on dynamic mount (#10162)
* fix: improve intro transitions on dynamic mount * fix: improve intro transitions on dynamic mount * fix: improve intro transitions on dynamic mount
1 parent da9a5bf commit ef3e072

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

.changeset/kind-baboons-approve.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 intro transitions on dynamic mount

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const DELAY_NEXT_TICK = Number.MIN_SAFE_INTEGER;
3131

3232
/** @type {undefined | number} */
3333
let active_tick_ref = undefined;
34+
let skip_mount_intro = false;
3435

3536
/**
3637
* @template T
@@ -482,7 +483,6 @@ export function bind_transition(dom, get_transition_fn, props_fn, direction, glo
482483
// @ts-ignore
483484
dom.__animate = true;
484485
}
485-
let foo = false;
486486
/** @type {import('./types.js').Block | null} */
487487
let transition_block = block;
488488
main: while (transition_block !== null) {
@@ -496,7 +496,7 @@ export function bind_transition(dom, get_transition_fn, props_fn, direction, glo
496496
can_show_intro_on_mount = true;
497497
} else if (transition_block.t === IF_BLOCK) {
498498
transition_block.r = if_block_transition;
499-
if (can_show_intro_on_mount) {
499+
if (can_show_intro_on_mount && !skip_mount_intro) {
500500
/** @type {import('./types.js').Block | null} */
501501
let if_block = transition_block;
502502
while (if_block.t === IF_BLOCK) {
@@ -511,14 +511,14 @@ export function bind_transition(dom, get_transition_fn, props_fn, direction, glo
511511
}
512512
}
513513
if (!can_apply_lazy_transitions && can_show_intro_on_mount) {
514-
can_show_intro_on_mount = transition_block.e !== null;
515-
foo = true;
514+
can_show_intro_on_mount = !skip_mount_intro && transition_block.e !== null;
516515
}
517516
if (can_show_intro_on_mount || !global) {
518517
can_apply_lazy_transitions = true;
519518
}
520519
} else if (transition_block.t === ROOT_BLOCK && !can_apply_lazy_transitions) {
521-
can_show_intro_on_mount = transition_block.e !== null || transition_block.i;
520+
can_show_intro_on_mount =
521+
!skip_mount_intro && (transition_block.e !== null || transition_block.i);
522522
}
523523
transition_block = transition_block.p;
524524
}
@@ -529,7 +529,12 @@ export function bind_transition(dom, get_transition_fn, props_fn, direction, glo
529529
effect(() => {
530530
if (transition !== undefined) {
531531
// Destroy any existing transitions first
532-
transition.x();
532+
try {
533+
skip_mount_intro = true;
534+
transition.x();
535+
} finally {
536+
skip_mount_intro = false;
537+
}
533538
}
534539
const transition_fn = get_transition_fn();
535540
/** @param {DOMRect} [from] */

packages/svelte/tests/runtime-runes/samples/dynamic-transition/_config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ export default test({
2020
b2.click();
2121
});
2222

23-
assert.deepEqual(log, ['transition 2', 'transition 1', 'transition 1']);
23+
assert.deepEqual(log, ['transition 2', 'transition 1']);
2424
}
2525
});

0 commit comments

Comments
 (0)