Skip to content

fix(core): preserve velocity across retargets for decay animations#2516

Merged
joshuaellis merged 1 commit into
nextfrom
fix/1843
May 22, 2026
Merged

fix(core): preserve velocity across retargets for decay animations#2516
joshuaellis merged 1 commit into
nextfrom
fix/1843

Conversation

@joshuaellis
Copy link
Copy Markdown
Member

Summary

Decay animations integrate an initial velocity — position = from + (v0 / (1 - decay)) * (1 - e^(-(1-decay)t)). The previous _update logic unconditionally reset config.velocity = 0 whenever to or from was provided, which silently breaks gesture-driven decay flows that retarget mid-throw (mouse-flick decay, drag-throw, etc.). The fix is a one-condition tweak: skip the velocity reset when config.decay is set.

The bug report (#1843) was filed because useSpring({ xys, config: { decay: 0.48 } }) "doesn't work". That repro never sets a velocity at all, so even after this fix it won't animate — decay needs a velocity to decelerate. The user-facing confusion is that the existing docs don't say so. This PR also updates the decay JSDoc and docs-site reference to make that explicit, including a @use-gesture/react snippet that mirrors the rocket-decay demo.

Closes #1843.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 22, 2026

🦋 Changeset detected

Latest commit: 71ca974

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

@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 Error Error May 22, 2026 3:06pm

Request Review

@github-actions
Copy link
Copy Markdown
Contributor

Docs preview: https://pr-2516---react-spring-204644970562.europe-west1.run.app

Deployed at b6ea9970205baa3b44dc091cebde3876593a9485. Updates on every push.

Decay animations integrate an initial velocity; the previous `_update`
logic unconditionally reset `config.velocity` to `0` whenever `to` or
`from` was provided, silently breaking gesture-driven decay flows that
retarget mid-throw. Skip the reset when `config.decay` is set.

Also clarifies the JSDoc and docs-site reference for `decay` to explain
that it decelerates from an initial velocity and does not ease toward
`to` — the root cause of the user-facing confusion in #1843.

Closes #1843.
@joshuaellis joshuaellis merged commit 6bd6613 into next May 22, 2026
4 of 6 checks passed
@joshuaellis joshuaellis deleted the fix/1843 branch May 22, 2026 15:06
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.

Decay seems not working anymore

1 participant