GeezerVison is showing github.com — Bailout in sync task if work is not sync (#20813) · react/react@e2fd460
File treeExpand file treeCollapse file tree Open diff view settings react-dom/src/events/plugins/__tests__
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/events/plugins/__tests__/SimpleEventPlugin-test.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -477,8 +477,8 @@ describe('SimpleEventPlugin', function() { | 477 | 477 | // At the end, both counters should equal the total number of clicks | 478 | 478 | expect(Scheduler).toHaveYielded([ | 479 | 479 | 'High-pri count: 8, Low-pri count: 0', | 480 | | - | 481 | | - // TODO: with cancellation, this required another flush? | | 480 | + ]); | | 481 | + expect(Scheduler).toFlushAndYield([ | 482 | 482 | 'High-pri count: 8, Low-pri count: 8', | 483 | 483 | ]); | 484 | 484 | } else { | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberWorkLoop.new.js +14Lines changed: 14 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1028,6 +1028,20 @@ function performSyncWorkOnRoot(root) { | 1028 | 1028 | exitStatus = renderRootSync(root, lanes); | 1029 | 1029 | } else { | 1030 | 1030 | lanes = getNextLanes(root, NoLanes); | | 1031 | + // Because we don't cancel synchronous tasks, sometimes more than one | | 1032 | + // synchronous task ends up being scheduled. This is an artifact of the fact | | 1033 | + // that we have two different lanes that schedule sync tasks: discrete and | | 1034 | + // sync. If we had only one, then (I believe) this extra check wouldn't be | | 1035 | + // necessary, because there's nothing higher priority than sync that would | | 1036 | + // cause us to cancel it. | | 1037 | + // TODO: Merge InputDiscreteLanePriority with SyncLanePriority, then delete | | 1038 | + // this bailout. | | 1039 | + if (supportsMicrotasks) { | | 1040 | + const nextLanesPriority = returnNextLanesPriority(); | | 1041 | + if (nextLanesPriority < InputDiscreteLanePriority) { | | 1042 | + return null; | | 1043 | + } | | 1044 | + } | 1031 | 1045 | exitStatus = renderRootSync(root, lanes); | 1032 | 1046 | } | 1033 | 1047 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberWorkLoop.old.js +14Lines changed: 14 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1028,6 +1028,20 @@ function performSyncWorkOnRoot(root) { | 1028 | 1028 | exitStatus = renderRootSync(root, lanes); | 1029 | 1029 | } else { | 1030 | 1030 | lanes = getNextLanes(root, NoLanes); | | 1031 | + // Because we don't cancel synchronous tasks, sometimes more than one | | 1032 | + // synchronous task ends up being scheduled. This is an artifact of the fact | | 1033 | + // that we have two different lanes that schedule sync tasks: discrete and | | 1034 | + // sync. If we had only one, then (I believe) this extra check wouldn't be | | 1035 | + // necessary, because there's nothing higher priority than sync that would | | 1036 | + // cause us to cancel it. | | 1037 | + // TODO: Merge InputDiscreteLanePriority with SyncLanePriority, then delete | | 1038 | + // this bailout. | | 1039 | + if (supportsMicrotasks) { | | 1040 | + const nextLanesPriority = returnNextLanesPriority(); | | 1041 | + if (nextLanesPriority < InputDiscreteLanePriority) { | | 1042 | + return null; | | 1043 | + } | | 1044 | + } | 1031 | 1045 | exitStatus = renderRootSync(root, lanes); | 1032 | 1046 | } | 1033 | 1047 |
| |
|