Skip to content

Commit

Permalink
fix: unmount transition items even if leave is a noop
Browse files Browse the repository at this point in the history
The `onRest` prop is not called for no-op updates, so we need to use the `onResolve` prop instead.
  • Loading branch information
aleclarson committed Oct 9, 2020
1 parent 67f838e commit 11f48aa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
10 changes: 4 additions & 6 deletions packages/core/src/hooks/useTransition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,14 @@ export function useTransition(
payload.from = callProp(from, t.item, i)
}

const { onRest }: { onRest?: any } = payload
payload.onRest = result => {
const { onResolve } = payload
payload.onResolve = result => {
callProp(onResolve, result)

const transitions = usedTransitions.current!
const t = transitions.find(t => t.key === key)
if (!t) return

if (is.fun(onRest)) {
onRest(result, t)
}

// Reset the phase of a cancelled enter/leave transition, so it can
// retry the animation on the next render.
if (result.cancelled && t.phase != UPDATE) {
Expand Down
4 changes: 0 additions & 4 deletions packages/core/src/types/transition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ export type UseTransitionProps<Item = any> = Merge<
config?:
| SpringConfig
| ((item: Item, index: number) => AnimationProps['config'])
onRest?: (
result: AnimationResult<Controller>,
transition: TransitionState
) => void
/**
* Called after a transition item is unmounted.
*/
Expand Down

0 comments on commit 11f48aa

Please sign in to comment.