Skip to content
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