Skip to content

fix(core): fire onRest when animation is cancelled before its first frame#2511

Merged
joshuaellis merged 2 commits into
nextfrom
worktree-1802
May 22, 2026
Merged

fix(core): fire onRest when animation is cancelled before its first frame#2511
joshuaellis merged 2 commits into
nextfrom
worktree-1802

Conversation

@joshuaellis

Copy link
Copy Markdown
Member

Closes #1802.

Summary

SpringValue._stop gated onRest on anim.changed, which only flips to true once the first frame has rendered. When two start() calls happen within a single tick and the second returns the spring to its current value, the engine stops the animation before any frame fires — so onRest was silently dropped while the start promise still resolved. The same gap affected set() and stop() called synchronously after start().

Entry to the block already requires isAnimating(this), so dropping the anim.changed guard just covers the gap where a spring transitioned active → idle without rendering a frame. The full unit suite passes (253 / 0).

Repro

const [, api] = useSpring(() => ({
  opacity: 0,
  onRest: (v) => console.log('rest', v.value),
}))

api.start({ opacity: 1 })
api.start({ opacity: 0 }) // before the next rAF — onRest never fires

…t frame

Closes #1802

`SpringValue._stop` gated `onRest` on `anim.changed`, which only flips to
`true` once the first frame has rendered. When two `start()` calls happen
within a single tick and the second returns the spring to its current
value, the engine stops the animation before any frame fires, so
`onRest` was silently dropped.

The entry to the block already requires `isAnimating(this)` to be true,
so dropping the `anim.changed` guard is safe — it just covers the gap
where a spring transitioned active → idle without rendering a frame.
@vercel

vercel Bot commented May 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
react-spring Error Error May 22, 2026 11:52am

Request Review

@changeset-bot

changeset-bot Bot commented May 22, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0d56421

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 12 packages
Name Type
@react-spring/core Patch
@react-spring/animated Patch
@react-spring/mock-raf Patch
@react-spring/parallax Patch
@react-spring/rafz Patch
@react-spring/shared Patch
@react-spring/types Patch
@react-spring/konva Patch
@react-spring/native Patch
@react-spring/three Patch
@react-spring/web Patch
@react-spring/zdog Patch

Not sure what this means? Click here to learn what changesets are.

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

@joshuaellis
joshuaellis merged commit 84b058a into next May 22, 2026
17 of 18 checks passed
@joshuaellis
joshuaellis deleted the worktree-1802 branch May 22, 2026 12:10
This was referenced May 22, 2026
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.

'onRest' not fired when two 'start' calls are too close

1 participant