|
9 | 9 |
|
10 | 10 | import type {Thenable, Wakeable} from 'shared/ReactTypes';
|
11 | 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'; |
14 | 13 | import type {Interaction} from 'scheduler/src/Tracing';
|
15 | 14 | import type {SuspenseState} from './ReactFiberSuspenseComponent.new';
|
16 | 15 | import type {StackCursor} from './ReactFiberStack.new';
|
@@ -46,7 +45,6 @@ import {
|
46 | 45 | shouldYield,
|
47 | 46 | requestPaint,
|
48 | 47 | now,
|
49 |
| - NoPriority as NoSchedulerPriority, |
50 | 48 | ImmediatePriority as ImmediateSchedulerPriority,
|
51 | 49 | UserBlockingPriority as UserBlockingSchedulerPriority,
|
52 | 50 | NormalPriority as NormalSchedulerPriority,
|
@@ -173,6 +171,7 @@ import {
|
173 | 171 | markRootFinished,
|
174 | 172 | schedulerPriorityToLanePriority,
|
175 | 173 | lanePriorityToSchedulerPriority,
|
| 174 | + higherLanePriority, |
176 | 175 | } from './ReactFiberLane.new';
|
177 | 176 | import {requestCurrentTransition, NoTransition} from './ReactFiberTransition';
|
178 | 177 | import {beginWork as originalBeginWork} from './ReactFiberBeginWork.new';
|
@@ -333,7 +332,7 @@ let rootCommittingMutationOrLayoutEffects: FiberRoot | null = null;
|
333 | 332 |
|
334 | 333 | let rootDoesHavePassiveEffects: boolean = false;
|
335 | 334 | let rootWithPendingPassiveEffects: FiberRoot | null = null;
|
336 |
| -let pendingPassiveEffectsRenderPriority: ReactPriorityLevel = NoSchedulerPriority; |
| 335 | +let pendingPassiveEffectsRenderPriority: LanePriority = NoLanePriority; |
337 | 336 | let pendingPassiveEffectsLanes: Lanes = NoLanes;
|
338 | 337 | let pendingPassiveProfilerEffects: Array<Fiber> = [];
|
339 | 338 |
|
@@ -394,7 +393,7 @@ export function requestUpdateLane(fiber: Fiber): Lane {
|
394 | 393 | if ((mode & BlockingMode) === NoMode) {
|
395 | 394 | return (SyncLane: Lane);
|
396 | 395 | } else if ((mode & ConcurrentMode) === NoMode) {
|
397 |
| - return getCurrentPriorityLevel() === ImmediateSchedulerPriority |
| 396 | + return getCurrentUpdateLanePriority() === SyncLanePriority |
398 | 397 | ? (SyncLane: Lane)
|
399 | 398 | : (SyncBatchedLane: Lane);
|
400 | 399 | } else if (
|
@@ -482,7 +481,7 @@ function requestRetryLane(fiber: Fiber) {
|
482 | 481 | if ((mode & BlockingMode) === NoMode) {
|
483 | 482 | return (SyncLane: Lane);
|
484 | 483 | } else if ((mode & ConcurrentMode) === NoMode) {
|
485 |
| - return getCurrentPriorityLevel() === ImmediateSchedulerPriority |
| 484 | + return getCurrentUpdateLanePriority() === SyncLanePriority |
486 | 485 | ? (SyncLane: Lane)
|
487 | 486 | : (SyncBatchedLane: Lane);
|
488 | 487 | }
|
@@ -596,9 +595,9 @@ export function scheduleUpdateOnFiber(
|
596 | 595 | // Schedule a discrete update but only if it's not Sync.
|
597 | 596 | if (
|
598 | 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 |
602 | 601 | ) {
|
603 | 602 | // This is the result of a discrete event. Track the lowest priority
|
604 | 603 | // discrete update per root so we can flush them early, if needed.
|
@@ -1751,11 +1750,17 @@ function completeUnitOfWork(unitOfWork: Fiber): void {
|
1751 | 1750 | }
|
1752 | 1751 |
|
1753 | 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 | + |
1759 | 1764 | return null;
|
1760 | 1765 | }
|
1761 | 1766 |
|
@@ -1983,7 +1988,10 @@ function commitRootImpl(root, renderPriorityLevel) {
|
1983 | 1988 | rootDoesHavePassiveEffects = false;
|
1984 | 1989 | rootWithPendingPassiveEffects = root;
|
1985 | 1990 | pendingPassiveEffectsLanes = lanes;
|
1986 |
| - pendingPassiveEffectsRenderPriority = renderPriorityLevel; |
| 1991 | + pendingPassiveEffectsRenderPriority = |
| 1992 | + renderPriorityLevel === NoLanePriority |
| 1993 | + ? DefaultLanePriority |
| 1994 | + : renderPriorityLevel; |
1987 | 1995 | }
|
1988 | 1996 |
|
1989 | 1997 | // Read this again, since an effect might have updated it
|
@@ -2097,18 +2105,16 @@ function commitRootImpl(root, renderPriorityLevel) {
|
2097 | 2105 |
|
2098 | 2106 | export function flushPassiveEffects(): boolean {
|
2099 | 2107 | // Returns whether passive effects were flushed.
|
2100 |
| - if (pendingPassiveEffectsRenderPriority !== NoSchedulerPriority) { |
| 2108 | + if (pendingPassiveEffectsRenderPriority !== NoLanePriority) { |
2101 | 2109 | const priorityLevel =
|
2102 |
| - pendingPassiveEffectsRenderPriority > NormalSchedulerPriority |
2103 |
| - ? NormalSchedulerPriority |
| 2110 | + pendingPassiveEffectsRenderPriority > DefaultLanePriority |
| 2111 | + ? DefaultLanePriority |
2104 | 2112 | : pendingPassiveEffectsRenderPriority;
|
2105 |
| - pendingPassiveEffectsRenderPriority = NoSchedulerPriority; |
| 2113 | + pendingPassiveEffectsRenderPriority = NoLanePriority; |
2106 | 2114 | const previousLanePriority = getCurrentUpdateLanePriority();
|
2107 | 2115 | try {
|
2108 |
| - setCurrentUpdateLanePriority( |
2109 |
| - schedulerPriorityToLanePriority(priorityLevel), |
2110 |
| - ); |
2111 |
| - return runWithPriority(priorityLevel, flushPassiveEffectsImpl); |
| 2116 | + setCurrentUpdateLanePriority(priorityLevel); |
| 2117 | + return flushPassiveEffectsImpl(); |
2112 | 2118 | } finally {
|
2113 | 2119 | setCurrentUpdateLanePriority(previousLanePriority);
|
2114 | 2120 | }
|
|
0 commit comments