File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,14 @@ describe('useSprings', () => {
2626 } , isStrictMode )
2727
2828 describe ( 'when only a props function is passed' , ( ) => {
29+ it ( 'should reach final value in strict mode' , async ( ) => {
30+ update ( 1 , ( ) => ( {
31+ from : { x : 0 } ,
32+ to : { x : 1 } ,
33+ } ) )
34+ expect ( mapSprings ( s => s . goal ) ) . toEqual ( [ { x : 1 } ] )
35+ } )
36+
2937 it ( 'calls the props function once per new spring' , ( ) => {
3038 const getProps = jest . fn ( ( i : number ) => ( { x : i * 100 } ) )
3139
Original file line number Diff line number Diff line change @@ -127,9 +127,12 @@ export function useSprings(
127127 [ ]
128128 )
129129
130+ // useRef is needed to get the same references accross renders.
131+ // Note that controllers are a shallow copy of the final array.
132+ // So any array manipulation won't impact the final array until
133+ // the commit phase, in the useIsomorphicLayoutEffect callback
130134 const ctrls = useRef ( [ ...state . ctrls ] )
131135 const updates = useRef < any [ ] > ( [ ] )
132- updates . current ??= [ ]
133136
134137 // Cache old controllers to dispose in the commit phase.
135138 const prevLength = usePrev ( length ) || 0
@@ -181,6 +184,10 @@ export function useSprings(
181184 const prevContext = usePrev ( context )
182185 const hasContext = context !== prevContext && hasProps ( context )
183186
187+ // This is the commit phase where the new transition will begin.
188+ // - updated animation values will be passed to the controlers.
189+ // - state will be updated
190+ // - springs will start or the new update will be queued if the spring is not started yet.
184191 useIsomorphicLayoutEffect ( ( ) => {
185192 layoutId . current ++
186193
@@ -218,7 +225,6 @@ export function useSprings(
218225 ctrl . start ( update )
219226 }
220227 }
221- updates . current [ i ] = null
222228 } )
223229 } )
224230
You can’t perform that action at this time.
0 commit comments