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

Bailout in sync task if work is not sync #20813

Merged
merged 1 commit into from
Feb 16, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,8 @@ describe('SimpleEventPlugin', function() {
// At the end, both counters should equal the total number of clicks
expect(Scheduler).toHaveYielded([
'High-pri count: 8, Low-pri count: 0',

// TODO: with cancellation, this required another flush?
]);
expect(Scheduler).toFlushAndYield([
'High-pri count: 8, Low-pri count: 8',
]);
} else {
Expand Down
14 changes: 14 additions & 0 deletions packages/react-reconciler/src/ReactFiberWorkLoop.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,20 @@ function performSyncWorkOnRoot(root) {
exitStatus = renderRootSync(root, lanes);
} else {
lanes = getNextLanes(root, NoLanes);
// Because we don't cancel synchronous tasks, sometimes more than one
// synchronous task ends up being scheduled. This is an artifact of the fact
// that we have two different lanes that schedule sync tasks: discrete and
// sync. If we had only one, then (I believe) this extra check wouldn't be
// necessary, because there's nothing higher priority than sync that would
// cause us to cancel it.
// TODO: Merge InputDiscreteLanePriority with SyncLanePriority, then delete
// this bailout.
if (supportsMicrotasks) {
const nextLanesPriority = returnNextLanesPriority();
if (nextLanesPriority < InputDiscreteLanePriority) {
return null;
}
}
exitStatus = renderRootSync(root, lanes);
}

Expand Down
14 changes: 14 additions & 0 deletions packages/react-reconciler/src/ReactFiberWorkLoop.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,20 @@ function performSyncWorkOnRoot(root) {
exitStatus = renderRootSync(root, lanes);
} else {
lanes = getNextLanes(root, NoLanes);
// Because we don't cancel synchronous tasks, sometimes more than one
// synchronous task ends up being scheduled. This is an artifact of the fact
// that we have two different lanes that schedule sync tasks: discrete and
// sync. If we had only one, then (I believe) this extra check wouldn't be
// necessary, because there's nothing higher priority than sync that would
// cause us to cancel it.
// TODO: Merge InputDiscreteLanePriority with SyncLanePriority, then delete
// this bailout.
if (supportsMicrotasks) {
const nextLanesPriority = returnNextLanesPriority();
if (nextLanesPriority < InputDiscreteLanePriority) {
return null;
}
}
exitStatus = renderRootSync(root, lanes);
}

Expand Down