Skip to content

Commit 5b9fb22

Browse files
committed
Suspend the commit while we wait for the previous transition to finish
1 parent 13cf2cd commit 5b9fb22

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1197,8 +1197,14 @@ export function startViewTransition(
11971197
// TODO: Wait for fonts.
11981198
afterMutationCallback();
11991199
});
1200+
// $FlowFixMe[prop-missing]
1201+
ownerDocument.__reactViewTransition = transition;
12001202
transition.ready.then(layoutCallback, layoutCallback);
1201-
transition.finished.then(passiveCallback);
1203+
transition.finished.then(() => {
1204+
// $FlowFixMe[prop-missing]
1205+
ownerDocument.__reactViewTransition = null;
1206+
passiveCallback();
1207+
});
12021208
return true;
12031209
}
12041210

@@ -3681,6 +3687,19 @@ export function suspendOnActiveViewTransition(rootContainer: Container): void {
36813687
'Internal React Error: suspendedState null when it was expected to exists. Please report this as a React bug.',
36823688
);
36833689
}
3690+
const state = suspendedState;
3691+
const ownerDocument =
3692+
rootContainer.nodeType === DOCUMENT_NODE
3693+
? rootContainer
3694+
: rootContainer.ownerDocument;
3695+
// $FlowFixMe[prop-missing]
3696+
const activeViewTransition = ownerDocument.__reactViewTransition;
3697+
if (activeViewTransition == null) {
3698+
return;
3699+
}
3700+
state.count++;
3701+
const ping = onUnsuspend.bind(state);
3702+
activeViewTransition.finished.then(ping, ping);
36843703
}
36853704

36863705
export function waitForCommitToBeReady(): null | ((() => void) => () => void) {

0 commit comments

Comments
 (0)