Skip to content

Commit 7a9dff3

Browse files
authored
fix: useTransition would not obey refs (pmndrs#1944)
1 parent c2781c6 commit 7a9dff3

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@react-spring/core': patch
3+
'@react-spring/animated': patch
4+
'@react-spring/parallax': patch
5+
'@react-spring/rafz': patch
6+
'react-spring': patch
7+
'@react-spring/shared': patch
8+
'@react-spring/types': patch
9+
'@react-spring/konva': patch
10+
'@react-spring/native': patch
11+
'@react-spring/three': patch
12+
'@react-spring/web': patch
13+
'@react-spring/zdog': patch
14+
---
15+
16+
fix: react18 useTransition on mount

packages/core/src/hooks/useTransition.tsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,19 +104,15 @@ export function useTransition(
104104

105105
useOnce(() => {
106106
/**
107-
* This _should_ only run in `StrictMode` where everything
108-
* is destroyed and remounted, because the enter animation
109-
* was most likely cancelled we run it again on initial mount.
107+
* If transitions exist on mount of the component
108+
* then reattach their refs on-mount, this was required
109+
* for react18 strict mode to work properly.
110110
*
111-
* This does nothing when `StrictMode` isn't enabled,
112-
* because usedTransitions on mount is typically null.
111+
* See https://github.com/pmndrs/react-spring/issues/1890
113112
*/
114-
each(usedTransitions.current!, t => {
115-
t.ctrl.ref?.add(t.ctrl)
116-
const change = changes.get(t)
117-
if (change) {
118-
t.ctrl.start(change.payload)
119-
}
113+
each(transitions, t => {
114+
ref?.add(t.ctrl)
115+
t.ctrl.ref = ref
120116
})
121117

122118
// Destroy all transitions on dismount.
@@ -159,6 +155,7 @@ export function useTransition(
159155
if (~i) transitions[i] = t
160156
}
161157
})
158+
162159
// Mount new items with fresh transitions.
163160
each(items, (item, i) => {
164161
if (!transitions[i]) {

0 commit comments

Comments
 (0)