Skip to content

Commit 03c6408

Browse files
committed
fix: transitions might render animated elements without animation styles applied for the duration of some rendering frames when they starts
1 parent 23d42fb commit 03c6408

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,17 @@ function animate(element, options, counterpart, t2, on_finish) {
381381
// create a dummy animation that lasts as long as the delay (but with whatever devtools
382382
// multiplier is in effect). in the common case that it is `0`, we keep it anyway so that
383383
// the CSS keyframes aren't created until the DOM is updated
384-
var animation = element.animate(keyframes, { duration: delay });
384+
//
385+
// fill forwards to prevent the element to render without animation styles applied
386+
// when entering the onfinish callback, can be verified by adding a breakpoint in the onfinish callback
387+
// see https://github.com/sveltejs/svelte/issues/14732
388+
var animation = element.animate(keyframes, { duration: delay, fill: 'forwards' });
385389

386390
animation.onfinish = () => {
391+
// have to manually cancel the dummy animation to remove it from the animations stack
392+
// because it fill forwards
393+
animation.cancel();
394+
387395
// for bidirectional transitions, we start from the current position,
388396
// rather than doing a full intro/outro
389397
var t1 = counterpart?.t() ?? 1 - t2;

0 commit comments

Comments
 (0)