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/kind-baboons-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: improve intro transitions on dynamic mount
17 changes: 11 additions & 6 deletions packages/svelte/src/internal/client/transitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const DELAY_NEXT_TICK = Number.MIN_SAFE_INTEGER;

/** @type {undefined | number} */
let active_tick_ref = undefined;
let skip_mount_intro = false;

/**
* @template T
Expand Down Expand Up @@ -482,7 +483,6 @@ export function bind_transition(dom, get_transition_fn, props_fn, direction, glo
// @ts-ignore
dom.__animate = true;
}
let foo = false;
/** @type {import('./types.js').Block | null} */
let transition_block = block;
main: while (transition_block !== null) {
Expand All @@ -496,7 +496,7 @@ export function bind_transition(dom, get_transition_fn, props_fn, direction, glo
can_show_intro_on_mount = true;
} else if (transition_block.t === IF_BLOCK) {
transition_block.r = if_block_transition;
if (can_show_intro_on_mount) {
if (can_show_intro_on_mount && !skip_mount_intro) {
/** @type {import('./types.js').Block | null} */
let if_block = transition_block;
while (if_block.t === IF_BLOCK) {
Expand All @@ -511,14 +511,14 @@ export function bind_transition(dom, get_transition_fn, props_fn, direction, glo
}
}
if (!can_apply_lazy_transitions && can_show_intro_on_mount) {
can_show_intro_on_mount = transition_block.e !== null;
foo = true;
can_show_intro_on_mount = !skip_mount_intro && transition_block.e !== null;
}
if (can_show_intro_on_mount || !global) {
can_apply_lazy_transitions = true;
}
} else if (transition_block.t === ROOT_BLOCK && !can_apply_lazy_transitions) {
can_show_intro_on_mount = transition_block.e !== null || transition_block.i;
can_show_intro_on_mount =
!skip_mount_intro && (transition_block.e !== null || transition_block.i);
}
transition_block = transition_block.p;
}
Expand All @@ -529,7 +529,12 @@ export function bind_transition(dom, get_transition_fn, props_fn, direction, glo
effect(() => {
if (transition !== undefined) {
// Destroy any existing transitions first
transition.x();
try {
skip_mount_intro = true;
transition.x();
} finally {
skip_mount_intro = false;
}
}
const transition_fn = get_transition_fn();
/** @param {DOMRect} [from] */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ export default test({
b2.click();
});

assert.deepEqual(log, ['transition 2', 'transition 1', 'transition 1']);
assert.deepEqual(log, ['transition 2', 'transition 1']);
}
});