Skip to content

Commit a993062

Browse files
committed
fix: avoid reusing "config" from async updates
In response to: #632 (comment)
1 parent 09e1e1b commit a993062

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

src/animated/Controller.ts

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ class Controller<State extends object = any> {
239239
if (is.arr(props.to) || is.fun(props.to)) {
240240
this._runAsync(props, onEnd)
241241
} else if (this._diff(props)) {
242-
this._animate(this.props)._start(onEnd)
242+
this._animate(this.props, props.config)._start(onEnd)
243243
} else {
244244
this._onEnd(onEnd)
245245
}
@@ -292,6 +292,7 @@ class Controller<State extends object = any> {
292292
}
293293

294294
// Merge every fresh prop. Returns true if one or more props changed.
295+
// The `config` prop is ignored by this method.
295296
private _diff({ timestamp, config, ...props }: UpdateProps<State>) {
296297
let changed = false
297298

@@ -323,20 +324,17 @@ class Controller<State extends object = any> {
323324
}
324325
}
325326

326-
// The `config` prop is atomic
327-
if (config && diffTimestamp('config')) {
328-
changed = true
329-
this.props.config = config
330-
}
331-
332327
for (const key in props) {
333328
diffProp([key], props[key], this.props)
334329
}
335330
return changed
336331
}
337332

338333
// Update the animation configs.
339-
private _animate(props: UpdateProps<State>) {
334+
private _animate(
335+
props: UpdateProps<State>,
336+
configArg: typeof props.config = props.config
337+
) {
340338
let { to = emptyObj, from = emptyObj } = props
341339

342340
// Reverse values when requested
@@ -381,15 +379,8 @@ class Controller<State extends object = any> {
381379
continue
382380
}
383381

384-
const config = callProp(props.config, key) || emptyObj
385-
386-
// Animations are only updated when they were reset, they have a new
387-
// goal value, or their spring config was changed.
388-
if (
389-
props.reset ||
390-
!is.equ(goalValue, state.goalValue) ||
391-
!is.equ(config, state.config)
392-
) {
382+
// Replace an animation when its goal value is changed (or it's been reset)
383+
if (props.reset || !is.equ(goalValue, state.goalValue)) {
393384
const immediate = callProp(props.immediate, key)
394385
if (!immediate) started.push(key)
395386

@@ -438,10 +429,11 @@ class Controller<State extends object = any> {
438429
}
439430
}
440431

441-
// Update the array of Animated nodes used by the frameloop
442-
animatedValues = toArray(animated.getPayload() as any)
432+
// Only change the "config" of updated animations.
433+
const config: SpringConfig = callProp(configArg, key) || emptyObj
443434

444435
changed = true
436+
animatedValues = toArray(animated.getPayload() as any)
445437
this.animations[key] = {
446438
key,
447439
goalValue,

0 commit comments

Comments
 (0)