Skip to content

fix(core)!: stop firing onRest when an active animation is retargeted#2467

Open
joshuaellis wants to merge 2 commits into
nextfrom
fix-onrest-retarget
Open

fix(core)!: stop firing onRest when an active animation is retargeted#2467
joshuaellis wants to merge 2 commits into
nextfrom
fix-onrest-retarget

Conversation

@joshuaellis
Copy link
Copy Markdown
Member

@joshuaellis joshuaellis commented May 22, 2026

Breaking change. Calling spring.start() with a new to value mid-flight currently fires the previous animation's onRest with { finished: false }. onRest is documented as "called when the animation comes to a stand-still" — a retarget is not a stand-still, the spring keeps moving toward the new goal.

Behaviour change

After this PR, the retarget path no longer fires onRest. Normal settle, reset, cancel, and async to are unchanged. The start() promise still resolves with finished: false for callers that need the old-goal-abandoned signal.

The asymmetry lived in a single raf.batchedUpdates block in SpringValue._merge — the old onRest fired unconditionally while the matching onStart was already guarded by if (!reset). The fix moves onRest inside the if (reset) branch.

Migration

Consumers doing side effects in onRest without inspecting result.finished will see fewer calls. If you relied on the retarget call (cleanup, analytics, navigation), read the finished: false resolution from the start() promise instead, or move the side effect to onChange.

Calling spring.start() with a new "to" value mid-flight no longer
invokes the previous animation's onRest handler. onRest is documented
as called when the animation comes to a stand-still, and a retarget is
not a stand-still — the spring keeps moving toward the new goal. The
start() promise still resolves with finished: false on retarget, so
callers that need the old goal-abandoned signal can read it there.
onRest continues to fire on reset, cancel, and normal settle.
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 22, 2026

🦋 Changeset detected

Latest commit: ad0624c

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

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

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

@vercel
Copy link
Copy Markdown

vercel Bot commented May 22, 2026

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

Project Deployment Actions Updated (UTC)
react-spring Ready Ready Preview May 22, 2026 6:53am

Request Review

@joshuaellis joshuaellis changed the title fix(core): stop firing onRest when an active animation is retargeted fix(core)!: stop firing onRest when an active animation is retargeted May 22, 2026
@joshuaellis joshuaellis force-pushed the next branch 3 times, most recently from aeb1a92 to 5812ef4 Compare May 22, 2026 15:04
@joshuaellis joshuaellis added this to the v11.0.0 milestone May 23, 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.

1 participant