@samitouri / QOS-React-2 / commits / 03ede83d2e

Use EventPriority to track update priority (#21082)

Instead of LanePriority. Internally, EventPriority is just a lane, so this skips an extra conversion. Since EventPriority is a "public" (to the host config) type, I was also able to remove some deep imports of the Lane module. This gets us most of the way to deleting the LanePriority entirely.

Andrew Clark committed Mar 25, 2021 at 11:21 UTC 03ede83d2ea1878e5cb82c3c17844621989caf66
25 files changed +484 -479
packages/react-dom/src/__tests__/ReactDOMServerPartialHydration-test.internal.js
+4 -6
@@ -17,11 +17,7 @@ let ReactFeatureFlags;
17 let Suspense;
18 let SuspenseList;
19 let act;
20 -
21 -// Copied from ReactFiberLanes. Don't do this!
22 -// This is hard coded directly to avoid needing to import, and
23 -// we'll remove this as we replace runWithPriority with React APIs.
24 -export const IdleLanePriority = 2;
20 +let IdleEventPriority;
21
22 function dispatchMouseEvent(to, from) {
23 if (!to) {
@@ -89,6 +85,8 @@ describe('ReactDOMServerPartialHydration', () => {
85 Scheduler = require('scheduler');
86 Suspense = React.Suspense;
87 SuspenseList = React.SuspenseList;
88 +
89 + IdleEventPriority = require('react-reconciler/constants').IdleEventPriority;
90 });
91
92 // Note: This is based on a similar component we use in www. We can delete
@@ -628,7 +626,7 @@ describe('ReactDOMServerPartialHydration', () => {
626 expect(span.textContent).toBe('Hello');
627
628 // Schedule an update at idle priority
631 - ReactDOM.unstable_runWithPriority(IdleLanePriority, () => {
629 + ReactDOM.unstable_runWithPriority(IdleEventPriority, () => {
630 root.render(<App text="Hi" className="hi" />);
631 });
632
packages/react-dom/src/__tests__/ReactDOMServerSelectiveHydration-test.internal.js
+4 -5
@@ -19,10 +19,7 @@ let Scheduler;
19 let Suspense;
20 let act;
21
22 -// Copied from ReactFiberLanes. Don't do this!
23 -// This is hard coded directly to avoid needing to import, and
24 -// we'll remove this as we replace runWithPriority with React APIs.
25 -export const IdleLanePriority = 2;
22 +let IdleEventPriority;
23
24 function dispatchMouseHoverEvent(to, from) {
25 if (!to) {
@@ -101,7 +98,7 @@ function dispatchClickEvent(target) {
98 // and there's no native DOM event that maps to idle priority, so this is a
99 // temporary workaround. Need something like ReactDOM.unstable_IdleUpdates.
100 function TODO_scheduleIdleDOMSchedulerTask(fn) {
104 - ReactDOM.unstable_runWithPriority(IdleLanePriority, () => {
101 + ReactDOM.unstable_runWithPriority(IdleEventPriority, () => {
102 const prevEvent = window.event;
103 window.event = {type: 'message'};
104 try {
@@ -125,6 +122,8 @@ describe('ReactDOMServerSelectiveHydration', () => {
122 act = ReactTestUtils.unstable_concurrentAct;
123 Scheduler = require('scheduler');
124 Suspense = React.Suspense;
125 +
126 + IdleEventPriority = require('react-reconciler/constants').IdleEventPriority;
127 });
128
129 // @gate experimental
packages/react-dom/src/client/ReactDOM.js
+5 -3
@@ -35,9 +35,11 @@ import {
35 attemptDiscreteHydration,
36 attemptContinuousHydration,
37 attemptHydrationAtCurrentPriority,
38 - runWithPriority,
39 - getCurrentUpdateLanePriority,
38 } from 'react-reconciler/src/ReactFiberReconciler';
39 +import {
40 + runWithPriority,
41 + getCurrentUpdatePriority,
42 +} from 'react-reconciler/src/ReactEventPriorities';
43 import {createPortal as createPortalImpl} from 'react-reconciler/src/ReactPortal';
44 import {canUseDOM} from 'shared/ExecutionEnvironment';
45 import ReactVersion from 'shared/ReactVersion';
@@ -74,7 +76,7 @@ setAttemptSynchronousHydration(attemptSynchronousHydration);
76 setAttemptDiscreteHydration(attemptDiscreteHydration);
77 setAttemptContinuousHydration(attemptContinuousHydration);
78 setAttemptHydrationAtCurrentPriority(attemptHydrationAtCurrentPriority);
77 -setGetCurrentUpdatePriority(getCurrentUpdateLanePriority);
79 +setGetCurrentUpdatePriority(getCurrentUpdatePriority);
80 setAttemptHydrationAtPriority(runWithPriority);
81
82 let didWarnAboutUnstableCreatePortal = false;
packages/react-dom/src/events/ReactDOMEventListener.js
+5 -24
@@ -44,16 +44,6 @@ import {
44 discreteUpdates,
45 } from './ReactDOMUpdateBatching';
46
47 -import {
48 - InputContinuousLanePriority as InputContinuousLanePriority_old,
49 - getCurrentUpdateLanePriority as getCurrentUpdateLanePriority_old,
50 - setCurrentUpdateLanePriority as setCurrentUpdateLanePriority_old,
51 -} from 'react-reconciler/src/ReactFiberLane.old';
52 -import {
53 - InputContinuousLanePriority as InputContinuousLanePriority_new,
54 - getCurrentUpdateLanePriority as getCurrentUpdateLanePriority_new,
55 - setCurrentUpdateLanePriority as setCurrentUpdateLanePriority_new,
56 -} from 'react-reconciler/src/ReactFiberLane.new';
47 import {getCurrentPriorityLevel as getCurrentPriorityLevel_old} from 'react-reconciler/src/SchedulerWithReactIntegration.old';
48 import {
49 getCurrentPriorityLevel as getCurrentPriorityLevel_new,
@@ -68,19 +58,10 @@ import {
58 ContinuousEventPriority,
59 DefaultEventPriority,
60 IdleEventPriority,
61 + getCurrentUpdatePriority,
62 + setCurrentUpdatePriority,
63 } from 'react-reconciler/src/ReactEventPriorities';
64
73 -// TODO: These should use the opaque EventPriority type instead of LanePriority.
74 -// Then internally we can use a Lane.
75 -const InputContinuousLanePriority = enableNewReconciler
76 - ? InputContinuousLanePriority_new
77 - : InputContinuousLanePriority_old;
78 -const getCurrentUpdateLanePriority = enableNewReconciler
79 - ? getCurrentUpdateLanePriority_new
80 - : getCurrentUpdateLanePriority_old;
81 -const setCurrentUpdateLanePriority = enableNewReconciler
82 - ? setCurrentUpdateLanePriority_new
83 - : setCurrentUpdateLanePriority_old;
65 const getCurrentPriorityLevel = enableNewReconciler
66 ? getCurrentPriorityLevel_new
67 : getCurrentPriorityLevel_old;
@@ -167,12 +148,12 @@ function dispatchContinuousEvent(
148 container,
149 nativeEvent,
150 ) {
170 - const previousPriority = getCurrentUpdateLanePriority();
151 + const previousPriority = getCurrentUpdatePriority();
152 try {
172 - setCurrentUpdateLanePriority(InputContinuousLanePriority);
153 + setCurrentUpdatePriority(ContinuousEventPriority);
154 dispatchEvent(domEventName, eventSystemFlags, container, nativeEvent);
155 } finally {
175 - setCurrentUpdateLanePriority(previousPriority);
156 + setCurrentUpdatePriority(previousPriority);
157 }
158 }
159
packages/react-dom/src/events/ReactDOMEventReplaying.js
+18 -10
@@ -12,7 +12,7 @@ import type {Container, SuspenseInstance} from '../client/ReactDOMHostConfig';
12 import type {DOMEventName} from '../events/DOMEventNames';
13 import type {EventSystemFlags} from './EventSystemFlags';
14 import type {FiberRoot} from 'react-reconciler/src/ReactInternalTypes';
15 -import type {LanePriority} from 'react-reconciler/src/ReactFiberLane.old';
15 +import type {EventPriority} from 'react-reconciler/src/ReactEventPriorities';
16
17 import {enableSelectiveHydration} from 'shared/ReactFeatureFlags';
18 import {
@@ -30,6 +30,7 @@ import {
30 getClosestInstanceFromNode,
31 } from '../client/ReactDOMComponentTree';
32 import {HostRoot, SuspenseComponent} from 'react-reconciler/src/ReactWorkTags';
33 +import {isHigherEventPriority} from 'react-reconciler/src/ReactEventPriorities';
34
35 let attemptSynchronousHydration: (fiber: Object) => void;
36
@@ -57,16 +58,16 @@ export function setAttemptHydrationAtCurrentPriority(
58 attemptHydrationAtCurrentPriority = fn;
59 }
60
60 -let getCurrentUpdatePriority: () => LanePriority;
61 +let getCurrentUpdatePriority: () => EventPriority;
62
62 -export function setGetCurrentUpdatePriority(fn: () => LanePriority) {
63 +export function setGetCurrentUpdatePriority(fn: () => EventPriority) {
64 getCurrentUpdatePriority = fn;
65 }
66
66 -let attemptHydrationAtPriority: <T>(priority: LanePriority, fn: () => T) => T;
67 +let attemptHydrationAtPriority: <T>(priority: EventPriority, fn: () => T) => T;
68
69 export function setAttemptHydrationAtPriority(
69 - fn: <T>(priority: LanePriority, fn: () => T) => T,
70 + fn: <T>(priority: EventPriority, fn: () => T) => T,
71 ) {
72 attemptHydrationAtPriority = fn;
73 }
@@ -109,7 +110,7 @@ const queuedPointerCaptures: Map<number, QueuedReplayableEvent> = new Map();
110 type QueuedHydrationTarget = {|
111 blockedOn: null | Container | SuspenseInstance,
112 target: Node,
112 - lanePriority: LanePriority,
113 + priority: EventPriority,
114 |};
115 const queuedExplicitHydrationTargets: Array<QueuedHydrationTarget> = [];
116
@@ -390,7 +391,7 @@ function attemptExplicitHydrationTarget(
391 // We're blocked on hydrating this boundary.
392 // Increase its priority.
393 queuedTarget.blockedOn = instance;
393 - attemptHydrationAtPriority(queuedTarget.lanePriority, () => {
394 + attemptHydrationAtPriority(queuedTarget.priority, () => {
395 attemptHydrationAtCurrentPriority(nearestMounted);
396 });
397
@@ -412,16 +413,23 @@ function attemptExplicitHydrationTarget(
413
414 export function queueExplicitHydrationTarget(target: Node): void {
415 if (enableSelectiveHydration) {
415 - const updateLanePriority = getCurrentUpdatePriority();
416 + // TODO: This will read the priority if it's dispatched by the React
417 + // event system but not native events. Should read window.event.type, like
418 + // we do for updates (getCurrentEventPriority).
419 + const updatePriority = getCurrentUpdatePriority();
420 const queuedTarget: QueuedHydrationTarget = {
421 blockedOn: null,
422 target: target,
419 - lanePriority: updateLanePriority,
423 + priority: updatePriority,
424 };
425 let i = 0;
426 for (; i < queuedExplicitHydrationTargets.length; i++) {
427 + // Stop once we hit the first target with lower priority than
428 if (
424 - updateLanePriority <= queuedExplicitHydrationTargets[i].lanePriority
429 + !isHigherEventPriority(
430 + updatePriority,
431 + queuedExplicitHydrationTargets[i].priority,
432 + )
433 ) {
434 break;
435 }
packages/react-reconciler/src/ReactEventPriorities.js
+49 -12
@@ -14,6 +14,10 @@ import {
14 ContinuousEventPriority as ContinuousEventPriority_old,
15 DefaultEventPriority as DefaultEventPriority_old,
16 IdleEventPriority as IdleEventPriority_old,
17 + getCurrentUpdatePriority as getCurrentUpdatePriority_old,
18 + setCurrentUpdatePriority as setCurrentUpdatePriority_old,
19 + runWithPriority as runWithPriority_old,
20 + isHigherEventPriority as isHigherEventPriority_old,
21 } from './ReactEventPriorities.old';
22
23 import {
@@ -21,17 +25,50 @@ import {
25 ContinuousEventPriority as ContinuousEventPriority_new,
26 DefaultEventPriority as DefaultEventPriority_new,
27 IdleEventPriority as IdleEventPriority_new,
28 + getCurrentUpdatePriority as getCurrentUpdatePriority_new,
29 + setCurrentUpdatePriority as setCurrentUpdatePriority_new,
30 + runWithPriority as runWithPriority_new,
31 + isHigherEventPriority as isHigherEventPriority_new,
32 } from './ReactEventPriorities.new';
33
26 -export const DiscreteEventPriority = enableNewReconciler
27 - ? DiscreteEventPriority_new
28 - : DiscreteEventPriority_old;
29 -export const ContinuousEventPriority = enableNewReconciler
30 - ? ContinuousEventPriority_new
31 - : ContinuousEventPriority_old;
32 -export const DefaultEventPriority = enableNewReconciler
33 - ? DefaultEventPriority_new
34 - : DefaultEventPriority_old;
35 -export const IdleEventPriority = enableNewReconciler
36 - ? IdleEventPriority_new
37 - : IdleEventPriority_old;
34 +export opaque type EventPriority = number;
35 +
36 +export const DiscreteEventPriority: EventPriority = enableNewReconciler
37 + ? (DiscreteEventPriority_new: any)
38 + : (DiscreteEventPriority_old: any);
39 +export const ContinuousEventPriority: EventPriority = enableNewReconciler
40 + ? (ContinuousEventPriority_new: any)
41 + : (ContinuousEventPriority_old: any);
42 +export const DefaultEventPriority: EventPriority = enableNewReconciler
43 + ? (DefaultEventPriority_new: any)
44 + : (DefaultEventPriority_old: any);
45 +export const IdleEventPriority: EventPriority = enableNewReconciler
46 + ? (IdleEventPriority_new: any)
47 + : (IdleEventPriority_old: any);
48 +
49 +export function runWithPriority<T>(priority: EventPriority, fn: () => T): T {
50 + return enableNewReconciler
51 + ? runWithPriority_new((priority: any), fn)
52 + : runWithPriority_old((priority: any), fn);
53 +}
54 +
55 +export function getCurrentUpdatePriority(): EventPriority {
56 + return enableNewReconciler
57 + ? (getCurrentUpdatePriority_new(): any)
58 + : (getCurrentUpdatePriority_old(): any);
59 +}
60 +
61 +export function setCurrentUpdatePriority(priority: EventPriority) {
62 + return enableNewReconciler
63 + ? setCurrentUpdatePriority_new((priority: any))
64 + : setCurrentUpdatePriority_old((priority: any));
65 +}
66 +
67 +export function isHigherEventPriority(
68 + a: EventPriority,
69 + b: EventPriority,
70 +): boolean {
71 + return enableNewReconciler
72 + ? isHigherEventPriority_new((a: any), (b: any))
73 + : isHigherEventPriority_old((a: any), (b: any));
74 +}
packages/react-reconciler/src/ReactEventPriorities.new.js
+65 -5
@@ -7,9 +7,69 @@
7 * @flow
8 */
9
10 -export {
11 - SyncLane as DiscreteEventPriority,
12 - InputContinuousLane as ContinuousEventPriority,
13 - DefaultLane as DefaultEventPriority,
14 - IdleLane as IdleEventPriority,
10 +import type {Lane, Lanes} from './ReactFiberLane.new';
11 +
12 +import {
13 + NoLane,
14 + SyncLane,
15 + InputContinuousLane,
16 + DefaultLane,
17 + IdleLane,
18 + getHighestPriorityLane,
19 + includesNonIdleWork,
20 } from './ReactFiberLane.new';
21 +
22 +export opaque type EventPriority = Lane;
23 +
24 +export const DiscreteEventPriority: EventPriority = SyncLane;
25 +export const ContinuousEventPriority: EventPriority = InputContinuousLane;
26 +export const DefaultEventPriority: EventPriority = DefaultLane;
27 +export const IdleEventPriority: EventPriority = IdleLane;
28 +
29 +let currentUpdatePriority: EventPriority = NoLane;
30 +
31 +export function getCurrentUpdatePriority(): EventPriority {
32 + return currentUpdatePriority;
33 +}
34 +
35 +export function setCurrentUpdatePriority(newPriority: EventPriority) {
36 + currentUpdatePriority = newPriority;
37 +}
38 +
39 +export function runWithPriority<T>(priority: EventPriority, fn: () => T): T {
40 + const previousPriority = currentUpdatePriority;
41 + try {
42 + currentUpdatePriority = priority;
43 + return fn();
44 + } finally {
45 + currentUpdatePriority = previousPriority;
46 + }
47 +}
48 +
49 +export function higherEventPriority(
50 + a: EventPriority,
51 + b: EventPriority,
52 +): EventPriority {
53 + return a !== 0 && a < b ? a : b;
54 +}
55 +
56 +export function isHigherEventPriority(
57 + a: EventPriority,
58 + b: EventPriority,
59 +): boolean {
60 + return a !== 0 && a < b;
61 +}
62 +
63 +export function lanesToEventPriority(lanes: Lanes): EventPriority {
64 + const lane = getHighestPriorityLane(lanes);
65 + if (!isHigherEventPriority(DiscreteEventPriority, lane)) {
66 + return DiscreteEventPriority;
67 + }
68 + if (!isHigherEventPriority(ContinuousEventPriority, lane)) {
69 + return ContinuousEventPriority;
70 + }
71 + if (includesNonIdleWork(lane)) {
72 + return DefaultEventPriority;
73 + }
74 + return IdleEventPriority;
75 +}
packages/react-reconciler/src/ReactEventPriorities.old.js
+65 -5
@@ -7,9 +7,69 @@
7 * @flow
8 */
9
10 -export {
11 - SyncLane as DiscreteEventPriority,
12 - InputContinuousLane as ContinuousEventPriority,
13 - DefaultLane as DefaultEventPriority,
14 - IdleLane as IdleEventPriority,
10 +import type {Lane, Lanes} from './ReactFiberLane.old';
11 +
12 +import {
13 + NoLane,
14 + SyncLane,
15 + InputContinuousLane,
16 + DefaultLane,
17 + IdleLane,
18 + getHighestPriorityLane,
19 + includesNonIdleWork,
20 } from './ReactFiberLane.old';
21 +
22 +export opaque type EventPriority = Lane;
23 +
24 +export const DiscreteEventPriority: EventPriority = SyncLane;
25 +export const ContinuousEventPriority: EventPriority = InputContinuousLane;
26 +export const DefaultEventPriority: EventPriority = DefaultLane;
27 +export const IdleEventPriority: EventPriority = IdleLane;
28 +
29 +let currentUpdatePriority: EventPriority = NoLane;
30 +
31 +export function getCurrentUpdatePriority(): EventPriority {
32 + return currentUpdatePriority;
33 +}
34 +
35 +export function setCurrentUpdatePriority(newPriority: EventPriority) {
36 + currentUpdatePriority = newPriority;
37 +}
38 +
39 +export function runWithPriority<T>(priority: EventPriority, fn: () => T): T {
40 + const previousPriority = currentUpdatePriority;
41 + try {
42 + currentUpdatePriority = priority;
43 + return fn();
44 + } finally {
45 + currentUpdatePriority = previousPriority;
46 + }
47 +}
48 +
49 +export function higherEventPriority(
50 + a: EventPriority,
51 + b: EventPriority,
52 +): EventPriority {
53 + return a !== 0 && a < b ? a : b;
54 +}
55 +
56 +export function isHigherEventPriority(
57 + a: EventPriority,
58 + b: EventPriority,
59 +): boolean {
60 + return a !== 0 && a < b;
61 +}
62 +
63 +export function lanesToEventPriority(lanes: Lanes): EventPriority {
64 + const lane = getHighestPriorityLane(lanes);
65 + if (!isHigherEventPriority(DiscreteEventPriority, lane)) {
66 + return DiscreteEventPriority;
67 + }
68 + if (!isHigherEventPriority(ContinuousEventPriority, lane)) {
69 + return ContinuousEventPriority;
70 + }
71 + if (includesNonIdleWork(lane)) {
72 + return DefaultEventPriority;
73 + }
74 + return IdleEventPriority;
75 +}
packages/react-reconciler/src/ReactFiberCommitWork.new.js
+15 -65
@@ -17,7 +17,7 @@ import type {
17 } from './ReactFiberHostConfig';
18 import type {Fiber} from './ReactInternalTypes';
19 import type {FiberRoot} from './ReactInternalTypes';
20 -import type {LanePriority, Lanes} from './ReactFiberLane.new';
20 +import type {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';
@@ -1067,7 +1067,6 @@ function commitUnmount(
1067 finishedRoot: FiberRoot,
1068 current: Fiber,
1069 nearestMountedAncestor: Fiber,
1070 - renderPriorityLevel: LanePriority,
1070 ): void {
1071 onCommitUnmount(current);
1072
@@ -1127,12 +1126,7 @@ function commitUnmount(
1126 // We are also not using this parent because
1127 // the portal will get pushed immediately.
1128 if (supportsMutation) {
1130 - unmountHostComponents(
1131 - finishedRoot,
1132 - current,
1133 - nearestMountedAncestor,
1134 - renderPriorityLevel,
1135 - );
1129 + unmountHostComponents(finishedRoot, current, nearestMountedAncestor);
1130 } else if (supportsPersistence) {
1131 emptyPortalContainer(current);
1132 }
@@ -1163,7 +1157,6 @@ function commitNestedUnmounts(
1157 finishedRoot: FiberRoot,
1158 root: Fiber,
1159 nearestMountedAncestor: Fiber,
1166 - renderPriorityLevel: LanePriority,
1160 ): void {
1161 // While we're inside a removed host node we don't want to call
1162 // removeChild on the inner nodes because they're removed by the top
@@ -1172,12 +1165,7 @@ function commitNestedUnmounts(
1165 // we do an inner loop while we're still inside the host node.
1166 let node: Fiber = root;
1167 while (true) {
1175 - commitUnmount(
1176 - finishedRoot,
1177 - node,
1178 - nearestMountedAncestor,
1179 - renderPriorityLevel,
1180 - );
1168 + commitUnmount(finishedRoot, node, nearestMountedAncestor);
1169 // Visit children because they may contain more composite or host nodes.
1170 // Skip portals because commitUnmount() currently visits them recursively.
1171 if (
@@ -1532,7 +1520,6 @@ function unmountHostComponents(
1520 finishedRoot: FiberRoot,
1521 current: Fiber,
1522 nearestMountedAncestor: Fiber,
1535 - renderPriorityLevel: LanePriority,
1523 ): void {
1524 // We only have the top Fiber that was deleted but we need to recurse down its
1525 // children to find all the terminal nodes.
@@ -1576,12 +1563,7 @@ function unmountHostComponents(
1563 }
1564
1565 if (node.tag === HostComponent || node.tag === HostText) {
1579 - commitNestedUnmounts(
1580 - finishedRoot,
1581 - node,
1582 - nearestMountedAncestor,
1583 - renderPriorityLevel,
1584 - );
1566 + commitNestedUnmounts(finishedRoot, node, nearestMountedAncestor);
1567 // After all the children have unmounted, it is now safe to remove the
1568 // node from the tree.
1569 if (currentParentIsContainer) {
@@ -1634,12 +1616,7 @@ function unmountHostComponents(
1616 continue;
1617 }
1618 } else {
1637 - commitUnmount(
1638 - finishedRoot,
1639 - node,
1640 - nearestMountedAncestor,
1641 - renderPriorityLevel,
1642 - );
1619 + commitUnmount(finishedRoot, node, nearestMountedAncestor);
1620 // Visit children because we may find more host components below.
1621 if (node.child !== null) {
1622 node.child.return = node;
@@ -1670,25 +1647,14 @@ function commitDeletion(
1647 finishedRoot: FiberRoot,
1648 current: Fiber,
1649 nearestMountedAncestor: Fiber,
1673 - renderPriorityLevel: LanePriority,
1650 ): void {
1651 if (supportsMutation) {
1652 // Recursively delete all host nodes from the parent.
1653 // Detach refs and call componentWillUnmount() on the whole subtree.
1678 - unmountHostComponents(
1679 - finishedRoot,
1680 - current,
1681 - nearestMountedAncestor,
1682 - renderPriorityLevel,
1683 - );
1654 + unmountHostComponents(finishedRoot, current, nearestMountedAncestor);
1655 } else {
1656 // Detach refs and call componentWillUnmount() on the whole subtree.
1686 - commitNestedUnmounts(
1687 - finishedRoot,
1688 - current,
1689 - nearestMountedAncestor,
1690 - renderPriorityLevel,
1691 - );
1657 + commitNestedUnmounts(finishedRoot, current, nearestMountedAncestor);
1658 }
1659
1660 detachFiberMutation(current);
@@ -2009,19 +1975,12 @@ function commitResetTextContent(current: Fiber) {
1975 resetTextContent(current.stateNode);
1976 }
1977
2012 -export function commitMutationEffects(
2013 - root: FiberRoot,
2014 - renderPriorityLevel: LanePriority,
2015 - firstChild: Fiber,
2016 -) {
1978 +export function commitMutationEffects(root: FiberRoot, firstChild: Fiber) {
1979 nextEffect = firstChild;
2018 - commitMutationEffects_begin(root, renderPriorityLevel);
1980 + commitMutationEffects_begin(root);
1981 }
1982
2021 -function commitMutationEffects_begin(
2022 - root: FiberRoot,
2023 - renderPriorityLevel: LanePriority,
2024 -) {
1983 +function commitMutationEffects_begin(root: FiberRoot) {
1984 while (nextEffect !== null) {
1985 const fiber = nextEffect;
1986
@@ -2038,7 +1997,6 @@ function commitMutationEffects_begin(
1997 root,
1998 childToDelete,
1999 fiber,
2041 - renderPriorityLevel,
2000 );
2001 if (hasCaughtError()) {
2002 const error = clearCaughtError();
@@ -2046,7 +2004,7 @@ function commitMutationEffects_begin(
2004 }
2005 } else {
2006 try {
2049 - commitDeletion(root, childToDelete, fiber, renderPriorityLevel);
2007 + commitDeletion(root, childToDelete, fiber);
2008 } catch (error) {
2009 captureCommitPhaseError(childToDelete, fiber, error);
2010 }
@@ -2059,15 +2017,12 @@ function commitMutationEffects_begin(
2017 ensureCorrectReturnPointer(child, fiber);
2018 nextEffect = child;
2019 } else {
2062 - commitMutationEffects_complete(root, renderPriorityLevel);
2020 + commitMutationEffects_complete(root);
2021 }
2022 }
2023 }
2024
2067 -function commitMutationEffects_complete(
2068 - root: FiberRoot,
2069 - renderPriorityLevel: LanePriority,
2070 -) {
2025 +function commitMutationEffects_complete(root: FiberRoot) {
2026 while (nextEffect !== null) {
2027 const fiber = nextEffect;
2028 if (__DEV__) {
@@ -2078,7 +2033,6 @@ function commitMutationEffects_complete(
2033 null,
2034 fiber,
2035 root,
2081 - renderPriorityLevel,
2036 );
2037 if (hasCaughtError()) {
2038 const error = clearCaughtError();
@@ -2087,7 +2041,7 @@ function commitMutationEffects_complete(
2041 resetCurrentDebugFiberInDEV();
2042 } else {
2043 try {
2090 - commitMutationEffectsOnFiber(fiber, root, renderPriorityLevel);
2044 + commitMutationEffectsOnFiber(fiber, root);
2045 } catch (error) {
2046 captureCommitPhaseError(fiber, fiber.return, error);
2047 }
@@ -2104,11 +2058,7 @@ function commitMutationEffects_complete(
2058 }
2059 }
2060
2107 -function commitMutationEffectsOnFiber(
2108 - finishedWork: Fiber,
2109 - root: FiberRoot,
2110 - renderPriorityLevel: LanePriority,
2111 -) {
2061 +function commitMutationEffectsOnFiber(finishedWork: Fiber, root: FiberRoot) {
2062 const flags = finishedWork.flags;
2063
2064 if (flags & ContentReset) {
packages/react-reconciler/src/ReactFiberCommitWork.old.js
+15 -65
@@ -17,7 +17,7 @@ import type {
17 } from './ReactFiberHostConfig';
18 import type {Fiber} from './ReactInternalTypes';
19 import type {FiberRoot} from './ReactInternalTypes';
20 -import type {LanePriority, Lanes} from './ReactFiberLane.old';
20 +import type {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';
@@ -1067,7 +1067,6 @@ function commitUnmount(
1067 finishedRoot: FiberRoot,
1068 current: Fiber,
1069 nearestMountedAncestor: Fiber,
1070 - renderPriorityLevel: LanePriority,
1070 ): void {
1071 onCommitUnmount(current);
1072
@@ -1127,12 +1126,7 @@ function commitUnmount(
1126 // We are also not using this parent because
1127 // the portal will get pushed immediately.
1128 if (supportsMutation) {
1130 - unmountHostComponents(
1131 - finishedRoot,
1132 - current,
1133 - nearestMountedAncestor,
1134 - renderPriorityLevel,
1135 - );
1129 + unmountHostComponents(finishedRoot, current, nearestMountedAncestor);
1130 } else if (supportsPersistence) {
1131 emptyPortalContainer(current);
1132 }
@@ -1163,7 +1157,6 @@ function commitNestedUnmounts(
1157 finishedRoot: FiberRoot,
1158 root: Fiber,
1159 nearestMountedAncestor: Fiber,
1166 - renderPriorityLevel: LanePriority,
1160 ): void {
1161 // While we're inside a removed host node we don't want to call
1162 // removeChild on the inner nodes because they're removed by the top
@@ -1172,12 +1165,7 @@ function commitNestedUnmounts(
1165 // we do an inner loop while we're still inside the host node.
1166 let node: Fiber = root;
1167 while (true) {
1175 - commitUnmount(
1176 - finishedRoot,
1177 - node,
1178 - nearestMountedAncestor,
1179 - renderPriorityLevel,
1180 - );
1168 + commitUnmount(finishedRoot, node, nearestMountedAncestor);
1169 // Visit children because they may contain more composite or host nodes.
1170 // Skip portals because commitUnmount() currently visits them recursively.
1171 if (
@@ -1532,7 +1520,6 @@ function unmountHostComponents(
1520 finishedRoot: FiberRoot,
1521 current: Fiber,
1522 nearestMountedAncestor: Fiber,
1535 - renderPriorityLevel: LanePriority,
1523 ): void {
1524 // We only have the top Fiber that was deleted but we need to recurse down its
1525 // children to find all the terminal nodes.
@@ -1576,12 +1563,7 @@ function unmountHostComponents(
1563 }
1564
1565 if (node.tag === HostComponent || node.tag === HostText) {
1579 - commitNestedUnmounts(
1580 - finishedRoot,
1581 - node,
1582 - nearestMountedAncestor,
1583 - renderPriorityLevel,
1584 - );
1566 + commitNestedUnmounts(finishedRoot, node, nearestMountedAncestor);
1567 // After all the children have unmounted, it is now safe to remove the
1568 // node from the tree.
1569 if (currentParentIsContainer) {
@@ -1634,12 +1616,7 @@ function unmountHostComponents(
1616 continue;
1617 }
1618 } else {
1637 - commitUnmount(
1638 - finishedRoot,
1639 - node,
1640 - nearestMountedAncestor,
1641 - renderPriorityLevel,
1642 - );
1619 + commitUnmount(finishedRoot, node, nearestMountedAncestor);
1620 // Visit children because we may find more host components below.
1621 if (node.child !== null) {
1622 node.child.return = node;
@@ -1670,25 +1647,14 @@ function commitDeletion(
1647 finishedRoot: FiberRoot,
1648 current: Fiber,
1649 nearestMountedAncestor: Fiber,
1673 - renderPriorityLevel: LanePriority,
1650 ): void {
1651 if (supportsMutation) {
1652 // Recursively delete all host nodes from the parent.
1653 // Detach refs and call componentWillUnmount() on the whole subtree.
1678 - unmountHostComponents(
1679 - finishedRoot,
1680 - current,
1681 - nearestMountedAncestor,
1682 - renderPriorityLevel,
1683 - );
1654 + unmountHostComponents(finishedRoot, current, nearestMountedAncestor);
1655 } else {
1656 // Detach refs and call componentWillUnmount() on the whole subtree.
1686 - commitNestedUnmounts(
1687 - finishedRoot,
1688 - current,
1689 - nearestMountedAncestor,
1690 - renderPriorityLevel,
1691 - );
1657 + commitNestedUnmounts(finishedRoot, current, nearestMountedAncestor);
1658 }
1659
1660 detachFiberMutation(current);
@@ -2009,19 +1975,12 @@ function commitResetTextContent(current: Fiber) {
1975 resetTextContent(current.stateNode);
1976 }
1977
2012 -export function commitMutationEffects(
2013 - root: FiberRoot,
2014 - renderPriorityLevel: LanePriority,
2015 - firstChild: Fiber,
2016 -) {
1978 +export function commitMutationEffects(root: FiberRoot, firstChild: Fiber) {
1979 nextEffect = firstChild;
2018 - commitMutationEffects_begin(root, renderPriorityLevel);
1980 + commitMutationEffects_begin(root);
1981 }
1982
2021 -function commitMutationEffects_begin(
2022 - root: FiberRoot,
2023 - renderPriorityLevel: LanePriority,
2024 -) {
1983 +function commitMutationEffects_begin(root: FiberRoot) {
1984 while (nextEffect !== null) {
1985 const fiber = nextEffect;
1986
@@ -2038,7 +1997,6 @@ function commitMutationEffects_begin(
1997 root,
1998 childToDelete,
1999 fiber,
2041 - renderPriorityLevel,
2000 );
2001 if (hasCaughtError()) {
2002 const error = clearCaughtError();
@@ -2046,7 +2004,7 @@ function commitMutationEffects_begin(
2004 }
2005 } else {
2006 try {
2049 - commitDeletion(root, childToDelete, fiber, renderPriorityLevel);
2007 + commitDeletion(root, childToDelete, fiber);
2008 } catch (error) {
2009 captureCommitPhaseError(childToDelete, fiber, error);
2010 }
@@ -2059,15 +2017,12 @@ function commitMutationEffects_begin(
2017 ensureCorrectReturnPointer(child, fiber);
2018 nextEffect = child;
2019 } else {
2062 - commitMutationEffects_complete(root, renderPriorityLevel);
2020 + commitMutationEffects_complete(root);
2021 }
2022 }
2023 }
2024
2067 -function commitMutationEffects_complete(
2068 - root: FiberRoot,
2069 - renderPriorityLevel: LanePriority,
2070 -) {
2025 +function commitMutationEffects_complete(root: FiberRoot) {
2026 while (nextEffect !== null) {
2027 const fiber = nextEffect;
2028 if (__DEV__) {
@@ -2078,7 +2033,6 @@ function commitMutationEffects_complete(
2033 null,
2034 fiber,
2035 root,
2081 - renderPriorityLevel,
2036 );
2037 if (hasCaughtError()) {
2038 const error = clearCaughtError();
@@ -2087,7 +2041,7 @@ function commitMutationEffects_complete(
2041 resetCurrentDebugFiberInDEV();
2042 } else {
2043 try {
2090 - commitMutationEffectsOnFiber(fiber, root, renderPriorityLevel);
2044 + commitMutationEffectsOnFiber(fiber, root);
2045 } catch (error) {
2046 captureCommitPhaseError(fiber, fiber.return, error);
2047 }
@@ -2104,11 +2058,7 @@ function commitMutationEffects_complete(
2058 }
2059 }
2060
2107 -function commitMutationEffectsOnFiber(
2108 - finishedWork: Fiber,
2109 - root: FiberRoot,
2110 - renderPriorityLevel: LanePriority,
2111 -) {
2061 +function commitMutationEffectsOnFiber(finishedWork: Fiber, root: FiberRoot) {
2062 const flags = finishedWork.flags;
2063
2064 if (flags & ContentReset) {
packages/react-reconciler/src/ReactFiberDevToolsHook.new.js
+31 -10
@@ -11,14 +11,21 @@ import {enableProfilerTimer} from 'shared/ReactFeatureFlags';
11
12 import type {Fiber, FiberRoot} from './ReactInternalTypes';
13 import type {ReactNodeList} from 'shared/ReactTypes';
14 -import type {LanePriority} from './ReactFiberLane.new';
14 +import type {EventPriority} from './ReactEventPriorities.new';
15
16 import {DidCapture} from './ReactFiberFlags';
17 import {
18 - lanePriorityToSchedulerPriority,
19 - NoLanePriority,
20 -} from './ReactFiberLane.new';
21 -import {NormalPriority} from './SchedulerWithReactIntegration.new';
18 + DiscreteEventPriority,
19 + ContinuousEventPriority,
20 + DefaultEventPriority,
21 + IdleEventPriority,
22 +} from './ReactEventPriorities.new';
23 +import {
24 + ImmediatePriority as ImmediateSchedulerPriority,
25 + UserBlockingPriority as UserBlockingSchedulerPriority,
26 + NormalPriority as NormalSchedulerPriority,
27 + IdlePriority as IdleSchedulerPriority,
28 +} from './SchedulerWithReactIntegration.new';
29
30 declare var __REACT_DEVTOOLS_GLOBAL_HOOK__: Object | void;
31
@@ -84,15 +91,29 @@ export function onScheduleRoot(root: FiberRoot, children: ReactNodeList) {
91 }
92 }
93
87 -export function onCommitRoot(root: FiberRoot, priorityLevel: LanePriority) {
94 +export function onCommitRoot(root: FiberRoot, eventPriority: EventPriority) {
95 if (injectedHook && typeof injectedHook.onCommitFiberRoot === 'function') {
96 try {
97 const didError = (root.current.flags & DidCapture) === DidCapture;
98 if (enableProfilerTimer) {
92 - const schedulerPriority =
93 - priorityLevel === NoLanePriority
94 - ? NormalPriority
95 - : lanePriorityToSchedulerPriority(priorityLevel);
99 + let schedulerPriority;
100 + switch (eventPriority) {
101 + case DiscreteEventPriority:
102 + schedulerPriority = ImmediateSchedulerPriority;
103 + break;
104 + case ContinuousEventPriority:
105 + schedulerPriority = UserBlockingSchedulerPriority;
106 + break;
107 + case DefaultEventPriority:
108 + schedulerPriority = NormalSchedulerPriority;
109 + break;
110 + case IdleEventPriority:
111 + schedulerPriority = IdleSchedulerPriority;
112 + break;
113 + default:
114 + schedulerPriority = NormalSchedulerPriority;
115 + break;
116 + }
117 injectedHook.onCommitFiberRoot(
118 rendererID,
119 root,
packages/react-reconciler/src/ReactFiberDevToolsHook.old.js
+31 -10
@@ -11,14 +11,21 @@ import {enableProfilerTimer} from 'shared/ReactFeatureFlags';
11
12 import type {Fiber, FiberRoot} from './ReactInternalTypes';
13 import type {ReactNodeList} from 'shared/ReactTypes';
14 -import type {LanePriority} from './ReactFiberLane.old';
14 +import type {EventPriority} from './ReactEventPriorities.old';
15
16 import {DidCapture} from './ReactFiberFlags';
17 import {
18 - lanePriorityToSchedulerPriority,
19 - NoLanePriority,
20 -} from './ReactFiberLane.old';
21 -import {NormalPriority} from './SchedulerWithReactIntegration.old';
18 + DiscreteEventPriority,
19 + ContinuousEventPriority,
20 + DefaultEventPriority,
21 + IdleEventPriority,
22 +} from './ReactEventPriorities.old';
23 +import {
24 + ImmediatePriority as ImmediateSchedulerPriority,
25 + UserBlockingPriority as UserBlockingSchedulerPriority,
26 + NormalPriority as NormalSchedulerPriority,
27 + IdlePriority as IdleSchedulerPriority,
28 +} from './SchedulerWithReactIntegration.old';
29
30 declare var __REACT_DEVTOOLS_GLOBAL_HOOK__: Object | void;
31
@@ -84,15 +91,29 @@ export function onScheduleRoot(root: FiberRoot, children: ReactNodeList) {
91 }
92 }
93
87 -export function onCommitRoot(root: FiberRoot, priorityLevel: LanePriority) {
94 +export function onCommitRoot(root: FiberRoot, eventPriority: EventPriority) {
95 if (injectedHook && typeof injectedHook.onCommitFiberRoot === 'function') {
96 try {
97 const didError = (root.current.flags & DidCapture) === DidCapture;
98 if (enableProfilerTimer) {
92 - const schedulerPriority =
93 - priorityLevel === NoLanePriority
94 - ? NormalPriority
95 - : lanePriorityToSchedulerPriority(priorityLevel);
99 + let schedulerPriority;
100 + switch (eventPriority) {
101 + case DiscreteEventPriority:
102 + schedulerPriority = ImmediateSchedulerPriority;
103 + break;
104 + case ContinuousEventPriority:
105 + schedulerPriority = UserBlockingSchedulerPriority;
106 + break;
107 + case DefaultEventPriority:
108 + schedulerPriority = NormalSchedulerPriority;
109 + break;
110 + case IdleEventPriority:
111 + schedulerPriority = IdleSchedulerPriority;
112 + break;
113 + default:
114 + schedulerPriority = NormalSchedulerPriority;
115 + break;
116 + }
117 injectedHook.onCommitFiberRoot(
118 rendererID,
119 root,
packages/react-reconciler/src/ReactFiberHooks.new.js
+12 -10
@@ -41,7 +41,6 @@ import {
41 import {
42 NoLane,
43 NoLanes,
44 - InputContinuousLanePriority,
44 isSubsetOfLanes,
45 mergeLanes,
46 removeLanes,
@@ -49,11 +48,14 @@ import {
48 isTransitionLane,
49 markRootEntangled,
50 markRootMutableRead,
52 - getCurrentUpdateLanePriority,
53 - setCurrentUpdateLanePriority,
54 - higherLanePriority,
55 - DefaultLanePriority,
51 } from './ReactFiberLane.new';
52 +import {
53 + DefaultEventPriority,
54 + ContinuousEventPriority,
55 + getCurrentUpdatePriority,
56 + setCurrentUpdatePriority,
57 + higherEventPriority,
58 +} from './ReactEventPriorities.new';
59 import {readContext, checkIfContextChanged} from './ReactFiberNewContext.new';
60 import {HostRoot, CacheComponent} from './ReactWorkTags';
61 import {
@@ -1705,9 +1707,9 @@ function rerenderDeferredValue<T>(value: T): T {
1707 }
1708
1709 function startTransition(setPending, callback) {
1708 - const previousLanePriority = getCurrentUpdateLanePriority();
1709 - setCurrentUpdateLanePriority(
1710 - higherLanePriority(previousLanePriority, InputContinuousLanePriority),
1710 + const previousPriority = getCurrentUpdatePriority();
1711 + setCurrentUpdatePriority(
1712 + higherEventPriority(previousPriority, ContinuousEventPriority),
1713 );
1714
1715 setPending(true);
@@ -1715,7 +1717,7 @@ function startTransition(setPending, callback) {
1717 // TODO: Can remove this. Was only necessary because we used to give
1718 // different behavior to transitions without a config object. Now they are
1719 // all treated the same.
1718 - setCurrentUpdateLanePriority(DefaultLanePriority);
1720 + setCurrentUpdatePriority(DefaultEventPriority);
1721
1722 const prevTransition = ReactCurrentBatchConfig.transition;
1723 ReactCurrentBatchConfig.transition = 1;
@@ -1723,7 +1725,7 @@ function startTransition(setPending, callback) {
1725 setPending(false);
1726 callback();
1727 } finally {
1726 - setCurrentUpdateLanePriority(previousLanePriority);
1728 + setCurrentUpdatePriority(previousPriority);
1729 ReactCurrentBatchConfig.transition = prevTransition;
1730 }
1731 }
packages/react-reconciler/src/ReactFiberHooks.old.js
+12 -10
@@ -41,7 +41,6 @@ import {
41 import {
42 NoLane,
43 NoLanes,
44 - InputContinuousLanePriority,
44 isSubsetOfLanes,
45 mergeLanes,
46 removeLanes,
@@ -49,11 +48,14 @@ import {
48 isTransitionLane,
49 markRootEntangled,
50 markRootMutableRead,
52 - getCurrentUpdateLanePriority,
53 - setCurrentUpdateLanePriority,
54 - higherLanePriority,
55 - DefaultLanePriority,
51 } from './ReactFiberLane.old';
52 +import {
53 + DefaultEventPriority,
54 + ContinuousEventPriority,
55 + getCurrentUpdatePriority,
56 + setCurrentUpdatePriority,
57 + higherEventPriority,
58 +} from './ReactEventPriorities.old';
59 import {readContext, checkIfContextChanged} from './ReactFiberNewContext.old';
60 import {HostRoot, CacheComponent} from './ReactWorkTags';
61 import {
@@ -1705,9 +1707,9 @@ function rerenderDeferredValue<T>(value: T): T {
1707 }
1708
1709 function startTransition(setPending, callback) {
1708 - const previousLanePriority = getCurrentUpdateLanePriority();
1709 - setCurrentUpdateLanePriority(
1710 - higherLanePriority(previousLanePriority, InputContinuousLanePriority),
1710 + const previousPriority = getCurrentUpdatePriority();
1711 + setCurrentUpdatePriority(
1712 + higherEventPriority(previousPriority, ContinuousEventPriority),
1713 );
1714
1715 setPending(true);
@@ -1715,7 +1717,7 @@ function startTransition(setPending, callback) {
1717 // TODO: Can remove this. Was only necessary because we used to give
1718 // different behavior to transitions without a config object. Now they are
1719 // all treated the same.
1718 - setCurrentUpdateLanePriority(DefaultLanePriority);
1720 + setCurrentUpdatePriority(DefaultEventPriority);
1721
1722 const prevTransition = ReactCurrentBatchConfig.transition;
1723 ReactCurrentBatchConfig.transition = 1;
@@ -1723,7 +1725,7 @@ function startTransition(setPending, callback) {
1725 setPending(false);
1726 callback();
1727 } finally {
1726 - setCurrentUpdateLanePriority(previousLanePriority);
1728 + setCurrentUpdatePriority(previousPriority);
1729 ReactCurrentBatchConfig.transition = prevTransition;
1730 }
1731 }
packages/react-reconciler/src/ReactFiberLane.new.js
+3 -42
@@ -73,8 +73,8 @@ export const NoLanePriority: LanePriority = 0;
73
74 export const TotalLanes = 31;
75
76 -export const NoLanes: Lanes = /* */ 0b000000000000000000000000000000;
77 -export const NoLane: Lane = /* */ 0b000000000000000000000000000000;
76 +export const NoLanes: Lanes = /* */ 0b0000000000000000000000000000000;
77 +export const NoLane: Lane = /* */ 0b0000000000000000000000000000000;
78
79 export const SyncLane: Lane = /* */ 0b0000000000000000000000000000001;
80
@@ -168,19 +168,9 @@ export function getLabelsForLanes(lanes: Lanes): Array<string> | void {
168
169 export const NoTimestamp = -1;
170
171 -let currentUpdateLanePriority: LanePriority = NoLanePriority;
172 -
171 let nextTransitionLane: Lane = TransitionLane1;
172 let nextRetryLane: Lane = RetryLane1;
173
176 -export function getCurrentUpdateLanePriority(): LanePriority {
177 - return currentUpdateLanePriority;
178 -}
179 -
180 -export function setCurrentUpdateLanePriority(newLanePriority: LanePriority) {
181 - currentUpdateLanePriority = newLanePriority;
182 -}
183 -
174 // "Registers" used to "return" multiple values
175 // Used by getHighestPriorityLanes and getNextLanes:
176 let return_highestLanePriority: LanePriority = DefaultLanePriority;
@@ -532,35 +522,6 @@ export function isTransitionLane(lane: Lane) {
522 return (lane & TransitionLanes) !== 0;
523 }
524
535 -// To ensure consistency across multiple updates in the same event, this should
536 -// be a pure function, so that it always returns the same lane for given inputs.
537 -export function findUpdateLane(lanePriority: LanePriority): Lane {
538 - switch (lanePriority) {
539 - case NoLanePriority:
540 - break;
541 - case SyncLanePriority:
542 - return SyncLane;
543 - case InputContinuousLanePriority:
544 - return InputContinuousLane;
545 - case DefaultLanePriority:
546 - return DefaultLane;
547 - case TransitionPriority: // Should be handled by findTransitionLane instead
548 - case RetryLanePriority: // Should be handled by findRetryLane instead
549 - break;
550 - case IdleLanePriority:
551 - return IdleLane;
552 - default:
553 - // The remaining priorities are not valid for updates
554 - break;
555 - }
556 -
557 - invariant(
558 - false,
559 - 'Invalid update priority: %s. This is a bug in React.',
560 - lanePriority,
561 - );
562 -}
563 -
525 export function claimNextTransitionLane(): Lane {
526 // Cycle through the lanes, assigning each new transition to the next lane.
527 // In most cases, this means every transition gets its own lane, until we
@@ -582,7 +543,7 @@ export function claimNextRetryLane(): Lane {
543 return lane;
544 }
545
585 -function getHighestPriorityLane(lanes: Lanes) {
546 +export function getHighestPriorityLane(lanes: Lanes): Lane {
547 return lanes & -lanes;
548 }
549
packages/react-reconciler/src/ReactFiberLane.old.js
+3 -42
@@ -73,8 +73,8 @@ export const NoLanePriority: LanePriority = 0;
73
74 export const TotalLanes = 31;
75
76 -export const NoLanes: Lanes = /* */ 0b000000000000000000000000000000;
77 -export const NoLane: Lane = /* */ 0b000000000000000000000000000000;
76 +export const NoLanes: Lanes = /* */ 0b0000000000000000000000000000000;
77 +export const NoLane: Lane = /* */ 0b0000000000000000000000000000000;
78
79 export const SyncLane: Lane = /* */ 0b0000000000000000000000000000001;
80
@@ -168,19 +168,9 @@ export function getLabelsForLanes(lanes: Lanes): Array<string> | void {
168
169 export const NoTimestamp = -1;
170
171 -let currentUpdateLanePriority: LanePriority = NoLanePriority;
172 -
171 let nextTransitionLane: Lane = TransitionLane1;
172 let nextRetryLane: Lane = RetryLane1;
173
176 -export function getCurrentUpdateLanePriority(): LanePriority {
177 - return currentUpdateLanePriority;
178 -}
179 -
180 -export function setCurrentUpdateLanePriority(newLanePriority: LanePriority) {
181 - currentUpdateLanePriority = newLanePriority;
182 -}
183 -
174 // "Registers" used to "return" multiple values
175 // Used by getHighestPriorityLanes and getNextLanes:
176 let return_highestLanePriority: LanePriority = DefaultLanePriority;
@@ -532,35 +522,6 @@ export function isTransitionLane(lane: Lane) {
522 return (lane & TransitionLanes) !== 0;
523 }
524
535 -// To ensure consistency across multiple updates in the same event, this should
536 -// be a pure function, so that it always returns the same lane for given inputs.
537 -export function findUpdateLane(lanePriority: LanePriority): Lane {
538 - switch (lanePriority) {
539 - case NoLanePriority:
540 - break;
541 - case SyncLanePriority:
542 - return SyncLane;
543 - case InputContinuousLanePriority:
544 - return InputContinuousLane;
545 - case DefaultLanePriority:
546 - return DefaultLane;
547 - case TransitionPriority: // Should be handled by findTransitionLane instead
548 - case RetryLanePriority: // Should be handled by findRetryLane instead
549 - break;
550 - case IdleLanePriority:
551 - return IdleLane;
552 - default:
553 - // The remaining priorities are not valid for updates
554 - break;
555 - }
556 -
557 - invariant(
558 - false,
559 - 'Invalid update priority: %s. This is a bug in React.',
560 - lanePriority,
561 - );
562 -}
563 -
525 export function claimNextTransitionLane(): Lane {
526 // Cycle through the lanes, assigning each new transition to the next lane.
527 // In most cases, this means every transition gets its own lane, until we
@@ -582,7 +543,7 @@ export function claimNextRetryLane(): Lane {
543 return lane;
544 }
545
585 -function getHighestPriorityLane(lanes: Lanes) {
546 +export function getHighestPriorityLane(lanes: Lanes): Lane {
547 return lanes & -lanes;
548 }
549
packages/react-reconciler/src/ReactFiberReconciler.js
+5 -5
@@ -51,7 +51,7 @@ import {
51 observeVisibleRects as observeVisibleRects_old,
52 registerMutableSourceForHydration as registerMutableSourceForHydration_old,
53 runWithPriority as runWithPriority_old,
54 - getCurrentUpdateLanePriority as getCurrentUpdateLanePriority_old,
54 + getCurrentUpdatePriority as getCurrentUpdatePriority_old,
55 } from './ReactFiberReconciler.old';
56
57 import {
@@ -91,7 +91,7 @@ import {
91 observeVisibleRects as observeVisibleRects_new,
92 registerMutableSourceForHydration as registerMutableSourceForHydration_new,
93 runWithPriority as runWithPriority_new,
94 - getCurrentUpdateLanePriority as getCurrentUpdateLanePriority_new,
94 + getCurrentUpdatePriority as getCurrentUpdatePriority_new,
95 } from './ReactFiberReconciler.new';
96
97 export const createContainer = enableNewReconciler
@@ -143,9 +143,9 @@ export const attemptContinuousHydration = enableNewReconciler
143 export const attemptHydrationAtCurrentPriority = enableNewReconciler
144 ? attemptHydrationAtCurrentPriority_new
145 : attemptHydrationAtCurrentPriority_old;
146 -export const getCurrentUpdateLanePriority = enableNewReconciler
147 - ? getCurrentUpdateLanePriority_new
148 - : getCurrentUpdateLanePriority_old;
146 +export const getCurrentUpdatePriority = enableNewReconciler
147 + ? getCurrentUpdatePriority_new
148 + : getCurrentUpdatePriority_old;
149 export const findHostInstance = enableNewReconciler
150 ? findHostInstance_new
151 : findHostInstance_old;
packages/react-reconciler/src/ReactFiberReconciler.new.js
+6 -14
@@ -18,7 +18,7 @@ import type {
18 } from './ReactFiberHostConfig';
19 import type {RendererInspectionConfig} from './ReactFiberHostConfig';
20 import type {ReactNodeList} from 'shared/ReactTypes';
21 -import type {Lane, LanePriority} from './ReactFiberLane.new';
21 +import type {Lane} from './ReactFiberLane.new';
22 import type {SuspenseState} from './ReactFiberSuspenseComponent.new';
23
24 import {
@@ -82,9 +82,11 @@ import {
82 NoTimestamp,
83 getHighestPriorityPendingLanes,
84 higherPriorityLane,
85 - getCurrentUpdateLanePriority,
86 - setCurrentUpdateLanePriority,
85 } from './ReactFiberLane.new';
86 +import {
87 + getCurrentUpdatePriority,
88 + runWithPriority,
89 +} from './ReactEventPriorities.new';
90 import {
91 scheduleRefresh,
92 scheduleRoot,
@@ -442,17 +444,7 @@ export function attemptHydrationAtCurrentPriority(fiber: Fiber): void {
444 markRetryLaneIfNotHydrated(fiber, lane);
445 }
446
445 -export function runWithPriority<T>(priority: LanePriority, fn: () => T) {
446 - const previousPriority = getCurrentUpdateLanePriority();
447 - try {
448 - setCurrentUpdateLanePriority(priority);
449 - return fn();
450 - } finally {
451 - setCurrentUpdateLanePriority(previousPriority);
452 - }
453 -}
454 -
455 -export {getCurrentUpdateLanePriority};
447 +export {getCurrentUpdatePriority, runWithPriority};
448
449 export {findHostInstance};
450
packages/react-reconciler/src/ReactFiberReconciler.old.js
+6 -14
@@ -18,7 +18,7 @@ import type {
18 } from './ReactFiberHostConfig';
19 import type {RendererInspectionConfig} from './ReactFiberHostConfig';
20 import type {ReactNodeList} from 'shared/ReactTypes';
21 -import type {Lane, LanePriority} from './ReactFiberLane.old';
21 +import type {Lane} from './ReactFiberLane.old';
22 import type {SuspenseState} from './ReactFiberSuspenseComponent.old';
23
24 import {
@@ -82,9 +82,11 @@ import {
82 NoTimestamp,
83 getHighestPriorityPendingLanes,
84 higherPriorityLane,
85 - getCurrentUpdateLanePriority,
86 - setCurrentUpdateLanePriority,
85 } from './ReactFiberLane.old';
86 +import {
87 + getCurrentUpdatePriority,
88 + runWithPriority,
89 +} from './ReactEventPriorities.old';
90 import {
91 scheduleRefresh,
92 scheduleRoot,
@@ -442,17 +444,7 @@ export function attemptHydrationAtCurrentPriority(fiber: Fiber): void {
444 markRetryLaneIfNotHydrated(fiber, lane);
445 }
446
445 -export function runWithPriority<T>(priority: LanePriority, fn: () => T) {
446 - const previousPriority = getCurrentUpdateLanePriority();
447 - try {
448 - setCurrentUpdateLanePriority(priority);
449 - return fn();
450 - } finally {
451 - setCurrentUpdateLanePriority(previousPriority);
452 - }
453 -}
454 -
455 -export {getCurrentUpdateLanePriority};
447 +export {getCurrentUpdatePriority, runWithPriority};
448
449 export {findHostInstance};
450
packages/react-reconciler/src/ReactFiberWorkLoop.new.js
+48 -45
@@ -9,7 +9,7 @@
9
10 import type {Thenable, Wakeable} from 'shared/ReactTypes';
11 import type {Fiber, FiberRoot} from './ReactInternalTypes';
12 -import type {Lanes, Lane, LanePriority} from './ReactFiberLane.new';
12 +import type {Lanes, Lane} 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';
@@ -132,12 +132,10 @@ import {
132 import {
133 NoLanePriority,
134 SyncLanePriority,
135 - DefaultLanePriority,
135 NoLanes,
136 NoLane,
137 SyncLane,
138 NoTimestamp,
140 - findUpdateLane,
139 claimNextTransitionLane,
140 claimNextRetryLane,
141 includesSomeLane,
@@ -150,8 +148,6 @@ import {
148 includesOnlyTransitions,
149 getNextLanes,
150 returnNextLanesPriority,
153 - setCurrentUpdateLanePriority,
154 - getCurrentUpdateLanePriority,
151 markStarvedLanesAsExpired,
152 getLanesToRetrySynchronouslyOnError,
153 getMostRecentEventTime,
@@ -162,6 +158,14 @@ import {
158 markRootFinished,
159 lanePriorityToSchedulerPriority,
160 } from './ReactFiberLane.new';
161 +import {
162 + DiscreteEventPriority,
163 + DefaultEventPriority,
164 + getCurrentUpdatePriority,
165 + setCurrentUpdatePriority,
166 + higherEventPriority,
167 + lanesToEventPriority,
168 +} from './ReactEventPriorities.new';
169 import {requestCurrentTransition, NoTransition} from './ReactFiberTransition';
170 import {beginWork as originalBeginWork} from './ReactFiberBeginWork.new';
171 import {completeWork} from './ReactFiberCompleteWork.new';
@@ -320,7 +324,6 @@ let rootCommittingMutationOrLayoutEffects: FiberRoot | null = null;
324
325 let rootDoesHavePassiveEffects: boolean = false;
326 let rootWithPendingPassiveEffects: FiberRoot | null = null;
323 -let pendingPassiveEffectsRenderPriority: LanePriority = NoLanePriority;
327 let pendingPassiveEffectsLanes: Lanes = NoLanes;
328 let pendingPassiveProfilerEffects: Array<Fiber> = [];
329
@@ -423,9 +426,13 @@ export function requestUpdateLane(fiber: Fiber): Lane {
426
427 // Updates originating inside certain React methods, like flushSync, have
428 // their priority set by tracking it with a context variable.
426 - const updateLanePriority = getCurrentUpdateLanePriority();
427 - if (updateLanePriority !== NoLanePriority) {
428 - return findUpdateLane(updateLanePriority);
429 + //
430 + // The opaque type returned by the host config is internally a lane, so we can
431 + // use that directly.
432 + // TODO: Move this type conversion to the event priority module.
433 + const updateLane: Lane = (getCurrentUpdatePriority(): any);
434 + if (updateLane !== NoLane) {
435 + return updateLane;
436 }
437
438 // This update originated outside React. Ask the host environement for an
@@ -433,7 +440,8 @@ export function requestUpdateLane(fiber: Fiber): Lane {
440 //
441 // The opaque type returned by the host config is internally a lane, so we can
442 // use that directly.
436 - const eventLane = getCurrentEventPriority();
443 + // TODO: Move this type conversion to the event priority module.
444 + const eventLane: Lane = (getCurrentEventPriority(): any);
445 return eventLane;
446 }
447
@@ -1056,12 +1064,12 @@ export function flushDiscreteUpdates() {
1064 }
1065
1066 export function deferredUpdates<A>(fn: () => A): A {
1059 - const previousLanePriority = getCurrentUpdateLanePriority();
1067 + const previousPriority = getCurrentUpdatePriority();
1068 try {
1061 - setCurrentUpdateLanePriority(DefaultLanePriority);
1069 + setCurrentUpdatePriority(DefaultEventPriority);
1070 return fn();
1071 } finally {
1064 - setCurrentUpdateLanePriority(previousLanePriority);
1072 + setCurrentUpdatePriority(previousPriority);
1073 }
1074 }
1075
@@ -1102,12 +1110,12 @@ export function discreteUpdates<A, B, C, D, R>(
1110 c: C,
1111 d: D,
1112 ): R {
1105 - const previousLanePriority = getCurrentUpdateLanePriority();
1113 + const previousPriority = getCurrentUpdatePriority();
1114 try {
1107 - setCurrentUpdateLanePriority(SyncLanePriority);
1115 + setCurrentUpdatePriority(DiscreteEventPriority);
1116 return fn(a, b, c, d);
1117 } finally {
1110 - setCurrentUpdateLanePriority(previousLanePriority);
1118 + setCurrentUpdatePriority(previousPriority);
1119 if (executionContext === NoContext) {
1120 // Flush the immediate callbacks that were scheduled during this batch
1121 resetRenderTimer();
@@ -1146,16 +1154,16 @@ export function flushSync<A, R>(fn: A => R, a: A): R {
1154 }
1155 executionContext |= BatchedContext;
1156
1149 - const previousLanePriority = getCurrentUpdateLanePriority();
1157 + const previousPriority = getCurrentUpdatePriority();
1158 try {
1151 - setCurrentUpdateLanePriority(SyncLanePriority);
1159 + setCurrentUpdatePriority(DiscreteEventPriority);
1160 if (fn) {
1161 return fn(a);
1162 } else {
1163 return (undefined: $FlowFixMe);
1164 }
1165 } finally {
1158 - setCurrentUpdateLanePriority(previousLanePriority);
1166 + setCurrentUpdatePriority(previousPriority);
1167 executionContext = prevExecutionContext;
1168 // Flush the immediate callbacks that were scheduled during this batch.
1169 // Note that this will happen even if batchedUpdates is higher up
@@ -1167,12 +1175,12 @@ export function flushSync<A, R>(fn: A => R, a: A): R {
1175 export function flushControlled(fn: () => mixed): void {
1176 const prevExecutionContext = executionContext;
1177 executionContext |= BatchedContext;
1170 - const previousLanePriority = getCurrentUpdateLanePriority();
1178 + const previousPriority = getCurrentUpdatePriority();
1179 try {
1172 - setCurrentUpdateLanePriority(SyncLanePriority);
1180 + setCurrentUpdatePriority(DiscreteEventPriority);
1181 fn();
1182 } finally {
1175 - setCurrentUpdateLanePriority(previousLanePriority);
1183 + setCurrentUpdatePriority(previousPriority);
1184
1185 executionContext = prevExecutionContext;
1186 if (executionContext === NoContext) {
@@ -1663,12 +1671,14 @@ function completeUnitOfWork(unitOfWork: Fiber): void {
1671 }
1672
1673 function commitRoot(root) {
1666 - const previousUpdateLanePriority = getCurrentUpdateLanePriority();
1674 + // TODO: This no longer makes any sense. We already wrap the mutation and
1675 + // layout phases. Should be able to remove.
1676 + const previousUpdateLanePriority = getCurrentUpdatePriority();
1677 try {
1668 - setCurrentUpdateLanePriority(SyncLanePriority);
1678 + setCurrentUpdatePriority(DiscreteEventPriority);
1679 commitRootImpl(root, previousUpdateLanePriority);
1680 } finally {
1671 - setCurrentUpdateLanePriority(previousUpdateLanePriority);
1681 + setCurrentUpdatePriority(previousUpdateLanePriority);
1682 }
1683
1684 return null;
@@ -1780,8 +1790,8 @@ function commitRootImpl(root, renderPriorityLevel) {
1790 NoFlags;
1791
1792 if (subtreeHasEffects || rootHasEffect) {
1783 - const previousLanePriority = getCurrentUpdateLanePriority();
1784 - setCurrentUpdateLanePriority(SyncLanePriority);
1793 + const previousPriority = getCurrentUpdatePriority();
1794 + setCurrentUpdatePriority(DiscreteEventPriority);
1795
1796 const prevExecutionContext = executionContext;
1797 executionContext |= CommitContext;
@@ -1815,7 +1825,7 @@ function commitRootImpl(root, renderPriorityLevel) {
1825 }
1826
1827 // The next phase is the mutation phase, where we mutate the host tree.
1818 - commitMutationEffects(root, renderPriorityLevel, finishedWork);
1828 + commitMutationEffects(root, finishedWork);
1829
1830 if (shouldFireAfterActiveInstanceBlur) {
1831 afterActiveInstanceBlur();
@@ -1863,10 +1873,8 @@ function commitRootImpl(root, renderPriorityLevel) {
1873 }
1874 executionContext = prevExecutionContext;
1875
1866 - if (previousLanePriority != null) {
1867 - // Reset the priority to the previous non-sync value.
1868 - setCurrentUpdateLanePriority(previousLanePriority);
1869 - }
1876 + // Reset the priority to the previous non-sync value.
1877 + setCurrentUpdatePriority(previousPriority);
1878 } else {
1879 // No effects.
1880 root.current = finishedWork;
@@ -1886,10 +1894,6 @@ function commitRootImpl(root, renderPriorityLevel) {
1894 rootDoesHavePassiveEffects = false;
1895 rootWithPendingPassiveEffects = root;
1896 pendingPassiveEffectsLanes = lanes;
1889 - pendingPassiveEffectsRenderPriority =
1890 - renderPriorityLevel === NoLanePriority
1891 - ? DefaultLanePriority
1892 - : renderPriorityLevel;
1897 }
1898
1899 // Read this again, since an effect might have updated it
@@ -2003,18 +2007,17 @@ function commitRootImpl(root, renderPriorityLevel) {
2007
2008 export function flushPassiveEffects(): boolean {
2009 // Returns whether passive effects were flushed.
2006 - if (pendingPassiveEffectsRenderPriority !== NoLanePriority) {
2007 - const priorityLevel =
2008 - pendingPassiveEffectsRenderPriority > DefaultLanePriority
2009 - ? DefaultLanePriority
2010 - : pendingPassiveEffectsRenderPriority;
2011 - pendingPassiveEffectsRenderPriority = NoLanePriority;
2012 - const previousLanePriority = getCurrentUpdateLanePriority();
2010 + if (pendingPassiveEffectsLanes !== NoLanes) {
2011 + const priority = higherEventPriority(
2012 + DefaultEventPriority,
2013 + lanesToEventPriority(pendingPassiveEffectsLanes),
2014 + );
2015 + const previousPriority = getCurrentUpdatePriority();
2016 try {
2014 - setCurrentUpdateLanePriority(priorityLevel);
2017 + setCurrentUpdatePriority(priority);
2018 return flushPassiveEffectsImpl();
2019 } finally {
2017 - setCurrentUpdateLanePriority(previousLanePriority);
2020 + setCurrentUpdatePriority(previousPriority);
2021 }
2022 }
2023 return false;
packages/react-reconciler/src/ReactFiberWorkLoop.old.js
+48 -45
@@ -9,7 +9,7 @@
9
10 import type {Thenable, Wakeable} from 'shared/ReactTypes';
11 import type {Fiber, FiberRoot} from './ReactInternalTypes';
12 -import type {Lanes, Lane, LanePriority} from './ReactFiberLane.old';
12 +import type {Lanes, Lane} 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';
@@ -132,12 +132,10 @@ import {
132 import {
133 NoLanePriority,
134 SyncLanePriority,
135 - DefaultLanePriority,
135 NoLanes,
136 NoLane,
137 SyncLane,
138 NoTimestamp,
140 - findUpdateLane,
139 claimNextTransitionLane,
140 claimNextRetryLane,
141 includesSomeLane,
@@ -150,8 +148,6 @@ import {
148 includesOnlyTransitions,
149 getNextLanes,
150 returnNextLanesPriority,
153 - setCurrentUpdateLanePriority,
154 - getCurrentUpdateLanePriority,
151 markStarvedLanesAsExpired,
152 getLanesToRetrySynchronouslyOnError,
153 getMostRecentEventTime,
@@ -162,6 +158,14 @@ import {
158 markRootFinished,
159 lanePriorityToSchedulerPriority,
160 } from './ReactFiberLane.old';
161 +import {
162 + DiscreteEventPriority,
163 + DefaultEventPriority,
164 + getCurrentUpdatePriority,
165 + setCurrentUpdatePriority,
166 + higherEventPriority,
167 + lanesToEventPriority,
168 +} from './ReactEventPriorities.old';
169 import {requestCurrentTransition, NoTransition} from './ReactFiberTransition';
170 import {beginWork as originalBeginWork} from './ReactFiberBeginWork.old';
171 import {completeWork} from './ReactFiberCompleteWork.old';
@@ -320,7 +324,6 @@ let rootCommittingMutationOrLayoutEffects: FiberRoot | null = null;
324
325 let rootDoesHavePassiveEffects: boolean = false;
326 let rootWithPendingPassiveEffects: FiberRoot | null = null;
323 -let pendingPassiveEffectsRenderPriority: LanePriority = NoLanePriority;
327 let pendingPassiveEffectsLanes: Lanes = NoLanes;
328 let pendingPassiveProfilerEffects: Array<Fiber> = [];
329
@@ -423,9 +426,13 @@ export function requestUpdateLane(fiber: Fiber): Lane {
426
427 // Updates originating inside certain React methods, like flushSync, have
428 // their priority set by tracking it with a context variable.
426 - const updateLanePriority = getCurrentUpdateLanePriority();
427 - if (updateLanePriority !== NoLanePriority) {
428 - return findUpdateLane(updateLanePriority);
429 + //
430 + // The opaque type returned by the host config is internally a lane, so we can
431 + // use that directly.
432 + // TODO: Move this type conversion to the event priority module.
433 + const updateLane: Lane = (getCurrentUpdatePriority(): any);
434 + if (updateLane !== NoLane) {
435 + return updateLane;
436 }
437
438 // This update originated outside React. Ask the host environement for an
@@ -433,7 +440,8 @@ export function requestUpdateLane(fiber: Fiber): Lane {
440 //
441 // The opaque type returned by the host config is internally a lane, so we can
442 // use that directly.
436 - const eventLane = getCurrentEventPriority();
443 + // TODO: Move this type conversion to the event priority module.
444 + const eventLane: Lane = (getCurrentEventPriority(): any);
445 return eventLane;
446 }
447
@@ -1056,12 +1064,12 @@ export function flushDiscreteUpdates() {
1064 }
1065
1066 export function deferredUpdates<A>(fn: () => A): A {
1059 - const previousLanePriority = getCurrentUpdateLanePriority();
1067 + const previousPriority = getCurrentUpdatePriority();
1068 try {
1061 - setCurrentUpdateLanePriority(DefaultLanePriority);
1069 + setCurrentUpdatePriority(DefaultEventPriority);
1070 return fn();
1071 } finally {
1064 - setCurrentUpdateLanePriority(previousLanePriority);
1072 + setCurrentUpdatePriority(previousPriority);
1073 }
1074 }
1075
@@ -1102,12 +1110,12 @@ export function discreteUpdates<A, B, C, D, R>(
1110 c: C,
1111 d: D,
1112 ): R {
1105 - const previousLanePriority = getCurrentUpdateLanePriority();
1113 + const previousPriority = getCurrentUpdatePriority();
1114 try {
1107 - setCurrentUpdateLanePriority(SyncLanePriority);
1115 + setCurrentUpdatePriority(DiscreteEventPriority);
1116 return fn(a, b, c, d);
1117 } finally {
1110 - setCurrentUpdateLanePriority(previousLanePriority);
1118 + setCurrentUpdatePriority(previousPriority);
1119 if (executionContext === NoContext) {
1120 // Flush the immediate callbacks that were scheduled during this batch
1121 resetRenderTimer();
@@ -1146,16 +1154,16 @@ export function flushSync<A, R>(fn: A => R, a: A): R {
1154 }
1155 executionContext |= BatchedContext;
1156
1149 - const previousLanePriority = getCurrentUpdateLanePriority();
1157 + const previousPriority = getCurrentUpdatePriority();
1158 try {
1151 - setCurrentUpdateLanePriority(SyncLanePriority);
1159 + setCurrentUpdatePriority(DiscreteEventPriority);
1160 if (fn) {
1161 return fn(a);
1162 } else {
1163 return (undefined: $FlowFixMe);
1164 }
1165 } finally {
1158 - setCurrentUpdateLanePriority(previousLanePriority);
1166 + setCurrentUpdatePriority(previousPriority);
1167 executionContext = prevExecutionContext;
1168 // Flush the immediate callbacks that were scheduled during this batch.
1169 // Note that this will happen even if batchedUpdates is higher up
@@ -1167,12 +1175,12 @@ export function flushSync<A, R>(fn: A => R, a: A): R {
1175 export function flushControlled(fn: () => mixed): void {
1176 const prevExecutionContext = executionContext;
1177 executionContext |= BatchedContext;
1170 - const previousLanePriority = getCurrentUpdateLanePriority();
1178 + const previousPriority = getCurrentUpdatePriority();
1179 try {
1172 - setCurrentUpdateLanePriority(SyncLanePriority);
1180 + setCurrentUpdatePriority(DiscreteEventPriority);
1181 fn();
1182 } finally {
1175 - setCurrentUpdateLanePriority(previousLanePriority);
1183 + setCurrentUpdatePriority(previousPriority);
1184
1185 executionContext = prevExecutionContext;
1186 if (executionContext === NoContext) {
@@ -1663,12 +1671,14 @@ function completeUnitOfWork(unitOfWork: Fiber): void {
1671 }
1672
1673 function commitRoot(root) {
1666 - const previousUpdateLanePriority = getCurrentUpdateLanePriority();
1674 + // TODO: This no longer makes any sense. We already wrap the mutation and
1675 + // layout phases. Should be able to remove.
1676 + const previousUpdateLanePriority = getCurrentUpdatePriority();
1677 try {
1668 - setCurrentUpdateLanePriority(SyncLanePriority);
1678 + setCurrentUpdatePriority(DiscreteEventPriority);
1679 commitRootImpl(root, previousUpdateLanePriority);
1680 } finally {
1671 - setCurrentUpdateLanePriority(previousUpdateLanePriority);
1681 + setCurrentUpdatePriority(previousUpdateLanePriority);
1682 }
1683
1684 return null;
@@ -1780,8 +1790,8 @@ function commitRootImpl(root, renderPriorityLevel) {
1790 NoFlags;
1791
1792 if (subtreeHasEffects || rootHasEffect) {
1783 - const previousLanePriority = getCurrentUpdateLanePriority();
1784 - setCurrentUpdateLanePriority(SyncLanePriority);
1793 + const previousPriority = getCurrentUpdatePriority();
1794 + setCurrentUpdatePriority(DiscreteEventPriority);
1795
1796 const prevExecutionContext = executionContext;
1797 executionContext |= CommitContext;
@@ -1815,7 +1825,7 @@ function commitRootImpl(root, renderPriorityLevel) {
1825 }
1826
1827 // The next phase is the mutation phase, where we mutate the host tree.
1818 - commitMutationEffects(root, renderPriorityLevel, finishedWork);
1828 + commitMutationEffects(root, finishedWork);
1829
1830 if (shouldFireAfterActiveInstanceBlur) {
1831 afterActiveInstanceBlur();
@@ -1863,10 +1873,8 @@ function commitRootImpl(root, renderPriorityLevel) {
1873 }
1874 executionContext = prevExecutionContext;
1875
1866 - if (previousLanePriority != null) {
1867 - // Reset the priority to the previous non-sync value.
1868 - setCurrentUpdateLanePriority(previousLanePriority);
1869 - }
1876 + // Reset the priority to the previous non-sync value.
1877 + setCurrentUpdatePriority(previousPriority);
1878 } else {
1879 // No effects.
1880 root.current = finishedWork;
@@ -1886,10 +1894,6 @@ function commitRootImpl(root, renderPriorityLevel) {
1894 rootDoesHavePassiveEffects = false;
1895 rootWithPendingPassiveEffects = root;
1896 pendingPassiveEffectsLanes = lanes;
1889 - pendingPassiveEffectsRenderPriority =
1890 - renderPriorityLevel === NoLanePriority
1891 - ? DefaultLanePriority
1892 - : renderPriorityLevel;
1897 }
1898
1899 // Read this again, since an effect might have updated it
@@ -2003,18 +2007,17 @@ function commitRootImpl(root, renderPriorityLevel) {
2007
2008 export function flushPassiveEffects(): boolean {
2009 // Returns whether passive effects were flushed.
2006 - if (pendingPassiveEffectsRenderPriority !== NoLanePriority) {
2007 - const priorityLevel =
2008 - pendingPassiveEffectsRenderPriority > DefaultLanePriority
2009 - ? DefaultLanePriority
2010 - : pendingPassiveEffectsRenderPriority;
2011 - pendingPassiveEffectsRenderPriority = NoLanePriority;
2012 - const previousLanePriority = getCurrentUpdateLanePriority();
2010 + if (pendingPassiveEffectsLanes !== NoLanes) {
2011 + const priority = higherEventPriority(
2012 + DefaultEventPriority,
2013 + lanesToEventPriority(pendingPassiveEffectsLanes),
2014 + );
2015 + const previousPriority = getCurrentUpdatePriority();
2016 try {
2014 - setCurrentUpdateLanePriority(priorityLevel);
2017 + setCurrentUpdatePriority(priority);
2018 return flushPassiveEffectsImpl();
2019 } finally {
2017 - setCurrentUpdateLanePriority(previousLanePriority);
2020 + setCurrentUpdatePriority(previousPriority);
2021 }
2022 }
2023 return false;
packages/react-reconciler/src/SchedulerWithReactIntegration.new.js
+9 -7
@@ -16,10 +16,10 @@ import {__interactionsRef} from 'scheduler/tracing';
16 import {enableSchedulerTracing} from 'shared/ReactFeatureFlags';
17 import invariant from 'shared/invariant';
18 import {
19 - SyncLanePriority,
20 - getCurrentUpdateLanePriority,
21 - setCurrentUpdateLanePriority,
22 -} from './ReactFiberLane.new';
19 + DiscreteEventPriority,
20 + getCurrentUpdatePriority,
21 + setCurrentUpdatePriority,
22 +} from './ReactEventPriorities.new';
23
24 const {
25 unstable_scheduleCallback: Scheduler_scheduleCallback,
@@ -147,11 +147,13 @@ export function flushSyncCallbackQueue() {
147 // Prevent re-entrancy.
148 isFlushingSyncQueue = true;
149 let i = 0;
150 - const previousLanePriority = getCurrentUpdateLanePriority();
150 + const previousUpdatePriority = getCurrentUpdatePriority();
151 try {
152 const isSync = true;
153 const queue = syncQueue;
154 - setCurrentUpdateLanePriority(SyncLanePriority);
154 + // TODO: Is this necessary anymore? The only user code that runs in this
155 + // queue is in the render or commit phases.
156 + setCurrentUpdatePriority(DiscreteEventPriority);
157 for (; i < queue.length; i++) {
158 let callback = queue[i];
159 do {
@@ -171,7 +173,7 @@ export function flushSyncCallbackQueue() {
173 );
174 throw error;
175 } finally {
174 - setCurrentUpdateLanePriority(previousLanePriority);
176 + setCurrentUpdatePriority(previousUpdatePriority);
177 isFlushingSyncQueue = false;
178 }
179 }
packages/react-reconciler/src/SchedulerWithReactIntegration.old.js
+9 -7
@@ -16,10 +16,10 @@ import {__interactionsRef} from 'scheduler/tracing';
16 import {enableSchedulerTracing} from 'shared/ReactFeatureFlags';
17 import invariant from 'shared/invariant';
18 import {
19 - SyncLanePriority,
20 - getCurrentUpdateLanePriority,
21 - setCurrentUpdateLanePriority,
22 -} from './ReactFiberLane.old';
19 + DiscreteEventPriority,
20 + getCurrentUpdatePriority,
21 + setCurrentUpdatePriority,
22 +} from './ReactEventPriorities.old';
23
24 const {
25 unstable_scheduleCallback: Scheduler_scheduleCallback,
@@ -147,11 +147,13 @@ export function flushSyncCallbackQueue() {
147 // Prevent re-entrancy.
148 isFlushingSyncQueue = true;
149 let i = 0;
150 - const previousLanePriority = getCurrentUpdateLanePriority();
150 + const previousUpdatePriority = getCurrentUpdatePriority();
151 try {
152 const isSync = true;
153 const queue = syncQueue;
154 - setCurrentUpdateLanePriority(SyncLanePriority);
154 + // TODO: Is this necessary anymore? The only user code that runs in this
155 + // queue is in the render or commit phases.
156 + setCurrentUpdatePriority(DiscreteEventPriority);
157 for (; i < queue.length; i++) {
158 let callback = queue[i];
159 do {
@@ -171,7 +173,7 @@ export function flushSyncCallbackQueue() {
173 );
174 throw error;
175 } finally {
174 - setCurrentUpdateLanePriority(previousLanePriority);
176 + setCurrentUpdatePriority(previousUpdatePriority);
177 isFlushingSyncQueue = false;
178 }
179 }
packages/react-reconciler/src/__tests__/ReactIncrementalUpdates-test.js
+7 -9
@@ -13,11 +13,7 @@
13 let React;
14 let ReactNoop;
15 let Scheduler;
16 -
17 -// Copied from ReactFiberLanes. Don't do this!
18 -// This is hard coded directly to avoid needing to import, and
19 -// we'll remove this as we replace runWithPriority with React APIs.
20 -const InputContinuousLanePriority = 10;
16 +let ContinuousEventPriority;
17
18 describe('ReactIncrementalUpdates', () => {
19 beforeEach(() => {
@@ -26,6 +22,8 @@ describe('ReactIncrementalUpdates', () => {
22 React = require('react');
23 ReactNoop = require('react-noop-renderer');
24 Scheduler = require('scheduler');
25 + ContinuousEventPriority = require('react-reconciler/constants')
26 + .ContinuousEventPriority;
27 });
28
29 function span(prop) {
@@ -544,7 +542,7 @@ describe('ReactIncrementalUpdates', () => {
542 Scheduler.unstable_yieldValue('Committed: ' + log);
543 if (log === 'B') {
544 // Right after B commits, schedule additional updates.
547 - ReactNoop.unstable_runWithPriority(InputContinuousLanePriority, () =>
545 + ReactNoop.unstable_runWithPriority(ContinuousEventPriority, () =>
546 pushToLog('C'),
547 );
548 setLog(prevLog => prevLog + 'D');
@@ -564,7 +562,7 @@ describe('ReactIncrementalUpdates', () => {
562 await ReactNoop.act(async () => {
563 pushToLog('A');
564
567 - ReactNoop.unstable_runWithPriority(InputContinuousLanePriority, () =>
565 + ReactNoop.unstable_runWithPriority(ContinuousEventPriority, () =>
566 pushToLog('B'),
567 );
568 });
@@ -597,7 +595,7 @@ describe('ReactIncrementalUpdates', () => {
595 Scheduler.unstable_yieldValue('Committed: ' + this.state.log);
596 if (this.state.log === 'B') {
597 // Right after B commits, schedule additional updates.
600 - ReactNoop.unstable_runWithPriority(InputContinuousLanePriority, () =>
598 + ReactNoop.unstable_runWithPriority(ContinuousEventPriority, () =>
599 this.pushToLog('C'),
600 );
601 this.pushToLog('D');
@@ -618,7 +616,7 @@ describe('ReactIncrementalUpdates', () => {
616
617 await ReactNoop.act(async () => {
618 pushToLog('A');
621 - ReactNoop.unstable_runWithPriority(InputContinuousLanePriority, () =>
619 + ReactNoop.unstable_runWithPriority(ContinuousEventPriority, () =>
620 pushToLog('B'),
621 );
622 });
packages/react/src/__tests__/ReactDOMTracing-test.internal.js
+9 -9
@@ -23,12 +23,8 @@ let onWorkCanceled;
23 let onWorkScheduled;
24 let onWorkStarted;
25 let onWorkStopped;
26 -
27 -// Copied from ReactFiberLanes. Don't do this!
28 -// This is hard coded directly to avoid needing to import, and
29 -// we'll remove this as we replace runWithPriority with React APIs.
30 -const IdleLanePriority = 2;
31 -const InputContinuousPriority = 10;
26 +let IdleEventPriority;
27 +let ContinuousEventPriority;
28
29 function loadModules() {
30 ReactFeatureFlags = require('shared/ReactFeatureFlags');
@@ -44,6 +40,10 @@ function loadModules() {
40 SchedulerTracing = require('scheduler/tracing');
41 TestUtils = require('react-dom/test-utils');
42
43 + IdleEventPriority = require('react-reconciler/constants').IdleEventPriority;
44 + ContinuousEventPriority = require('react-reconciler/constants')
45 + .ContinuousEventPriority;
46 +
47 act = TestUtils.unstable_concurrentAct;
48
49 onInteractionScheduledWorkCompleted = jest.fn();
@@ -246,7 +246,7 @@ describe('ReactDOMTracing', () => {
246 Scheduler.unstable_yieldValue('Child:update');
247 } else {
248 Scheduler.unstable_yieldValue('Child:mount');
249 - ReactDOM.unstable_runWithPriority(IdleLanePriority, () =>
249 + ReactDOM.unstable_runWithPriority(IdleEventPriority, () =>
250 setDidMount(true),
251 );
252 }
@@ -499,7 +499,7 @@ describe('ReactDOMTracing', () => {
499 let interaction = null;
500 SchedulerTracing.unstable_trace('update', 0, () => {
501 interaction = Array.from(SchedulerTracing.unstable_getCurrent())[0];
502 - ReactDOM.unstable_runWithPriority(InputContinuousPriority, () =>
502 + ReactDOM.unstable_runWithPriority(ContinuousEventPriority, () =>
503 scheduleUpdateWithHidden(),
504 );
505 });
@@ -606,7 +606,7 @@ describe('ReactDOMTracing', () => {
606 // Schedule an unrelated low priority update that shouldn't be included
607 // in the previous interaction. This is meant to ensure that we don't
608 // rely on the whole tree completing to cover up bugs.
609 - ReactDOM.unstable_runWithPriority(IdleLanePriority, () => {
609 + ReactDOM.unstable_runWithPriority(IdleEventPriority, () => {
610 root.render(<App />);
611 });
612