Skip to content

Commit ff72dd2

Browse files
fix: transitions might render animated elements without animation styles applied for the duration of some rendering frames when they start (#16035)
* fix: transitions might render animated elements without animation styles applied for the duration of some rendering frames when they starts * add changeset * Apply suggestions from code review --------- Co-authored-by: Rich Harris <hello@rich-harris.dev>
1 parent b5b814c commit ff72dd2

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

.changeset/tiny-poems-scream.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: use `fill: 'forwards'` on transition animations to prevent flicker

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,15 @@ 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 from rendering without styles applied
386+
// see https://github.com/sveltejs/svelte/issues/14732
387+
var animation = element.animate(keyframes, { duration: delay, fill: 'forwards' });
385388

386389
animation.onfinish = () => {
390+
// remove dummy animation from the stack to prevent conflict with main animation
391+
animation.cancel();
392+
387393
// for bidirectional transitions, we start from the current position,
388394
// rather than doing a full intro/outro
389395
var t1 = counterpart?.t() ?? 1 - t2;

0 commit comments

Comments
 (0)