-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Which react-spring target are you using?
-
@react-spring/web -
@react-spring/three -
@react-spring/native -
@react-spring/konva -
@react-spring/zdog
What version of react-spring are you using?
9.4.5
What's Wrong?
This comment (and the associated behavior) introduced in #1875 doesn't seem correct:
react-spring/packages/core/src/hooks/useTransition.tsx
Lines 106 to 113 in 28ef2d1
| /** | |
| * This _should_ only run in `StrictMode` where everything | |
| * is destroyed and remounted, because the enter animation | |
| * was most likely cancelled we run it again on initial mount. | |
| * | |
| * This does nothing when `StrictMode` isn't enabled, | |
| * because usedTransitions on mount is typically null. | |
| */ |
Specifically, "usedTransitions on mount is typically null" is not true. By the time this effect runs, transitions has been assigned to usedTransitions.current:
react-spring/packages/core/src/hooks/useTransition.tsx
Lines 101 to 103 in 28ef2d1
| useLayoutEffect(() => { | |
| usedTransitions.current = transitions | |
| }) |
And populated:
react-spring/packages/core/src/hooks/useTransition.tsx
Lines 163 to 165 in 28ef2d1
| each(items, (item, i) => { | |
| if (!transitions[i]) { | |
| transitions[i] = { |
So usedTransitions is never null at this point, and this code block always runs on mount with a full array of transitions, regardless of whether StrictMode is enabled:
react-spring/packages/core/src/hooks/useTransition.tsx
Lines 114 to 120 in 28ef2d1
| each(usedTransitions.current!, t => { | |
| t.ctrl.ref?.add(t.ctrl) | |
| const change = changes.get(t) | |
| if (change) { | |
| t.ctrl.start(change.payload) | |
| } | |
| }) |
To Reproduce
I unfortunately don't have a good user-facing reproduction yet. For context, upgrading (only) @react-spring/web from 9.4.4 to 9.4.5 broke several internal tests and this seemed to be the underlying cause. I confirmed that manually commenting out the new each(usedTransitions.current, ...) block in 9.4.5 fixes all of those tests. StrictMode is not enabled anywhere in this test suite.
I tried to reduce to a single clear reproduction without much luck. I'll keep trying, but thought it might be useful to report this in the meantime since there seems to be a clear contradiction between the intended and actual behavior, based on the comment.
cc @joshuaellis
Expected Behaviour
See above.
Link to repo
See above.