Skip to content

fix: transitions might render animated elements without animation styles applied for the duration of some rendering frames when they start - #16035

Merged
Rich-Harris merged 3 commits into
sveltejs:mainfrom
raythurnvoid:fix/@sveltejs/svelte/#14732
May 29, 2025
Merged

Rich-Harris merged 3 commits into
sveltejs:mainfrom
raythurnvoid:fix/@sveltejs/svelte/#14732

Conversation

@raythurnvoid

Copy link
Copy Markdown
Contributor

Fix the issue reported at #14732

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.
  • If this PR changes code within packages/svelte/src, add a changeset (npx changeset).

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

…les applied for the duration of some rendering frames when they starts
@changeset-bot

changeset-bot Bot commented May 29, 2025

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 03c6408

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@raythurnvoid

Copy link
Copy Markdown
Contributor Author

I'm unsure this can be tested if not manually

@raythurnvoid raythurnvoid changed the title fix: transitions might render animated elements without animation styles applied for the duration of some rendering frames when they starts fix: transitions might render animated elements without animation styles applied for the duration of some rendering frames when they start May 29, 2025
@github-actions

Copy link
Copy Markdown
Contributor

Playground

pnpm add https://pkg.pr.new/svelte@16035

@Rich-Harris Rich-Harris left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is great, thank you! agree that testing such things is prohibitively difficult, but having the comment there should make regressions unlikely

Comment thread .changeset/tiny-poems-scream.md Resolved
@rdrpenguin04

rdrpenguin04 commented Aug 20, 2025 •

Copy link
Copy Markdown

For whatever reason, this seems to have broken some other animations; #16304 is one example, and I just ran into it in my code. In my case, using slide, the contents of the element being slid in don't render until after the entire box has been loaded in, which makes the animation look very odd.

Edit: for extra clarification, I have two animate:slide elements nested. The minimum size of the inner one appears to be calculated as 0 during the animation, or something like that, causing all of the content to snap in at the end of the animation.

dummdidumm pushed a commit that referenced this pull request Aug 25, 2026
…#18647)

Fixes #18421 (regression from #16035, which re-broke the #4784
scenario).

Since #16035 the dummy delay animation runs with `fill: 'forwards'`, so
an intro's `t = 0` styles (for `slide`, `height: 0`) apply the moment
the transition is created and stay applied until the real animation
starts a frame later. Transition functions of other elements in the same
batch run after that and measure a collapsed DOM. With nested intros
(the TreeView from the issue), intro effects run deepest-first, so every
ancestor's `slide` captures a height where its children are pinned at 0.
On the issue's REPL every `<ul>` animates `0px -> 36px` (the height of a
single row) and then jumps to its real size when the animation finishes,
which is the "children pop out" behavior from #4784.

The fix waits one microtask before applying the initial styles and
creating the dummy, the same way deferred transitions (`crossfade`)
already work in `animate()`. Everything in the batch measures the DOM
first; the microtask still runs before the next paint, so elements never
render unstyled and the #14732 behavior is preserved. Verified in a real
browser that a delayed intro (`delay: 300`) stays held at `height: 0`
for the whole delay, including the first painted frame.

Most of the diff is the existing dummy/onfinish block moving into
`queue_micro_task`; hiding whitespace shows the actual change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants