Skip to content

Commit 8e9b94b

Browse files
committed
fix: when useSpring from/to props are falsy
...avoid passing `false` to any SpringValue objects
1 parent 9b9a4c8 commit 8e9b94b

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

packages/core/src/Controller.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -288,19 +288,24 @@ export class Controller<State extends Indexable = UnknownProps>
288288
const props: PendingProps<State> = inferTo(propsArg) as any
289289
let { from, to, reverse, delay } = props as any
290290

291-
// Avoid sending async "to" prop to springs.
292-
if (is.arr(to) || is.fun(to)) {
293-
to = undefined
294-
}
295-
296291
// Each update only affects the springs whose keys have defined values.
297292
const keys = (props.keys = new Set<string>())
298-
const findDefined = (values: any) =>
299-
values &&
300-
each(values, (value, key) => value != null && keys.add(key as any))
301293

302-
findDefined(from)
303-
findDefined(to)
294+
if (from) {
295+
findDefined(from, keys)
296+
} else {
297+
// Falsy values are ignored.
298+
props.from = from = undefined
299+
}
300+
301+
if (is.obj(to)) {
302+
findDefined(to, keys)
303+
} else {
304+
// Falsy values are ignored.
305+
if (!to) props.to = undefined
306+
// Avoid passing functions/arrays to SpringValue objects.
307+
to = undefined
308+
}
304309

305310
// Create our springs and give them values.
306311
const springs = this.springs as Indexable<SpringValue>
@@ -352,6 +357,11 @@ export class Controller<State extends Indexable = UnknownProps>
352357
}
353358
}
354359

360+
/** Find keys with defined values */
361+
function findDefined(values: any, keys: Set<string>) {
362+
each(values, (value, key) => value != null && keys.add(key as any))
363+
}
364+
355365
/** Basic helper for clearing a queue after processing it */
356366
function flush<P, T>(
357367
queue: Map<P, T>,

0 commit comments

Comments
 (0)