Skip to content

Commit cd45949

Browse files
committed
Start timer after update
In anticipation of React Fiber
1 parent 20216b0 commit cd45949

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/composables/withTimeout.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { withHandlers, isolate, onWillReceiveProps, onWillUnmount } from "reassemble";
1+
import { withHandlers, isolate, onWillReceiveProps, onDidUpdate, onWillUnmount } from "reassemble";
22

33
import { CSSTransitionProps } from "../csstransition";
44
import { WithTransitionStateProps } from "./withTransitionState";
@@ -28,18 +28,31 @@ export const withTimeout =
2828
};
2929
}),
3030
onWillReceiveProps<PropsUnion>(
31+
(
32+
{transitionState: {inTransition}, active},
33+
{
34+
transitionState: {inTransition: nextInTransition},
35+
cancel, active: nextActive,
36+
},
37+
) => {
38+
const inTransitionChanged = inTransition !== nextInTransition;
39+
const interrupted = nextInTransition && active !== nextActive;
40+
if (inTransitionChanged || interrupted) {
41+
cancel();
42+
}
43+
}),
44+
onDidUpdate<PropsUnion>(
3145
(
3246
{transitionState: {inTransition}, active},
3347
{
3448
transitionState: {inTransition: nextInTransition},
3549
transitionInfo: {totalDuration},
36-
cancel, timeoutIn, active: nextActive,
50+
timeoutIn, active: nextActive,
3751
},
3852
) => {
39-
const newTransition = inTransition !== nextInTransition;
53+
const newTransition = !inTransition && nextInTransition;
4054
const interrupted = nextInTransition && active !== nextActive;
4155
if (newTransition || interrupted) {
42-
cancel();
4356
if (nextInTransition) {
4457
timeoutIn(totalDuration * timeoutMultiplier);
4558
}

0 commit comments

Comments
 (0)