Skip to content

Commit d1afba9

Browse files
committed
Use the start time of the transition or the previous fallback as the basis for timeouts
If some has already elapsed we should wait less.
1 parent c7155bc commit d1afba9

File tree

8 files changed

+21
-11
lines changed

8 files changed

+21
-11
lines changed

packages/react-art/src/ReactFiberConfigART.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ export function suspendInstance(instance, type, props) {}
615615

616616
export function suspendOnActiveViewTransition(container) {}
617617

618-
export function waitForCommitToBeReady() {
618+
export function waitForCommitToBeReady(timeoutOffset) {
619619
return null;
620620
}
621621

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6067,7 +6067,9 @@ export function suspendOnActiveViewTransition(rootContainer: Container): void {
60676067
activeViewTransition.finished.then(ping, ping);
60686068
}
60696069

6070-
export function waitForCommitToBeReady(): null | ((() => void) => () => void) {
6070+
export function waitForCommitToBeReady(
6071+
timeoutOffset: number,
6072+
): null | ((() => void) => () => void) {
60716073
if (suspendedState === null) {
60726074
throw new Error(
60736075
'Internal React Error: suspendedState null when it was expected to exists. Please report this as a React bug.',
@@ -6102,7 +6104,7 @@ export function waitForCommitToBeReady(): null | ((() => void) => () => void) {
61026104
state.unsuspend = null;
61036105
unsuspend();
61046106
}
6105-
}, 60000); // one minute
6107+
}, 60000 + timeoutOffset); // one minute
61066108

61076109
state.unsuspend = commit;
61086110

packages/react-native-renderer/src/ReactFiberConfigFabric.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ export function suspendInstance(
612612

613613
export function suspendOnActiveViewTransition(container: Container): void {}
614614

615-
export function waitForCommitToBeReady(): null {
615+
export function waitForCommitToBeReady(timeoutOffset: number): null {
616616
return null;
617617
}
618618

packages/react-native-renderer/src/ReactFiberConfigNative.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ export function suspendInstance(
788788

789789
export function suspendOnActiveViewTransition(container: Container): void {}
790790

791-
export function waitForCommitToBeReady(): null {
791+
export function waitForCommitToBeReady(timeoutOffset: number): null {
792792
return null;
793793
}
794794

packages/react-noop-renderer/src/createReactNoop.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,9 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
361361
}
362362
}
363363

364-
function waitForCommitToBeReady():
365-
| ((commit: () => mixed) => () => void)
366-
| null {
364+
function waitForCommitToBeReady(
365+
timeoutOffset: number,
366+
): ((commit: () => mixed) => () => void) | null {
367367
const subscription = suspenseyCommitSubscription;
368368
if (subscription !== null) {
369369
suspenseyCommitSubscription = null;

packages/react-reconciler/src/ReactFiberWorkLoop.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1505,10 +1505,18 @@ function commitRootWhenReady(
15051505
suspendOnActiveViewTransition(root.containerInfo);
15061506
}
15071507
}
1508+
// For timeouts we use the previous fallback commit for retries and
1509+
// the start time of the transition for transitions. This offset
1510+
// represents the time already passed.
1511+
const timeoutOffset = includesOnlyRetries(lanes)
1512+
? globalMostRecentFallbackTime - now()
1513+
: includesOnlyTransitions(lanes)
1514+
? globalMostRecentTransitionTime - now()
1515+
: 0;
15081516
// At the end, ask the renderer if it's ready to commit, or if we should
15091517
// suspend. If it's not ready, it will return a callback to subscribe to
15101518
// a ready event.
1511-
const schedulePendingCommit = waitForCommitToBeReady();
1519+
const schedulePendingCommit = waitForCommitToBeReady(timeoutOffset);
15121520
if (schedulePendingCommit !== null) {
15131521
// NOTE: waitForCommitToBeReady returns a subscribe function so that we
15141522
// only allocate a function if the commit isn't ready yet. The other

packages/react-reconciler/src/__tests__/ReactFiberHostContext-test.internal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ describe('ReactFiberHostContext', () => {
109109
startSuspendingCommit() {},
110110
suspendInstance(instance, type, props) {},
111111
suspendOnActiveViewTransition(container) {},
112-
waitForCommitToBeReady() {
112+
waitForCommitToBeReady(timeoutOffset: number) {
113113
return null;
114114
},
115115
supportsMutation: true,

packages/react-test-renderer/src/ReactFiberConfigTestHost.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ export function suspendInstance(
571571

572572
export function suspendOnActiveViewTransition(container: Container): void {}
573573

574-
export function waitForCommitToBeReady(): null {
574+
export function waitForCommitToBeReady(timeoutOffset: number): null {
575575
return null;
576576
}
577577

0 commit comments

Comments
 (0)