Switch callsites over to update lane priority
Rick Hanlon committed
Mar 8, 2021 at 10:46 UTC
431e76e2db39e74e25965027d67d69debdb7384a
7 files changed
+102
-216
packages/react-reconciler/src/ReactFiberCommitWork.new.js
+9
-10
@@ -17,12 +17,11 @@ import type {
17
} from './ReactFiberHostConfig';
18
import type {Fiber} from './ReactInternalTypes';
19
import type {FiberRoot} from './ReactInternalTypes';
20
-import type {Lanes} from './ReactFiberLane.new';
20
+import type {LanePriority, Lanes} from './ReactFiberLane.new';
21
import type {SuspenseState} from './ReactFiberSuspenseComponent.new';
22
import type {UpdateQueue} from './ReactUpdateQueue.new';
23
import type {FunctionComponentUpdateQueue} from './ReactFiberHooks.new';
24
import type {Wakeable} from 'shared/ReactTypes';
25
-import type {ReactPriorityLevel} from './ReactInternalTypes';
25
import type {OffscreenState} from './ReactFiberOffscreenComponent';
26
import type {HookFlags} from './ReactHookEffectTags';
27
@@ -1057,7 +1056,7 @@ function commitUnmount(
1056
finishedRoot: FiberRoot,
1057
current: Fiber,
1058
nearestMountedAncestor: Fiber,
1060
- renderPriorityLevel: ReactPriorityLevel,
1059
+ renderPriorityLevel: LanePriority,
1060
): void {
1061
onCommitUnmount(current);
1062
@@ -1153,7 +1152,7 @@ function commitNestedUnmounts(
1152
finishedRoot: FiberRoot,
1153
root: Fiber,
1154
nearestMountedAncestor: Fiber,
1156
- renderPriorityLevel: ReactPriorityLevel,
1155
+ renderPriorityLevel: LanePriority,
1156
): void {
1157
// While we're inside a removed host node we don't want to call
1158
// removeChild on the inner nodes because they're removed by the top
@@ -1463,7 +1462,7 @@ function unmountHostComponents(
1462
finishedRoot: FiberRoot,
1463
current: Fiber,
1464
nearestMountedAncestor: Fiber,
1466
- renderPriorityLevel: ReactPriorityLevel,
1465
+ renderPriorityLevel: LanePriority,
1466
): void {
1467
// We only have the top Fiber that was deleted but we need to recurse down its
1468
// children to find all the terminal nodes.
@@ -1601,7 +1600,7 @@ function commitDeletion(
1600
finishedRoot: FiberRoot,
1601
current: Fiber,
1602
nearestMountedAncestor: Fiber,
1604
- renderPriorityLevel: ReactPriorityLevel,
1603
+ renderPriorityLevel: LanePriority,
1604
): void {
1605
if (supportsMutation) {
1606
// Recursively delete all host nodes from the parent.
@@ -1945,7 +1944,7 @@ function commitResetTextContent(current: Fiber) {
1944
1945
export function commitMutationEffects(
1946
root: FiberRoot,
1948
- renderPriorityLevel: ReactPriorityLevel,
1947
+ renderPriorityLevel: LanePriority,
1948
firstChild: Fiber,
1949
) {
1950
nextEffect = firstChild;
@@ -1954,7 +1953,7 @@ export function commitMutationEffects(
1953
1954
function commitMutationEffects_begin(
1955
root: FiberRoot,
1957
- renderPriorityLevel: ReactPriorityLevel,
1956
+ renderPriorityLevel: LanePriority,
1957
) {
1958
while (nextEffect !== null) {
1959
const fiber = nextEffect;
@@ -2000,7 +1999,7 @@ function commitMutationEffects_begin(
1999
2000
function commitMutationEffects_complete(
2001
root: FiberRoot,
2003
- renderPriorityLevel: ReactPriorityLevel,
2002
+ renderPriorityLevel: LanePriority,
2003
) {
2004
while (nextEffect !== null) {
2005
const fiber = nextEffect;
@@ -2041,7 +2040,7 @@ function commitMutationEffects_complete(
2040
function commitMutationEffectsOnFiber(
2041
finishedWork: Fiber,
2042
root: FiberRoot,
2044
- renderPriorityLevel: ReactPriorityLevel,
2043
+ renderPriorityLevel: LanePriority,
2044
) {
2045
const flags = finishedWork.flags;
2046
packages/react-reconciler/src/ReactFiberCommitWork.old.js
+9
-10
@@ -17,12 +17,11 @@ import type {
17
} from './ReactFiberHostConfig';
18
import type {Fiber} from './ReactInternalTypes';
19
import type {FiberRoot} from './ReactInternalTypes';
20
-import type {Lanes} from './ReactFiberLane.old';
20
+import type {LanePriority, Lanes} from './ReactFiberLane.old';
21
import type {SuspenseState} from './ReactFiberSuspenseComponent.old';
22
import type {UpdateQueue} from './ReactUpdateQueue.old';
23
import type {FunctionComponentUpdateQueue} from './ReactFiberHooks.old';
24
import type {Wakeable} from 'shared/ReactTypes';
25
-import type {ReactPriorityLevel} from './ReactInternalTypes';
25
import type {OffscreenState} from './ReactFiberOffscreenComponent';
26
import type {HookFlags} from './ReactHookEffectTags';
27
@@ -1057,7 +1056,7 @@ function commitUnmount(
1056
finishedRoot: FiberRoot,
1057
current: Fiber,
1058
nearestMountedAncestor: Fiber,
1060
- renderPriorityLevel: ReactPriorityLevel,
1059
+ renderPriorityLevel: LanePriority,
1060
): void {
1061
onCommitUnmount(current);
1062
@@ -1153,7 +1152,7 @@ function commitNestedUnmounts(
1152
finishedRoot: FiberRoot,
1153
root: Fiber,
1154
nearestMountedAncestor: Fiber,
1156
- renderPriorityLevel: ReactPriorityLevel,
1155
+ renderPriorityLevel: LanePriority,
1156
): void {
1157
// While we're inside a removed host node we don't want to call
1158
// removeChild on the inner nodes because they're removed by the top
@@ -1463,7 +1462,7 @@ function unmountHostComponents(
1462
finishedRoot: FiberRoot,
1463
current: Fiber,
1464
nearestMountedAncestor: Fiber,
1466
- renderPriorityLevel: ReactPriorityLevel,
1465
+ renderPriorityLevel: LanePriority,
1466
): void {
1467
// We only have the top Fiber that was deleted but we need to recurse down its
1468
// children to find all the terminal nodes.
@@ -1601,7 +1600,7 @@ function commitDeletion(
1600
finishedRoot: FiberRoot,
1601
current: Fiber,
1602
nearestMountedAncestor: Fiber,
1604
- renderPriorityLevel: ReactPriorityLevel,
1603
+ renderPriorityLevel: LanePriority,
1604
): void {
1605
if (supportsMutation) {
1606
// Recursively delete all host nodes from the parent.
@@ -1945,7 +1944,7 @@ function commitResetTextContent(current: Fiber) {
1944
1945
export function commitMutationEffects(
1946
root: FiberRoot,
1948
- renderPriorityLevel: ReactPriorityLevel,
1947
+ renderPriorityLevel: LanePriority,
1948
firstChild: Fiber,
1949
) {
1950
nextEffect = firstChild;
@@ -1954,7 +1953,7 @@ export function commitMutationEffects(
1953
1954
function commitMutationEffects_begin(
1955
root: FiberRoot,
1957
- renderPriorityLevel: ReactPriorityLevel,
1956
+ renderPriorityLevel: LanePriority,
1957
) {
1958
while (nextEffect !== null) {
1959
const fiber = nextEffect;
@@ -2000,7 +1999,7 @@ function commitMutationEffects_begin(
1999
2000
function commitMutationEffects_complete(
2001
root: FiberRoot,
2003
- renderPriorityLevel: ReactPriorityLevel,
2002
+ renderPriorityLevel: LanePriority,
2003
) {
2004
while (nextEffect !== null) {
2005
const fiber = nextEffect;
@@ -2041,7 +2040,7 @@ function commitMutationEffects_complete(
2040
function commitMutationEffectsOnFiber(
2041
finishedWork: Fiber,
2042
root: FiberRoot,
2044
- renderPriorityLevel: ReactPriorityLevel,
2043
+ renderPriorityLevel: LanePriority,
2044
) {
2045
const flags = finishedWork.flags;
2046
packages/react-reconciler/src/ReactFiberDevToolsHook.new.js
+13
-6
@@ -9,10 +9,16 @@
9
10
import {enableProfilerTimer} from 'shared/ReactFeatureFlags';
11
12
-import type {Fiber, FiberRoot, ReactPriorityLevel} from './ReactInternalTypes';
12
+import type {Fiber, FiberRoot} from './ReactInternalTypes';
13
import type {ReactNodeList} from 'shared/ReactTypes';
14
+import type {LanePriority} from './ReactFiberLane.new';
15
16
import {DidCapture} from './ReactFiberFlags';
17
+import {
18
+ lanePriorityToSchedulerPriority,
19
+ NoLanePriority,
20
+} from './ReactFiberLane.new';
21
+import {NormalPriority} from './SchedulerWithReactIntegration.new';
22
23
declare var __REACT_DEVTOOLS_GLOBAL_HOOK__: Object | void;
24
@@ -78,18 +84,19 @@ export function onScheduleRoot(root: FiberRoot, children: ReactNodeList) {
84
}
85
}
86
81
-export function onCommitRoot(
82
- root: FiberRoot,
83
- priorityLevel: ReactPriorityLevel,
84
-) {
87
+export function onCommitRoot(root: FiberRoot, priorityLevel: LanePriority) {
88
if (injectedHook && typeof injectedHook.onCommitFiberRoot === 'function') {
89
try {
90
const didError = (root.current.flags & DidCapture) === DidCapture;
91
if (enableProfilerTimer) {
92
+ const schedulerPriority =
93
+ priorityLevel === NoLanePriority
94
+ ? NormalPriority
95
+ : lanePriorityToSchedulerPriority(priorityLevel);
96
injectedHook.onCommitFiberRoot(
97
rendererID,
98
root,
92
- priorityLevel,
99
+ schedulerPriority,
100
didError,
101
);
102
} else {
packages/react-reconciler/src/ReactFiberDevToolsHook.old.js
+13
-6
@@ -9,10 +9,16 @@
9
10
import {enableProfilerTimer} from 'shared/ReactFeatureFlags';
11
12
-import type {Fiber, FiberRoot, ReactPriorityLevel} from './ReactInternalTypes';
12
+import type {Fiber, FiberRoot} from './ReactInternalTypes';
13
import type {ReactNodeList} from 'shared/ReactTypes';
14
+import type {LanePriority} from './ReactFiberLane.old';
15
16
import {DidCapture} from './ReactFiberFlags';
17
+import {
18
+ lanePriorityToSchedulerPriority,
19
+ NoLanePriority,
20
+} from './ReactFiberLane.old';
21
+import {NormalPriority} from './SchedulerWithReactIntegration.old';
22
23
declare var __REACT_DEVTOOLS_GLOBAL_HOOK__: Object | void;
24
@@ -78,18 +84,19 @@ export function onScheduleRoot(root: FiberRoot, children: ReactNodeList) {
84
}
85
}
86
81
-export function onCommitRoot(
82
- root: FiberRoot,
83
- priorityLevel: ReactPriorityLevel,
84
-) {
87
+export function onCommitRoot(root: FiberRoot, priorityLevel: LanePriority) {
88
if (injectedHook && typeof injectedHook.onCommitFiberRoot === 'function') {
89
try {
90
const didError = (root.current.flags & DidCapture) === DidCapture;
91
if (enableProfilerTimer) {
92
+ const schedulerPriority =
93
+ priorityLevel === NoLanePriority
94
+ ? NormalPriority
95
+ : lanePriorityToSchedulerPriority(priorityLevel);
96
injectedHook.onCommitFiberRoot(
97
rendererID,
98
root,
92
- priorityLevel,
99
+ schedulerPriority,
100
didError,
101
);
102
} else {
packages/react-reconciler/src/ReactFiberWorkLoop.new.js
+29
-23
@@ -9,8 +9,7 @@
9
10
import type {Thenable, Wakeable} from 'shared/ReactTypes';
11
import type {Fiber, FiberRoot} from './ReactInternalTypes';
12
-import type {Lanes, Lane} from './ReactFiberLane.new';
13
-import type {ReactPriorityLevel} from './ReactInternalTypes';
12
+import type {Lanes, Lane, LanePriority} from './ReactFiberLane.new';
13
import type {Interaction} from 'scheduler/src/Tracing';
14
import type {SuspenseState} from './ReactFiberSuspenseComponent.new';
15
import type {StackCursor} from './ReactFiberStack.new';
@@ -46,7 +45,6 @@ import {
45
shouldYield,
46
requestPaint,
47
now,
49
- NoPriority as NoSchedulerPriority,
48
ImmediatePriority as ImmediateSchedulerPriority,
49
UserBlockingPriority as UserBlockingSchedulerPriority,
50
NormalPriority as NormalSchedulerPriority,
@@ -173,6 +171,7 @@ import {
171
markRootFinished,
172
schedulerPriorityToLanePriority,
173
lanePriorityToSchedulerPriority,
174
+ higherLanePriority,
175
} from './ReactFiberLane.new';
176
import {requestCurrentTransition, NoTransition} from './ReactFiberTransition';
177
import {beginWork as originalBeginWork} from './ReactFiberBeginWork.new';
@@ -333,7 +332,7 @@ let rootCommittingMutationOrLayoutEffects: FiberRoot | null = null;
332
333
let rootDoesHavePassiveEffects: boolean = false;
334
let rootWithPendingPassiveEffects: FiberRoot | null = null;
336
-let pendingPassiveEffectsRenderPriority: ReactPriorityLevel = NoSchedulerPriority;
335
+let pendingPassiveEffectsRenderPriority: LanePriority = NoLanePriority;
336
let pendingPassiveEffectsLanes: Lanes = NoLanes;
337
let pendingPassiveProfilerEffects: Array<Fiber> = [];
338
@@ -394,7 +393,7 @@ export function requestUpdateLane(fiber: Fiber): Lane {
393
if ((mode & BlockingMode) === NoMode) {
394
return (SyncLane: Lane);
395
} else if ((mode & ConcurrentMode) === NoMode) {
397
- return getCurrentPriorityLevel() === ImmediateSchedulerPriority
396
+ return getCurrentUpdateLanePriority() === SyncLanePriority
397
? (SyncLane: Lane)
398
: (SyncBatchedLane: Lane);
399
} else if (
@@ -482,7 +481,7 @@ function requestRetryLane(fiber: Fiber) {
481
if ((mode & BlockingMode) === NoMode) {
482
return (SyncLane: Lane);
483
} else if ((mode & ConcurrentMode) === NoMode) {
485
- return getCurrentPriorityLevel() === ImmediateSchedulerPriority
484
+ return getCurrentUpdateLanePriority() === SyncLanePriority
485
? (SyncLane: Lane)
486
: (SyncBatchedLane: Lane);
487
}
@@ -596,9 +595,9 @@ export function scheduleUpdateOnFiber(
595
// Schedule a discrete update but only if it's not Sync.
596
if (
597
(executionContext & DiscreteEventContext) !== NoContext &&
599
- // Only updates at user-blocking priority or greater are considered
600
- // discrete, even inside a discrete event.
601
- updateLanePriority === InputDiscreteLanePriority
598
+ // Only updates greater than default considered discrete, even inside a discrete event.
599
+ higherLanePriority(updateLanePriority, DefaultLanePriority) !==
600
+ DefaultLanePriority
601
) {
602
// This is the result of a discrete event. Track the lowest priority
603
// discrete update per root so we can flush them early, if needed.
@@ -1751,11 +1750,17 @@ function completeUnitOfWork(unitOfWork: Fiber): void {
1750
}
1751
1752
function commitRoot(root) {
1754
- const renderPriorityLevel = getCurrentPriorityLevel();
1755
- runWithPriority(
1756
- ImmediateSchedulerPriority,
1757
- commitRootImpl.bind(null, root, renderPriorityLevel),
1758
- );
1753
+ const previousUpdateLanePriority = getCurrentUpdateLanePriority();
1754
+ try {
1755
+ setCurrentUpdateLanePriority(SyncLanePriority);
1756
+ runWithPriority(
1757
+ ImmediateSchedulerPriority,
1758
+ commitRootImpl.bind(null, root, previousUpdateLanePriority),
1759
+ );
1760
+ } finally {
1761
+ setCurrentUpdateLanePriority(previousUpdateLanePriority);
1762
+ }
1763
+
1764
return null;
1765
}
1766
@@ -1983,7 +1988,10 @@ function commitRootImpl(root, renderPriorityLevel) {
1988
rootDoesHavePassiveEffects = false;
1989
rootWithPendingPassiveEffects = root;
1990
pendingPassiveEffectsLanes = lanes;
1986
- pendingPassiveEffectsRenderPriority = renderPriorityLevel;
1991
+ pendingPassiveEffectsRenderPriority =
1992
+ renderPriorityLevel === NoLanePriority
1993
+ ? DefaultLanePriority
1994
+ : renderPriorityLevel;
1995
}
1996
1997
// Read this again, since an effect might have updated it
@@ -2097,18 +2105,16 @@ function commitRootImpl(root, renderPriorityLevel) {
2105
2106
export function flushPassiveEffects(): boolean {
2107
// Returns whether passive effects were flushed.
2100
- if (pendingPassiveEffectsRenderPriority !== NoSchedulerPriority) {
2108
+ if (pendingPassiveEffectsRenderPriority !== NoLanePriority) {
2109
const priorityLevel =
2102
- pendingPassiveEffectsRenderPriority > NormalSchedulerPriority
2103
- ? NormalSchedulerPriority
2110
+ pendingPassiveEffectsRenderPriority > DefaultLanePriority
2111
+ ? DefaultLanePriority
2112
: pendingPassiveEffectsRenderPriority;
2105
- pendingPassiveEffectsRenderPriority = NoSchedulerPriority;
2113
+ pendingPassiveEffectsRenderPriority = NoLanePriority;
2114
const previousLanePriority = getCurrentUpdateLanePriority();
2115
try {
2108
- setCurrentUpdateLanePriority(
2109
- schedulerPriorityToLanePriority(priorityLevel),
2110
- );
2111
- return runWithPriority(priorityLevel, flushPassiveEffectsImpl);
2116
+ setCurrentUpdateLanePriority(priorityLevel);
2117
+ return flushPassiveEffectsImpl();
2118
} finally {
2119
setCurrentUpdateLanePriority(previousLanePriority);
2120
}
packages/react-reconciler/src/ReactFiberWorkLoop.old.js
+29
-23
@@ -9,8 +9,7 @@
9
10
import type {Thenable, Wakeable} from 'shared/ReactTypes';
11
import type {Fiber, FiberRoot} from './ReactInternalTypes';
12
-import type {Lanes, Lane} from './ReactFiberLane.old';
13
-import type {ReactPriorityLevel} from './ReactInternalTypes';
12
+import type {Lanes, Lane, LanePriority} from './ReactFiberLane.old';
13
import type {Interaction} from 'scheduler/src/Tracing';
14
import type {SuspenseState} from './ReactFiberSuspenseComponent.old';
15
import type {StackCursor} from './ReactFiberStack.old';
@@ -46,7 +45,6 @@ import {
45
shouldYield,
46
requestPaint,
47
now,
49
- NoPriority as NoSchedulerPriority,
48
ImmediatePriority as ImmediateSchedulerPriority,
49
UserBlockingPriority as UserBlockingSchedulerPriority,
50
NormalPriority as NormalSchedulerPriority,
@@ -173,6 +171,7 @@ import {
171
markRootFinished,
172
schedulerPriorityToLanePriority,
173
lanePriorityToSchedulerPriority,
174
+ higherLanePriority,
175
} from './ReactFiberLane.old';
176
import {requestCurrentTransition, NoTransition} from './ReactFiberTransition';
177
import {beginWork as originalBeginWork} from './ReactFiberBeginWork.old';
@@ -333,7 +332,7 @@ let rootCommittingMutationOrLayoutEffects: FiberRoot | null = null;
332
333
let rootDoesHavePassiveEffects: boolean = false;
334
let rootWithPendingPassiveEffects: FiberRoot | null = null;
336
-let pendingPassiveEffectsRenderPriority: ReactPriorityLevel = NoSchedulerPriority;
335
+let pendingPassiveEffectsRenderPriority: LanePriority = NoLanePriority;
336
let pendingPassiveEffectsLanes: Lanes = NoLanes;
337
let pendingPassiveProfilerEffects: Array<Fiber> = [];
338
@@ -394,7 +393,7 @@ export function requestUpdateLane(fiber: Fiber): Lane {
393
if ((mode & BlockingMode) === NoMode) {
394
return (SyncLane: Lane);
395
} else if ((mode & ConcurrentMode) === NoMode) {
397
- return getCurrentPriorityLevel() === ImmediateSchedulerPriority
396
+ return getCurrentUpdateLanePriority() === SyncLanePriority
397
? (SyncLane: Lane)
398
: (SyncBatchedLane: Lane);
399
} else if (
@@ -482,7 +481,7 @@ function requestRetryLane(fiber: Fiber) {
481
if ((mode & BlockingMode) === NoMode) {
482
return (SyncLane: Lane);
483
} else if ((mode & ConcurrentMode) === NoMode) {
485
- return getCurrentPriorityLevel() === ImmediateSchedulerPriority
484
+ return getCurrentUpdateLanePriority() === SyncLanePriority
485
? (SyncLane: Lane)
486
: (SyncBatchedLane: Lane);
487
}
@@ -596,9 +595,9 @@ export function scheduleUpdateOnFiber(
595
// Schedule a discrete update but only if it's not Sync.
596
if (
597
(executionContext & DiscreteEventContext) !== NoContext &&
599
- // Only updates at user-blocking priority or greater are considered
600
- // discrete, even inside a discrete event.
601
- updateLanePriority === InputDiscreteLanePriority
598
+ // Only updates greater than default considered discrete, even inside a discrete event.
599
+ higherLanePriority(updateLanePriority, DefaultLanePriority) !==
600
+ DefaultLanePriority
601
) {
602
// This is the result of a discrete event. Track the lowest priority
603
// discrete update per root so we can flush them early, if needed.
@@ -1751,11 +1750,17 @@ function completeUnitOfWork(unitOfWork: Fiber): void {
1750
}
1751
1752
function commitRoot(root) {
1754
- const renderPriorityLevel = getCurrentPriorityLevel();
1755
- runWithPriority(
1756
- ImmediateSchedulerPriority,
1757
- commitRootImpl.bind(null, root, renderPriorityLevel),
1758
- );
1753
+ const previousUpdateLanePriority = getCurrentUpdateLanePriority();
1754
+ try {
1755
+ setCurrentUpdateLanePriority(SyncLanePriority);
1756
+ runWithPriority(
1757
+ ImmediateSchedulerPriority,
1758
+ commitRootImpl.bind(null, root, previousUpdateLanePriority),
1759
+ );
1760
+ } finally {
1761
+ setCurrentUpdateLanePriority(previousUpdateLanePriority);
1762
+ }
1763
+
1764
return null;
1765
}
1766
@@ -1983,7 +1988,10 @@ function commitRootImpl(root, renderPriorityLevel) {
1988
rootDoesHavePassiveEffects = false;
1989
rootWithPendingPassiveEffects = root;
1990
pendingPassiveEffectsLanes = lanes;
1986
- pendingPassiveEffectsRenderPriority = renderPriorityLevel;
1991
+ pendingPassiveEffectsRenderPriority =
1992
+ renderPriorityLevel === NoLanePriority
1993
+ ? DefaultLanePriority
1994
+ : renderPriorityLevel;
1995
}
1996
1997
// Read this again, since an effect might have updated it
@@ -2097,18 +2105,16 @@ function commitRootImpl(root, renderPriorityLevel) {
2105
2106
export function flushPassiveEffects(): boolean {
2107
// Returns whether passive effects were flushed.
2100
- if (pendingPassiveEffectsRenderPriority !== NoSchedulerPriority) {
2108
+ if (pendingPassiveEffectsRenderPriority !== NoLanePriority) {
2109
const priorityLevel =
2102
- pendingPassiveEffectsRenderPriority > NormalSchedulerPriority
2103
- ? NormalSchedulerPriority
2110
+ pendingPassiveEffectsRenderPriority > DefaultLanePriority
2111
+ ? DefaultLanePriority
2112
: pendingPassiveEffectsRenderPriority;
2105
- pendingPassiveEffectsRenderPriority = NoSchedulerPriority;
2113
+ pendingPassiveEffectsRenderPriority = NoLanePriority;
2114
const previousLanePriority = getCurrentUpdateLanePriority();
2115
try {
2108
- setCurrentUpdateLanePriority(
2109
- schedulerPriorityToLanePriority(priorityLevel),
2110
- );
2111
- return runWithPriority(priorityLevel, flushPassiveEffectsImpl);
2116
+ setCurrentUpdateLanePriority(priorityLevel);
2117
+ return flushPassiveEffectsImpl();
2118
} finally {
2119
setCurrentUpdateLanePriority(previousLanePriority);
2120
}
packages/react-reconciler/src/__tests__/ReactSchedulerIntegration-test.js
-138
@@ -160,144 +160,6 @@ describe('ReactSchedulerIntegration', () => {
160
]);
161
});
162
163
- // TODO: Figure out what to do with these tests. I don't think most of them
164
- // make sense once we decouple Scheduler from React. Perhaps need similar
165
- // tests for React DOM.
166
- // @gate !enableNativeEventPriorityInference
167
- it('passive effects never have higher than normal priority', async () => {
168
- const {useEffect} = React;
169
- function ReadPriority({step}) {
170
- Scheduler.unstable_yieldValue(
171
- `Render priority: ${getCurrentPriorityAsString()}`,
172
- );
173
- useEffect(() => {
174
- Scheduler.unstable_yieldValue(
175
- `Effect priority: ${getCurrentPriorityAsString()}`,
176
- );
177
- return () => {
178
- Scheduler.unstable_yieldValue(
179
- `Effect clean-up priority: ${getCurrentPriorityAsString()}`,
180
- );
181
- };
182
- });
183
- return null;
184
- }
185
-
186
- // High priority renders spawn effects at normal priority
187
- await ReactNoop.act(async () => {
188
- Scheduler.unstable_runWithPriority(ImmediatePriority, () => {
189
- ReactNoop.render(<ReadPriority />);
190
- });
191
- });
192
- expect(Scheduler).toHaveYielded([
193
- 'Render priority: Immediate',
194
- 'Effect priority: Normal',
195
- ]);
196
- await ReactNoop.act(async () => {
197
- Scheduler.unstable_runWithPriority(UserBlockingPriority, () => {
198
- ReactNoop.render(<ReadPriority />);
199
- });
200
- });
201
- expect(Scheduler).toHaveYielded([
202
- 'Render priority: UserBlocking',
203
- 'Effect clean-up priority: Normal',
204
- 'Effect priority: Normal',
205
- ]);
206
-
207
- // Renders lower than normal priority spawn effects at the same priority
208
- await ReactNoop.act(async () => {
209
- Scheduler.unstable_runWithPriority(IdlePriority, () => {
210
- ReactNoop.render(<ReadPriority />);
211
- });
212
- });
213
- expect(Scheduler).toHaveYielded([
214
- 'Render priority: Idle',
215
- 'Effect clean-up priority: Idle',
216
- 'Effect priority: Idle',
217
- ]);
218
- });
219
-
220
- // TODO: Figure out what to do with these tests. I don't think most of them
221
- // make sense once we decouple Scheduler from React. Perhaps need similar
222
- // tests for React DOM.
223
- // @gate !enableNativeEventPriorityInference
224
- it('passive effects have correct priority even if they are flushed early', async () => {
225
- const {useEffect} = React;
226
- function ReadPriority({step}) {
227
- Scheduler.unstable_yieldValue(
228
- `Render priority [step ${step}]: ${getCurrentPriorityAsString()}`,
229
- );
230
- useEffect(() => {
231
- Scheduler.unstable_yieldValue(
232
- `Effect priority [step ${step}]: ${getCurrentPriorityAsString()}`,
233
- );
234
- });
235
- return null;
236
- }
237
- await ReactNoop.act(async () => {
238
- ReactNoop.render(<ReadPriority step={1} />);
239
- Scheduler.unstable_flushUntilNextPaint();
240
- expect(Scheduler).toHaveYielded(['Render priority [step 1]: Normal']);
241
- Scheduler.unstable_runWithPriority(UserBlockingPriority, () => {
242
- ReactNoop.render(<ReadPriority step={2} />);
243
- });
244
- });
245
- expect(Scheduler).toHaveYielded([
246
- 'Effect priority [step 1]: Normal',
247
- 'Render priority [step 2]: UserBlocking',
248
- 'Effect priority [step 2]: Normal',
249
- ]);
250
- });
251
-
252
- // TODO: Figure out what to do with these tests. I don't think most of them
253
- // make sense once we decouple Scheduler from React. Perhaps need similar
254
- // tests for React DOM.
255
- // @gate !enableNativeEventPriorityInference
256
- it('passive effect clean-up functions have correct priority even when component is deleted', async () => {
257
- const {useEffect} = React;
258
- function ReadPriority({step}) {
259
- useEffect(() => {
260
- return () => {
261
- Scheduler.unstable_yieldValue(
262
- `Effect clean-up priority: ${getCurrentPriorityAsString()}`,
263
- );
264
- };
265
- });
266
- return null;
267
- }
268
-
269
- await ReactNoop.act(async () => {
270
- ReactNoop.render(<ReadPriority />);
271
- });
272
- await ReactNoop.act(async () => {
273
- Scheduler.unstable_runWithPriority(ImmediatePriority, () => {
274
- ReactNoop.render(null);
275
- });
276
- });
277
- expect(Scheduler).toHaveYielded(['Effect clean-up priority: Normal']);
278
-
279
- await ReactNoop.act(async () => {
280
- ReactNoop.render(<ReadPriority />);
281
- });
282
- await ReactNoop.act(async () => {
283
- Scheduler.unstable_runWithPriority(UserBlockingPriority, () => {
284
- ReactNoop.render(null);
285
- });
286
- });
287
- expect(Scheduler).toHaveYielded(['Effect clean-up priority: Normal']);
288
-
289
- // Renders lower than normal priority spawn effects at the same priority
290
- await ReactNoop.act(async () => {
291
- ReactNoop.render(<ReadPriority />);
292
- });
293
- await ReactNoop.act(async () => {
294
- Scheduler.unstable_runWithPriority(IdlePriority, () => {
295
- ReactNoop.render(null);
296
- });
297
- });
298
- expect(Scheduler).toHaveYielded(['Effect clean-up priority: Idle']);
299
- });
300
-
163
it('passive effects are called before Normal-pri scheduled in layout effects', async () => {
164
const {useEffect, useLayoutEffect} = React;
165
function Effects({step}) {