Skip to content

Commit 25da502

Browse files
committed
fix(Controller): avoid adding batched handlers to the default props
1 parent 4de9fd0 commit 25da502

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

packages/core/src/Controller.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import * as G from 'shared/globals'
1212

1313
import { Lookup, Falsy } from './types/common'
14-
import { getDefaultProp } from './helpers'
14+
import { getDefaultProp, getDefaultProps } from './helpers'
1515
import { FrameValue } from './FrameValue'
1616
import { SpringPhase, CREATED, ACTIVE, IDLE, PAUSED } from './SpringPhase'
1717
import { SpringValue, createLoopUpdate, createUpdate } from './SpringValue'
@@ -267,6 +267,7 @@ export async function flushUpdate(
267267
isLoop?: boolean
268268
): AsyncResult {
269269
const { keys, to, loop, onRest } = props
270+
const defaults = is.obj(props.default) && props.default
270271

271272
// Looping must be handled in this function, or else the values
272273
// would end up looping out-of-sync in many common cases.
@@ -278,10 +279,14 @@ export async function flushUpdate(
278279
if (asyncTo) {
279280
props.to = undefined
280281
props.onRest = undefined
281-
} else {
282-
// For certain events, use batching to prevent multiple calls per frame.
283-
// However, batching is avoided when the `to` prop is async, because any
284-
// event props are used as default props instead.
282+
if (defaults) {
283+
defaults.onRest = undefined
284+
}
285+
}
286+
// For certain events, use batching to prevent multiple calls per frame.
287+
// However, batching is avoided when the `to` prop is async, because any
288+
// event props are used as default props instead.
289+
else {
285290
each(BATCHED_EVENTS, key => {
286291
const handler: any = props[key]
287292
if (is.fun(handler)) {
@@ -304,6 +309,10 @@ export async function flushUpdate(
304309
}
305310
}) as any
306311
}
312+
// Avoid using a batched `handler` as a default prop.
313+
if (defaults) {
314+
defaults[key] = props[key] as any
315+
}
307316
}
308317
})
309318
}

packages/core/src/helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export const getDefaultProp = <T extends Lookup, P extends keyof T>(
7474
*/
7575
export const getDefaultProps = <T extends Lookup>(
7676
props: Lookup,
77-
omitKeys: (string | Falsy)[] = [],
77+
omitKeys: readonly (string | Falsy)[] = [],
7878
defaults: Lookup = {} as any
7979
) => {
8080
let keys: readonly string[] = DEFAULT_PROPS
@@ -95,7 +95,7 @@ export const getDefaultProps = <T extends Lookup>(
9595
export const mergeDefaultProps = (
9696
defaults: Lookup,
9797
props: Lookup,
98-
omitKeys?: (string | Falsy)[]
98+
omitKeys?: readonly (string | Falsy)[]
9999
) => getDefaultProps(props, omitKeys, defaults)
100100

101101
/** These props can have default values */

0 commit comments

Comments
 (0)