Skip to content

Bailout without entering work loop for roots without work WIP #17267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/react-dom/src/__tests__/refs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,18 @@ describe('reactiverefs', () => {
expectClickLogsLengthToBe(testRefsComponent, 1);

// After clicking the reset, there should still only be one click log ref.
testRefsComponent.refs.resetDiv.click();
ReactTestUtils.act(() => testRefsComponent.refs.resetDiv.click());
expectClickLogsLengthToBe(testRefsComponent, 1);

// Begin incrementing clicks (and therefore refs).
clickIncrementer.click();
ReactTestUtils.act(() => clickIncrementer.click());
expectClickLogsLengthToBe(testRefsComponent, 2);

clickIncrementer.click();
ReactTestUtils.act(() => clickIncrementer.click());
expectClickLogsLengthToBe(testRefsComponent, 3);

// Now reset again
testRefsComponent.refs.resetDiv.click();
ReactTestUtils.act(() => testRefsComponent.refs.resetDiv.click());
expectClickLogsLengthToBe(testRefsComponent, 1);
});
});
Expand Down
36 changes: 36 additions & 0 deletions packages/react-reconciler/src/ReactFiberWorkLoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,24 @@ function performConcurrentWorkOnRoot(root, didTimeout) {
root !== workInProgressRoot ||
expirationTime !== renderExpirationTime
) {
// Before starting a fresh render, check if we can bailout on the entire tree.
// For non-root fibers, this bailout usually happens in the begin phase
// of the parent component, but roots are special because they don't
// have parents.
const remainingExpirationTimeOnRoot =
root.current.expirationTime > root.current.childExpirationTime
? root.current.expirationTime
: root.current.childExpirationTime;
if (remainingExpirationTimeOnRoot < expirationTime) {
// We can bailout without entering the work loop.
markRootFinishedAtTime(
root,
expirationTime,
remainingExpirationTimeOnRoot,
);
return null;
}

prepareFreshStack(root, expirationTime);
startWorkOnPendingInteractions(root, expirationTime);
}
Expand Down Expand Up @@ -997,6 +1015,24 @@ function performSyncWorkOnRoot(root) {
root !== workInProgressRoot ||
expirationTime !== renderExpirationTime
) {
// Before starting a fresh render, check if we can bailout on the entire tree.
// For non-root fibers, this bailout usually happens in the begin phase
// of the parent component, but roots are special because they don't
// have parents.
const remainingExpirationTimeOnRoot =
root.current.expirationTime > root.current.childExpirationTime
? root.current.expirationTime
: root.current.childExpirationTime;
if (remainingExpirationTimeOnRoot < expirationTime) {
// We can bailout without entering the work loop.
markRootFinishedAtTime(
root,
expirationTime,
remainingExpirationTimeOnRoot,
);
return null;
}

prepareFreshStack(root, expirationTime);
startWorkOnPendingInteractions(root, expirationTime);
}
Expand Down