Skip to content

[bug]: React 18 StrictMode logic seems incorrect #1890

@billyjanitsch

Description

@billyjanitsch

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:

/**
* 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:

useLayoutEffect(() => {
usedTransitions.current = transitions
})

And populated:

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:

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.

Metadata

Metadata

Assignees

Labels

area: corerelates to core classes // parts of the librarykind: bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions