File tree Expand file tree Collapse file tree 2 files changed +24
-11
lines changed Expand file tree Collapse file tree 2 files changed +24
-11
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff 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 ] ) {
You can’t perform that action at this time.
0 commit comments