Skip to content

Commit d0eaf78

Browse files
authored
Move priorities to separate import to break cycle (#21060)
The event priority constants exports by the reconciler package are meant to be used by the reconciler (host config) itself. So it doesn't make sense to export them from a module that requires them. To break the cycle, we can move them to a separate module and import that. This looks like a "deep import" of an internal module, which we try to avoid, but conceptually these are part of the public interface of the reconciler module. So, no different than importing from the main `react-reconciler`. We do need to be careful about not mixing these types of imports with implementation details. Those are the ones to really avoid. An unintended benefit of the reconciler fork infra is that it makes deep imports harder. Any module that we treat as "public", like this one, needs to account for the `enableNewReconciler` flag and forward to the correct implementation.
1 parent 435cff9 commit d0eaf78

13 files changed

Lines changed: 129 additions & 86 deletions

File tree

‎packages/react-art/src/ReactARTHostConfig.js‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,11 @@
77

88
importTransformfrom'art/core/transform';
99
importModefrom'art/modes/current';
10-
import{enableNewReconciler}from'shared/ReactFeatureFlags';
1110
importinvariantfrom'shared/invariant';
1211

1312
import{TYPES,EVENT_TYPES,childrenAsString}from'./ReactARTInternals';
1413

15-
import{DefaultLanePriorityasDefaultLanePriority_old}from'react-reconciler/src/ReactFiberLane.old';
16-
import{DefaultLanePriorityasDefaultLanePriority_new}from'react-reconciler/src/ReactFiberLane.new';
17-
18-
constDefaultLanePriority=enableNewReconciler
19-
? DefaultLanePriority_new
20-
: DefaultLanePriority_old;
14+
import{DefaultEventPriority}from'react-reconciler/src/ReactEventPriorities';
2115

2216
constpooledTransform=newTransform();
2317

@@ -347,7 +341,7 @@ export function shouldSetTextContent(type, props) {
347341
}
348342

349343
exportfunctiongetCurrentEventPriority(){
350-
returnDefaultLanePriority;
344+
returnDefaultEventPriority;
351345
}
352346

353347
// The ART renderer is secondary to the React DOM renderer.

‎packages/react-dom/src/client/ReactDOMHostConfig.js‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,11 @@ import {
6767
enableSuspenseServerRenderer,
6868
enableCreateEventHandleAPI,
6969
enableScopeAPI,
70-
enableNewReconciler,
7170
}from'shared/ReactFeatureFlags';
7271
import{HostComponent,HostText}from'react-reconciler/src/ReactWorkTags';
7372
import{listenToAllSupportedEvents}from'../events/DOMPluginEventSystem';
7473

75-
import{DefaultLanePriorityasDefaultLanePriority_old}from'react-reconciler/src/ReactFiberLane.old';
76-
import{DefaultLanePriorityasDefaultLanePriority_new}from'react-reconciler/src/ReactFiberLane.new';
77-
78-
constDefaultLanePriority=enableNewReconciler
79-
? DefaultLanePriority_new
80-
: DefaultLanePriority_old;
74+
import{DefaultEventPriority}from'react-reconciler/src/ReactEventPriorities';
8175

8276
exporttypeType=string;
8377
exporttypeProps={
@@ -385,7 +379,7 @@ export function createTextInstance(
385379
exportfunctiongetCurrentEventPriority(): *{
386380
constcurrentEvent=window.event;
387381
if(currentEvent===undefined){
388-
returnDefaultLanePriority;
382+
returnDefaultEventPriority;
389383
}
390384
returngetEventPriority(currentEvent.type);
391385
}

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

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type {
1414
}from'react-reconciler/src/ReactInternalTypes';
1515
importtype{Container,SuspenseInstance}from'../client/ReactDOMHostConfig';
1616
importtype{DOMEventName}from'../events/DOMEventNames';
17+
importtype{LanePriority}from'react-reconciler/src/ReactFiberLane.new';
1718

1819
import{
1920
isReplayableDiscreteEvent,
@@ -49,18 +50,13 @@ import {
4950

5051
import{
5152
InputContinuousLanePriorityasInputContinuousLanePriority_old,
52-
DefaultLanePriorityasDefaultLanePriority_old,
5353
getCurrentUpdateLanePriorityasgetCurrentUpdateLanePriority_old,
5454
setCurrentUpdateLanePriorityassetCurrentUpdateLanePriority_old,
5555
}from'react-reconciler/src/ReactFiberLane.old';
5656
import{
5757
InputContinuousLanePriorityasInputContinuousLanePriority_new,
58-
DefaultLanePriorityasDefaultLanePriority_new,
5958
getCurrentUpdateLanePriorityasgetCurrentUpdateLanePriority_new,
6059
setCurrentUpdateLanePriorityassetCurrentUpdateLanePriority_new,
61-
SyncLanePriority,
62-
IdleLanePriority,
63-
NoLanePriority,
6460
}from'react-reconciler/src/ReactFiberLane.new';
6561
import{getCurrentPriorityLevelasgetCurrentPriorityLevel_old}from'react-reconciler/src/SchedulerWithReactIntegration.old';
6662
import{
@@ -71,14 +67,16 @@ import {
7167
NormalPriorityasNormalSchedulerPriority,
7268
UserBlockingPriorityasUserBlockingSchedulerPriority,
7369
}from'react-reconciler/src/SchedulerWithReactIntegration.new';
74-
importtype{LanePriority}from'react-reconciler/src/ReactFiberLane.new';
70+
import{
71+
DiscreteEventPriority,
72+
ContinuousEventPriority,
73+
DefaultEventPriority,
74+
IdleEventPriority,
75+
}from'react-reconciler/src/ReactEventPriorities';
7576

7677
constInputContinuousLanePriority=enableNewReconciler
7778
? InputContinuousLanePriority_new
7879
: InputContinuousLanePriority_old;
79-
constDefaultLanePriority=enableNewReconciler
80-
? DefaultLanePriority_new
81-
: DefaultLanePriority_old;
8280
constgetCurrentUpdateLanePriority=enableNewReconciler
8381
? getCurrentUpdateLanePriority_new
8482
: getCurrentUpdateLanePriority_old;
@@ -94,17 +92,17 @@ function schedulerPriorityToLanePriority(
9492
): LanePriority{
9593
switch(schedulerPriorityLevel){
9694
caseImmediateSchedulerPriority:
97-
returnSyncLanePriority;
95+
returnDiscreteEventPriority;
9896
caseUserBlockingSchedulerPriority:
99-
returnInputContinuousLanePriority;
97+
returnContinuousEventPriority;
10098
caseNormalSchedulerPriority:
10199
caseLowSchedulerPriority:
102100
// TODO: Handle LowSchedulerPriority, somehow. Maybe the same lane as hydration.
103-
returnDefaultLanePriority;
101+
returnDefaultEventPriority;
104102
caseIdleSchedulerPriority:
105-
returnIdleLanePriority;
103+
returnIdleEventPriority;
106104
default:
107-
returnNoLanePriority;
105+
returnDefaultEventPriority;
108106
}
109107
}
110108

@@ -142,13 +140,13 @@ export function createEventListenerWrapperWithPriority(
142140
consteventPriority=getEventPriority(domEventName);
143141
letlistenerWrapper;
144142
switch(eventPriority){
145-
caseSyncLanePriority:
143+
caseDiscreteEventPriority:
146144
listenerWrapper=dispatchDiscreteEvent;
147145
break;
148-
caseInputContinuousLanePriority:
146+
caseContinuousEventPriority:
149147
listenerWrapper=dispatchContinuousEvent;
150148
break;
151-
caseDefaultLanePriority:
149+
caseDefaultEventPriority:
152150
default:
153151
listenerWrapper=dispatchEvent;
154152
break;
@@ -407,7 +405,7 @@ export function getEventPriority(domEventName: DOMEventName): * {
407405
case'popstate':
408406
case'select':
409407
case'selectstart':
410-
returnSyncLanePriority;
408+
returnDiscreteEventPriority;
411409
case'drag':
412410
case'dragenter':
413411
case'dragexit':
@@ -427,7 +425,7 @@ export function getEventPriority(domEventName: DOMEventName): * {
427425
// eslint-disable-next-line no-fallthrough
428426
case'mouseenter':
429427
case'mouseleave':
430-
returnInputContinuousLanePriority;
428+
returnContinuousEventPriority;
431429
case'message': {
432430
// We might be in the Scheduler callback.
433431
// Eventually this mechanism will be replaced by a check
@@ -436,6 +434,6 @@ export function getEventPriority(domEventName: DOMEventName): * {
436434
returnschedulerPriorityToLanePriority(schedulerPriority);
437435
}
438436
default:
439-
returnDefaultLanePriority;
437+
returnDefaultEventPriority;
440438
}
441439
}

‎packages/react-native-renderer/src/ReactFabricHostConfig.js‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,11 @@ import type {
2121
import{mountSafeCallback_NOT_REALLY_SAFE}from'./NativeMethodsMixinUtils';
2222
import{create,diff}from'./ReactNativeAttributePayload';
2323

24-
import{enableNewReconciler}from'shared/ReactFeatureFlags';
2524
importinvariantfrom'shared/invariant';
2625

2726
import{dispatchEvent}from'./ReactFabricEventEmitter';
2827

29-
import{DefaultLanePriorityasDefaultLanePriority_old}from'react-reconciler/src/ReactFiberLane.old';
30-
import{DefaultLanePriorityasDefaultLanePriority_new}from'react-reconciler/src/ReactFiberLane.new';
31-
32-
constDefaultLanePriority=enableNewReconciler
33-
? DefaultLanePriority_new
34-
: DefaultLanePriority_old;
28+
import{DefaultEventPriority}from'react-reconciler/src/ReactEventPriorities';
3529

3630
// Modules provided by RN:
3731
import{
@@ -349,7 +343,7 @@ export function shouldSetTextContent(type: string, props: Props): boolean {
349343
}
350344

351345
exportfunctiongetCurrentEventPriority(): *{
352-
return DefaultLanePriority;
346+
return DefaultEventPriority;
353347
}
354348

355349
// The Fabric renderer is secondary to the existing React Native renderer.

‎packages/react-native-renderer/src/ReactNativeHostConfig.js‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
importtype{TouchedViewDataAtPoint}from'./ReactNativeTypes';
1111

1212
importinvariantfrom'shared/invariant';
13-
import{enableNewReconciler}from'shared/ReactFeatureFlags';
1413

1514
// Modules provided by RN:
1615
import{
@@ -27,12 +26,7 @@ import {
2726
}from'./ReactNativeComponentTree';
2827
importReactNativeFiberHostComponentfrom'./ReactNativeFiberHostComponent';
2928

30-
import{DefaultLanePriorityasDefaultLanePriority_old}from'react-reconciler/src/ReactFiberLane.old';
31-
import{DefaultLanePriorityasDefaultLanePriority_new}from'react-reconciler/src/ReactFiberLane.new';
32-
33-
constDefaultLanePriority=enableNewReconciler
34-
? DefaultLanePriority_new
35-
: DefaultLanePriority_old;
29+
import{DefaultEventPriority}from'react-reconciler/src/ReactEventPriorities';
3630

3731
const{get: getViewConfigForType}=ReactNativeViewConfigRegistry;
3832

@@ -268,7 +262,7 @@ export function shouldSetTextContent(type: string, props: Props): boolean {
268262
}
269263

270264
exportfunctiongetCurrentEventPriority(): *{
271-
returnDefaultLanePriority;
265+
returnDefaultEventPriority;
272266
}
273267

274268
// -------------------

‎packages/react-noop-renderer/src/createReactNoop.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ import ReactSharedInternals from 'shared/ReactSharedInternals';
2727
importenqueueTaskfrom'shared/enqueueTask';
2828
const{IsSomeRendererActing}=ReactSharedInternals;
2929

30+
// TODO: Publish public entry point that exports the event priority constants
31+
constDefaultEventPriority=8;
32+
3033
typeContainer={
3134
rootID: string,
3235
children: Array<Instance|TextInstance>,
@@ -587,7 +590,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
587590
constroots=newMap();
588591
constDEFAULT_ROOT_ID='<default>';
589592

590-
letcurrentEventPriority=NoopRenderer.DefaultEventPriority;
593+
letcurrentEventPriority=DefaultEventPriority;
591594

592595
functionchildToJSX(child,text){
593596
if(text!==null){

‎packages/react-reconciler/README.md‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,16 @@ This is a property (not a function) that should be set to `true` if your rendere
219219
To implement this method, you'll need some constants available on the _returned_`Renderer` object:
220220

221221
```js
222+
import {
223+
DiscreteEventPriority,
224+
ContinuousEventPriority,
225+
DefaultEventPriority,
226+
} from'./ReactFiberReconciler/src/ReactEventPriorities';
227+
222228
constHostConfig= {
223229
// ...
224230
getCurrentEventPriority() {
225-
returnMyRenderer.DefaultEventPriority;
231+
return DefaultEventPriority;
226232
},
227233
// ...
228234
}
@@ -232,11 +238,11 @@ const MyRenderer = Reconciler(HostConfig);
232238

233239
The constant you return depends on which event, if any, is being handled right now. (In the browser, you can check this using `window.event && window.event.type`).
234240

235-
***Discrete events:** If the active event is _directly caused by the user_ (such as mouse and keyboard events) and _each event in a sequence is intentional_ (e.g. `click`), return `MyRenderer.DiscreteEventPriority`. This tells React that they should interrupt any background work and cannot be batched across time.
241+
***Discrete events:** If the active event is _directly caused by the user_ (such as mouse and keyboard events) and _each event in a sequence is intentional_ (e.g. `click`), return `DiscreteEventPriority`. This tells React that they should interrupt any background work and cannot be batched across time.
236242

237-
***Continuous events:** If the active event is _directly caused by the user_ but _the user can't distinguish between individual events in a sequence_ (e.g. `mouseover`), return `MyRenderer.ContinuousEventPriority`. This tells React they should interrupt any background work but can be batched across time.
243+
***Continuous events:** If the active event is _directly caused by the user_ but _the user can't distinguish between individual events in a sequence_ (e.g. `mouseover`), return `ContinuousEventPriority`. This tells React they should interrupt any background work but can be batched across time.
238244

239-
***Other events / No active event:** In all other cases, return `MyRenderer.DefaultEventPriority`. This tells React that this event is considered background work, and interactive events will be prioritized over it.
245+
***Other events / No active event:** In all other cases, return `DefaultEventPriority`. This tells React that this event is considered background work, and interactive events will be prioritized over it.
240246

241247
You can consult the `getCurrentEventPriority()` implementation in `ReactDOMHostConfig.js` for a reference implementation.
242248

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
import{enableNewReconciler}from'shared/ReactFeatureFlags';
11+
12+
import{
13+
DiscreteEventPriorityasDiscreteEventPriority_old,
14+
ContinuousEventPriorityasContinuousEventPriority_old,
15+
DefaultEventPriorityasDefaultEventPriority_old,
16+
IdleEventPriorityasIdleEventPriority_old,
17+
}from'./ReactEventPriorities.old';
18+
19+
import{
20+
DiscreteEventPriorityasDiscreteEventPriority_new,
21+
ContinuousEventPriorityasContinuousEventPriority_new,
22+
DefaultEventPriorityasDefaultEventPriority_new,
23+
IdleEventPriorityasIdleEventPriority_new,
24+
}from'./ReactEventPriorities.new';
25+
26+
exportconstDiscreteEventPriority=enableNewReconciler
27+
? DiscreteEventPriority_new
28+
: DiscreteEventPriority_old;
29+
exportconstContinuousEventPriority=enableNewReconciler
30+
? ContinuousEventPriority_new
31+
: ContinuousEventPriority_old;
32+
exportconstDefaultEventPriority=enableNewReconciler
33+
? DefaultEventPriority_new
34+
: DefaultEventPriority_old;
35+
exportconstIdleEventPriority=enableNewReconciler
36+
? IdleEventPriority_new
37+
: IdleEventPriority_old;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
export{
11+
SyncLanePriorityasDiscreteEventPriority,
12+
InputContinuousLanePriorityasContinuousEventPriority,
13+
DefaultLanePriorityasDefaultEventPriority,
14+
IdleLanePriorityasIdleEventPriority,
15+
}from'./ReactFiberLane.new';
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
export{
11+
SyncLanePriorityasDiscreteEventPriority,
12+
InputContinuousLanePriorityasContinuousEventPriority,
13+
DefaultLanePriorityasDefaultEventPriority,
14+
IdleLanePriorityasIdleEventPriority,
15+
}from'./ReactFiberLane.old';

0 commit comments

Comments
 (0)