fix: events not firing when SpringRef attached manually under StrictMode#2430
Merged
Conversation
Closes #1991 flushUpdate mutates the input props in place by wrapping event handlers (onStart/onChange/onRest) with a batching closure. useSprings' commit-phase layout effect pushes updates.current[i] — a stable reference reused across renders — onto ctrl.queue. Under StrictMode the layout effect runs twice, so the already-wrapped handler from the first flush gets wrapped again. The outer wrapper now closes over wrapper1 instead of the user's callback, so when _onFrame flushes the event Map it only ever invokes wrapper1 — which just adds itself to the queue. The user's handler is never reached. Push a shallow copy of the update (including its default sub-object) onto ctrl.queue so flushUpdate's mutations land on the copy and never leak back into the canonical updates.current[i] reference.
🦋 Changeset detectedLatest commit: 4c64204 The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 packages
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 |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This was referenced May 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1991.
Summary
When a user attaches a
SpringRefmanually via therefprop onuseSpring/useSprings, events (onStart,onChange,onRest) silently stop firing under React StrictMode, even though the animation itself still plays.Root cause
flushUpdateinController.tsmutates the input props in place — it wraps each event handler (onStart,onChange,onRest) with a batching closure so multiple per-frame invocations collapse into one. The wrapper captures the user's original handler in its closure.useSprings' commit-phase layout effect pushesupdates.current[i](a stable reference reused across renders) ontoctrl.queuewhenever a ref is attached. Under StrictMode the layout effect runs twice (mount → cleanup → re-mount), so the already-wrapped handler from the first flush gets wrapped a second time. The outer wrapper now closes overwrapper1instead of the user's callback, so when_onFrameflushes the event Map it only ever invokeswrapper1— which just adds itself to the queue. The user's handler is never reached.Fix
Push a shallow copy of the update (including its
defaultsub-object) ontoctrl.queue, soflushUpdate's mutations land on the copy and never leak back into the canonicalupdates.current[i]reference.One-line change in
packages/core/src/hooks/useSprings.ts.