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', () => {
26
26
} , isStrictMode )
27
27
28
28
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
+
29
37
it ( 'calls the props function once per new spring' , ( ) => {
30
38
const getProps = jest . fn ( ( i : number ) => ( { x : i * 100 } ) )
31
39
Original file line number Diff line number Diff line change @@ -127,9 +127,12 @@ export function useSprings(
127
127
[ ]
128
128
)
129
129
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
130
134
const ctrls = useRef ( [ ...state . ctrls ] )
131
135
const updates = useRef < any [ ] > ( [ ] )
132
- updates . current ??= [ ]
133
136
134
137
// Cache old controllers to dispose in the commit phase.
135
138
const prevLength = usePrev ( length ) || 0
@@ -181,6 +184,10 @@ export function useSprings(
181
184
const prevContext = usePrev ( context )
182
185
const hasContext = context !== prevContext && hasProps ( context )
183
186
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.
184
191
useIsomorphicLayoutEffect ( ( ) => {
185
192
layoutId . current ++
186
193
@@ -218,7 +225,6 @@ export function useSprings(
218
225
ctrl . start ( update )
219
226
}
220
227
}
221
- updates . current [ i ] = null
222
228
} )
223
229
} )
224
230
You can’t perform that action at this time.
0 commit comments