Skip to content

Commit 2e48166

Browse files
committed
Use LanePriority over ReactPriorityLevel
1 parent d745597 commit 2e48166

23 files changed

+292
-1231
lines changed

packages/react-dom/src/events/ReactDOMEventListener.js

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ import type {FiberRoot} from 'react-reconciler/src/ReactInternalTypes';
1212
import type {Container, SuspenseInstance} from '../client/ReactDOMHostConfig';
1313
import type {DOMEventName} from '../events/DOMEventNames';
1414

15-
// Intentionally not named imports because Rollup would use dynamic dispatch for
16-
// CommonJS interop named imports.
17-
import * as Scheduler from 'scheduler';
18-
1915
import {
2016
isReplayableDiscreteEvent,
2117
queueDiscreteEvent,
@@ -40,7 +36,6 @@ import {getClosestInstanceFromNode} from '../client/ReactDOMComponentTree';
4036

4137
import {
4238
enableLegacyFBSupport,
43-
decoupleUpdatePriorityFromScheduler,
4439
enableNewReconciler,
4540
} from 'shared/ReactFeatureFlags';
4641
import {dispatchEventForPluginEventSystem} from './DOMPluginEventSystem';
@@ -90,11 +85,6 @@ const getCurrentPriorityLevel = enableNewReconciler
9085
? getCurrentPriorityLevel_new
9186
: getCurrentPriorityLevel_old;
9287

93-
const {
94-
unstable_UserBlockingPriority: UserBlockingPriority,
95-
unstable_runWithPriority: runWithPriority,
96-
} = Scheduler;
97-
9888
// TODO: can we stop exporting these?
9989
export let _enabled = true;
10090

@@ -177,35 +167,12 @@ function dispatchContinuousEvent(
177167
container,
178168
nativeEvent,
179169
) {
180-
if (decoupleUpdatePriorityFromScheduler) {
181-
const previousPriority = getCurrentUpdateLanePriority();
182-
try {
183-
// TODO: Double wrapping is necessary while we decouple Scheduler priority.
184-
setCurrentUpdateLanePriority(InputContinuousLanePriority);
185-
runWithPriority(
186-
UserBlockingPriority,
187-
dispatchEvent.bind(
188-
null,
189-
domEventName,
190-
eventSystemFlags,
191-
container,
192-
nativeEvent,
193-
),
194-
);
195-
} finally {
196-
setCurrentUpdateLanePriority(previousPriority);
197-
}
198-
} else {
199-
runWithPriority(
200-
UserBlockingPriority,
201-
dispatchEvent.bind(
202-
null,
203-
domEventName,
204-
eventSystemFlags,
205-
container,
206-
nativeEvent,
207-
),
208-
);
170+
const previousPriority = getCurrentUpdateLanePriority();
171+
try {
172+
setCurrentUpdateLanePriority(InputContinuousLanePriority);
173+
dispatchEvent(domEventName, eventSystemFlags, container, nativeEvent);
174+
} finally {
175+
setCurrentUpdateLanePriority(previousPriority);
209176
}
210177
}
211178

packages/react-reconciler/src/ReactFiberCommitWork.new.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ import type {
1717
} from './ReactFiberHostConfig';
1818
import type {Fiber} from './ReactInternalTypes';
1919
import type {FiberRoot} from './ReactInternalTypes';
20-
import type {Lanes} from './ReactFiberLane.new';
20+
import type {LanePriority, Lanes} from './ReactFiberLane.new';
2121
import type {SuspenseState} from './ReactFiberSuspenseComponent.new';
2222
import type {UpdateQueue} from './ReactUpdateQueue.new';
2323
import type {FunctionComponentUpdateQueue} from './ReactFiberHooks.new';
2424
import type {Wakeable} from 'shared/ReactTypes';
25-
import type {ReactPriorityLevel} from './ReactInternalTypes';
2625
import type {OffscreenState} from './ReactFiberOffscreenComponent';
2726
import type {HookFlags} from './ReactHookEffectTags';
2827

@@ -1057,7 +1056,7 @@ function commitUnmount(
10571056
finishedRoot: FiberRoot,
10581057
current: Fiber,
10591058
nearestMountedAncestor: Fiber,
1060-
renderPriorityLevel: ReactPriorityLevel,
1059+
renderPriorityLevel: LanePriority,
10611060
): void {
10621061
onCommitUnmount(current);
10631062

@@ -1153,7 +1152,7 @@ function commitNestedUnmounts(
11531152
finishedRoot: FiberRoot,
11541153
root: Fiber,
11551154
nearestMountedAncestor: Fiber,
1156-
renderPriorityLevel: ReactPriorityLevel,
1155+
renderPriorityLevel: LanePriority,
11571156
): void {
11581157
// While we're inside a removed host node we don't want to call
11591158
// removeChild on the inner nodes because they're removed by the top
@@ -1463,7 +1462,7 @@ function unmountHostComponents(
14631462
finishedRoot: FiberRoot,
14641463
current: Fiber,
14651464
nearestMountedAncestor: Fiber,
1466-
renderPriorityLevel: ReactPriorityLevel,
1465+
renderPriorityLevel: LanePriority,
14671466
): void {
14681467
// We only have the top Fiber that was deleted but we need to recurse down its
14691468
// children to find all the terminal nodes.
@@ -1601,7 +1600,7 @@ function commitDeletion(
16011600
finishedRoot: FiberRoot,
16021601
current: Fiber,
16031602
nearestMountedAncestor: Fiber,
1604-
renderPriorityLevel: ReactPriorityLevel,
1603+
renderPriorityLevel: LanePriority,
16051604
): void {
16061605
if (supportsMutation) {
16071606
// Recursively delete all host nodes from the parent.
@@ -1945,7 +1944,7 @@ function commitResetTextContent(current: Fiber) {
19451944

19461945
export function commitMutationEffects(
19471946
root: FiberRoot,
1948-
renderPriorityLevel: ReactPriorityLevel,
1947+
renderPriorityLevel: LanePriority,
19491948
firstChild: Fiber,
19501949
) {
19511950
nextEffect = firstChild;
@@ -1954,7 +1953,7 @@ export function commitMutationEffects(
19541953

19551954
function commitMutationEffects_begin(
19561955
root: FiberRoot,
1957-
renderPriorityLevel: ReactPriorityLevel,
1956+
renderPriorityLevel: LanePriority,
19581957
) {
19591958
while (nextEffect !== null) {
19601959
const fiber = nextEffect;
@@ -2000,7 +1999,7 @@ function commitMutationEffects_begin(
20001999

20012000
function commitMutationEffects_complete(
20022001
root: FiberRoot,
2003-
renderPriorityLevel: ReactPriorityLevel,
2002+
renderPriorityLevel: LanePriority,
20042003
) {
20052004
while (nextEffect !== null) {
20062005
const fiber = nextEffect;
@@ -2041,7 +2040,7 @@ function commitMutationEffects_complete(
20412040
function commitMutationEffectsOnFiber(
20422041
finishedWork: Fiber,
20432042
root: FiberRoot,
2044-
renderPriorityLevel: ReactPriorityLevel,
2043+
renderPriorityLevel: LanePriority,
20452044
) {
20462045
const flags = finishedWork.flags;
20472046

packages/react-reconciler/src/ReactFiberCommitWork.old.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ import type {
1717
} from './ReactFiberHostConfig';
1818
import type {Fiber} from './ReactInternalTypes';
1919
import type {FiberRoot} from './ReactInternalTypes';
20-
import type {Lanes} from './ReactFiberLane.old';
20+
import type {LanePriority, Lanes} from './ReactFiberLane.old';
2121
import type {SuspenseState} from './ReactFiberSuspenseComponent.old';
2222
import type {UpdateQueue} from './ReactUpdateQueue.old';
2323
import type {FunctionComponentUpdateQueue} from './ReactFiberHooks.old';
2424
import type {Wakeable} from 'shared/ReactTypes';
25-
import type {ReactPriorityLevel} from './ReactInternalTypes';
2625
import type {OffscreenState} from './ReactFiberOffscreenComponent';
2726
import type {HookFlags} from './ReactHookEffectTags';
2827

@@ -1057,7 +1056,7 @@ function commitUnmount(
10571056
finishedRoot: FiberRoot,
10581057
current: Fiber,
10591058
nearestMountedAncestor: Fiber,
1060-
renderPriorityLevel: ReactPriorityLevel,
1059+
renderPriorityLevel: LanePriority,
10611060
): void {
10621061
onCommitUnmount(current);
10631062

@@ -1153,7 +1152,7 @@ function commitNestedUnmounts(
11531152
finishedRoot: FiberRoot,
11541153
root: Fiber,
11551154
nearestMountedAncestor: Fiber,
1156-
renderPriorityLevel: ReactPriorityLevel,
1155+
renderPriorityLevel: LanePriority,
11571156
): void {
11581157
// While we're inside a removed host node we don't want to call
11591158
// removeChild on the inner nodes because they're removed by the top
@@ -1463,7 +1462,7 @@ function unmountHostComponents(
14631462
finishedRoot: FiberRoot,
14641463
current: Fiber,
14651464
nearestMountedAncestor: Fiber,
1466-
renderPriorityLevel: ReactPriorityLevel,
1465+
renderPriorityLevel: LanePriority,
14671466
): void {
14681467
// We only have the top Fiber that was deleted but we need to recurse down its
14691468
// children to find all the terminal nodes.
@@ -1601,7 +1600,7 @@ function commitDeletion(
16011600
finishedRoot: FiberRoot,
16021601
current: Fiber,
16031602
nearestMountedAncestor: Fiber,
1604-
renderPriorityLevel: ReactPriorityLevel,
1603+
renderPriorityLevel: LanePriority,
16051604
): void {
16061605
if (supportsMutation) {
16071606
// Recursively delete all host nodes from the parent.
@@ -1945,7 +1944,7 @@ function commitResetTextContent(current: Fiber) {
19451944

19461945
export function commitMutationEffects(
19471946
root: FiberRoot,
1948-
renderPriorityLevel: ReactPriorityLevel,
1947+
renderPriorityLevel: LanePriority,
19491948
firstChild: Fiber,
19501949
) {
19511950
nextEffect = firstChild;
@@ -1954,7 +1953,7 @@ export function commitMutationEffects(
19541953

19551954
function commitMutationEffects_begin(
19561955
root: FiberRoot,
1957-
renderPriorityLevel: ReactPriorityLevel,
1956+
renderPriorityLevel: LanePriority,
19581957
) {
19591958
while (nextEffect !== null) {
19601959
const fiber = nextEffect;
@@ -2000,7 +1999,7 @@ function commitMutationEffects_begin(
20001999

20012000
function commitMutationEffects_complete(
20022001
root: FiberRoot,
2003-
renderPriorityLevel: ReactPriorityLevel,
2002+
renderPriorityLevel: LanePriority,
20042003
) {
20052004
while (nextEffect !== null) {
20062005
const fiber = nextEffect;
@@ -2041,7 +2040,7 @@ function commitMutationEffects_complete(
20412040
function commitMutationEffectsOnFiber(
20422041
finishedWork: Fiber,
20432042
root: FiberRoot,
2044-
renderPriorityLevel: ReactPriorityLevel,
2043+
renderPriorityLevel: LanePriority,
20452044
) {
20462045
const flags = finishedWork.flags;
20472046

packages/react-reconciler/src/ReactFiberDevToolsHook.new.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@
99

1010
import {enableProfilerTimer} from 'shared/ReactFeatureFlags';
1111

12-
import type {Fiber, FiberRoot, ReactPriorityLevel} from './ReactInternalTypes';
12+
import type {Fiber, FiberRoot} from './ReactInternalTypes';
1313
import type {ReactNodeList} from 'shared/ReactTypes';
14+
import type {LanePriority} from './ReactFiberLane.new';
1415

1516
import {DidCapture} from './ReactFiberFlags';
17+
import {
18+
lanePriorityToSchedulerPriority,
19+
NoLanePriority,
20+
} from './ReactFiberLane.new';
21+
import {NormalPriority} from './SchedulerWithReactIntegration.new';
1622

1723
declare var __REACT_DEVTOOLS_GLOBAL_HOOK__: Object | void;
1824

@@ -78,18 +84,19 @@ export function onScheduleRoot(root: FiberRoot, children: ReactNodeList) {
7884
}
7985
}
8086

81-
export function onCommitRoot(
82-
root: FiberRoot,
83-
priorityLevel: ReactPriorityLevel,
84-
) {
87+
export function onCommitRoot(root: FiberRoot, priorityLevel: LanePriority) {
8588
if (injectedHook && typeof injectedHook.onCommitFiberRoot === 'function') {
8689
try {
8790
const didError = (root.current.flags & DidCapture) === DidCapture;
8891
if (enableProfilerTimer) {
92+
const schedulerPriority =
93+
priorityLevel === NoLanePriority
94+
? NormalPriority
95+
: lanePriorityToSchedulerPriority(priorityLevel);
8996
injectedHook.onCommitFiberRoot(
9097
rendererID,
9198
root,
92-
priorityLevel,
99+
schedulerPriority,
93100
didError,
94101
);
95102
} else {

packages/react-reconciler/src/ReactFiberDevToolsHook.old.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@
99

1010
import {enableProfilerTimer} from 'shared/ReactFeatureFlags';
1111

12-
import type {Fiber, FiberRoot, ReactPriorityLevel} from './ReactInternalTypes';
12+
import type {Fiber, FiberRoot} from './ReactInternalTypes';
1313
import type {ReactNodeList} from 'shared/ReactTypes';
14+
import type {LanePriority} from './ReactFiberLane.old';
1415

1516
import {DidCapture} from './ReactFiberFlags';
17+
import {
18+
lanePriorityToSchedulerPriority,
19+
NoLanePriority,
20+
} from './ReactFiberLane.old';
21+
import {NormalPriority} from './SchedulerWithReactIntegration.old';
1622

1723
declare var __REACT_DEVTOOLS_GLOBAL_HOOK__: Object | void;
1824

@@ -78,18 +84,19 @@ export function onScheduleRoot(root: FiberRoot, children: ReactNodeList) {
7884
}
7985
}
8086

81-
export function onCommitRoot(
82-
root: FiberRoot,
83-
priorityLevel: ReactPriorityLevel,
84-
) {
87+
export function onCommitRoot(root: FiberRoot, priorityLevel: LanePriority) {
8588
if (injectedHook && typeof injectedHook.onCommitFiberRoot === 'function') {
8689
try {
8790
const didError = (root.current.flags & DidCapture) === DidCapture;
8891
if (enableProfilerTimer) {
92+
const schedulerPriority =
93+
priorityLevel === NoLanePriority
94+
? NormalPriority
95+
: lanePriorityToSchedulerPriority(priorityLevel);
8996
injectedHook.onCommitFiberRoot(
9097
rendererID,
9198
root,
92-
priorityLevel,
99+
schedulerPriority,
93100
didError,
94101
);
95102
} else {

0 commit comments

Comments
 (0)