Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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/tiny-poems-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: transitions might render animated elements without animation styles applied for the duration of some rendering frames when they start
10 changes: 9 additions & 1 deletion packages/svelte/src/internal/client/dom/elements/transitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,17 @@ function animate(element, options, counterpart, t2, on_finish) {
// create a dummy animation that lasts as long as the delay (but with whatever devtools
// multiplier is in effect). in the common case that it is `0`, we keep it anyway so that
// the CSS keyframes aren't created until the DOM is updated
var animation = element.animate(keyframes, { duration: delay });
//
// fill forwards to prevent the element to render without animation styles applied
// when entering the onfinish callback, can be verified by adding a breakpoint in the onfinish callback
// see https://github.com/sveltejs/svelte/issues/14732
var animation = element.animate(keyframes, { duration: delay, fill: 'forwards' });

animation.onfinish = () => {
// have to manually cancel the dummy animation to remove it from the animations stack
// because it fill forwards
animation.cancel();

// for bidirectional transitions, we start from the current position,
// rather than doing a full intro/outro
var t1 = counterpart?.t() ?? 1 - t2;
Expand Down