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

File tree

13 files changed

+129
-86
lines changed

13 files changed

+129
-86
lines changed

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
import Transform from 'art/core/transform';
99
import Mode from 'art/modes/current';
10-
import {enableNewReconciler} from 'shared/ReactFeatureFlags';
1110
import invariant from 'shared/invariant';
1211

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

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

2216
const pooledTransform = new Transform();
2317

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

349343
export function getCurrentEventPriority() {
350-
return DefaultLanePriority;
344+
return DefaultEventPriority;
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 {DefaultLanePriority as DefaultLanePriority_old} from 'react-reconciler/src/ReactFiberLane.old';
76-
import {DefaultLanePriority as DefaultLanePriority_new} from 'react-reconciler/src/ReactFiberLane.new';
77-
78-
const DefaultLanePriority = enableNewReconciler
79-
? DefaultLanePriority_new
80-
: DefaultLanePriority_old;
74+
import {DefaultEventPriority} from 'react-reconciler/src/ReactEventPriorities';
8175

8276
export type Type = string;
8377
export type Props = {
@@ -385,7 +379,7 @@ export function createTextInstance(
385379
export function getCurrentEventPriority(): * {
386380
const currentEvent = window.event;
387381
if (currentEvent === undefined) {
388-
return DefaultLanePriority;
382+
return DefaultEventPriority;
389383
}
390384
return getEventPriority(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
import type {Container, SuspenseInstance} from '../client/ReactDOMHostConfig';
1616
import type {DOMEventName} from '../events/DOMEventNames';
17+
import type {LanePriority} from 'react-reconciler/src/ReactFiberLane.new';
1718

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

5051
import {
5152
InputContinuousLanePriority as InputContinuousLanePriority_old,
52-
DefaultLanePriority as DefaultLanePriority_old,
5353
getCurrentUpdateLanePriority as getCurrentUpdateLanePriority_old,
5454
setCurrentUpdateLanePriority as setCurrentUpdateLanePriority_old,
5555
} from 'react-reconciler/src/ReactFiberLane.old';
5656
import {
5757
InputContinuousLanePriority as InputContinuousLanePriority_new,
58-
DefaultLanePriority as DefaultLanePriority_new,
5958
getCurrentUpdateLanePriority as getCurrentUpdateLanePriority_new,
6059
setCurrentUpdateLanePriority as setCurrentUpdateLanePriority_new,
61-
SyncLanePriority,
62-
IdleLanePriority,
63-
NoLanePriority,
6460
} from 'react-reconciler/src/ReactFiberLane.new';
6561
import {getCurrentPriorityLevel as getCurrentPriorityLevel_old} from 'react-reconciler/src/SchedulerWithReactIntegration.old';
6662
import {
@@ -71,14 +67,16 @@ import {
7167
NormalPriority as NormalSchedulerPriority,
7268
UserBlockingPriority as UserBlockingSchedulerPriority,
7369
} from 'react-reconciler/src/SchedulerWithReactIntegration.new';
74-
import type {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
const InputContinuousLanePriority = enableNewReconciler
7778
? InputContinuousLanePriority_new
7879
: InputContinuousLanePriority_old;
79-
const DefaultLanePriority = enableNewReconciler
80-
? DefaultLanePriority_new
81-
: DefaultLanePriority_old;
8280
const getCurrentUpdateLanePriority = enableNewReconciler
8381
? getCurrentUpdateLanePriority_new
8482
: getCurrentUpdateLanePriority_old;
@@ -94,17 +92,17 @@ function schedulerPriorityToLanePriority(
9492
): LanePriority {
9593
switch (schedulerPriorityLevel) {
9694
case ImmediateSchedulerPriority:
97-
return SyncLanePriority;
95+
return DiscreteEventPriority;
9896
case UserBlockingSchedulerPriority:
99-
return InputContinuousLanePriority;
97+
return ContinuousEventPriority;
10098
case NormalSchedulerPriority:
10199
case LowSchedulerPriority:
102100
// TODO: Handle LowSchedulerPriority, somehow. Maybe the same lane as hydration.
103-
return DefaultLanePriority;
101+
return DefaultEventPriority;
104102
case IdleSchedulerPriority:
105-
return IdleLanePriority;
103+
return IdleEventPriority;
106104
default:
107-
return NoLanePriority;
105+
return DefaultEventPriority;
108106
}
109107
}
110108

@@ -142,13 +140,13 @@ export function createEventListenerWrapperWithPriority(
142140
const eventPriority = getEventPriority(domEventName);
143141
let listenerWrapper;
144142
switch (eventPriority) {
145-
case SyncLanePriority:
143+
case DiscreteEventPriority:
146144
listenerWrapper = dispatchDiscreteEvent;
147145
break;
148-
case InputContinuousLanePriority:
146+
case ContinuousEventPriority:
149147
listenerWrapper = dispatchContinuousEvent;
150148
break;
151-
case DefaultLanePriority:
149+
case DefaultEventPriority:
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-
return SyncLanePriority;
408+
return DiscreteEventPriority;
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-
return InputContinuousLanePriority;
428+
return ContinuousEventPriority;
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
return schedulerPriorityToLanePriority(schedulerPriority);
437435
}
438436
default:
439-
return DefaultLanePriority;
437+
return DefaultEventPriority;
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
import invariant from 'shared/invariant';
2625

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

29-
import {DefaultLanePriority as DefaultLanePriority_old} from 'react-reconciler/src/ReactFiberLane.old';
30-
import {DefaultLanePriority as DefaultLanePriority_new} from 'react-reconciler/src/ReactFiberLane.new';
31-
32-
const DefaultLanePriority = 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
export function getCurrentEventPriority(): * {
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
import type {TouchedViewDataAtPoint} from './ReactNativeTypes';
1111

1212
import invariant from '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
import ReactNativeFiberHostComponent from './ReactNativeFiberHostComponent';
2928

30-
import {DefaultLanePriority as DefaultLanePriority_old} from 'react-reconciler/src/ReactFiberLane.old';
31-
import {DefaultLanePriority as DefaultLanePriority_new} from 'react-reconciler/src/ReactFiberLane.new';
32-
33-
const DefaultLanePriority = 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
export function getCurrentEventPriority(): * {
271-
return DefaultLanePriority;
265+
return DefaultEventPriority;
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
import enqueueTask from 'shared/enqueueTask';
2828
const {IsSomeRendererActing} = ReactSharedInternals;
2929

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

590-
let currentEventPriority = NoopRenderer.DefaultEventPriority;
593+
let currentEventPriority = DefaultEventPriority;
591594

592595
function childToJSX(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
const HostConfig = {
223229
// ...
224230
getCurrentEventPriority() {
225-
return MyRenderer.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+
DiscreteEventPriority as DiscreteEventPriority_old,
14+
ContinuousEventPriority as ContinuousEventPriority_old,
15+
DefaultEventPriority as DefaultEventPriority_old,
16+
IdleEventPriority as IdleEventPriority_old,
17+
} from './ReactEventPriorities.old';
18+
19+
import {
20+
DiscreteEventPriority as DiscreteEventPriority_new,
21+
ContinuousEventPriority as ContinuousEventPriority_new,
22+
DefaultEventPriority as DefaultEventPriority_new,
23+
IdleEventPriority as IdleEventPriority_new,
24+
} from './ReactEventPriorities.new';
25+
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;
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+
SyncLanePriority as DiscreteEventPriority,
12+
InputContinuousLanePriority as ContinuousEventPriority,
13+
DefaultLanePriority as DefaultEventPriority,
14+
IdleLanePriority as IdleEventPriority,
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+
SyncLanePriority as DiscreteEventPriority,
12+
InputContinuousLanePriority as ContinuousEventPriority,
13+
DefaultLanePriority as DefaultEventPriority,
14+
IdleLanePriority as IdleEventPriority,
15+
} from './ReactFiberLane.old';

packages/react-reconciler/src/ReactFiberReconciler.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ import {
5252
registerMutableSourceForHydration as registerMutableSourceForHydration_old,
5353
runWithPriority as runWithPriority_old,
5454
getCurrentUpdateLanePriority as getCurrentUpdateLanePriority_old,
55-
DefaultEventPriority as DefaultEventPriority_old,
56-
DiscreteEventPriority as DiscreteEventPriority_old,
57-
ContinuousEventPriority as ContinuousEventPriority_old,
58-
IdleEventPriority as IdleEventPriority_old,
5955
} from './ReactFiberReconciler.old';
6056

6157
import {
@@ -96,10 +92,6 @@ import {
9692
registerMutableSourceForHydration as registerMutableSourceForHydration_new,
9793
runWithPriority as runWithPriority_new,
9894
getCurrentUpdateLanePriority as getCurrentUpdateLanePriority_new,
99-
DefaultEventPriority as DefaultEventPriority_new,
100-
DiscreteEventPriority as DiscreteEventPriority_new,
101-
ContinuousEventPriority as ContinuousEventPriority_new,
102-
IdleEventPriority as IdleEventPriority_new,
10395
} from './ReactFiberReconciler.new';
10496

10597
export const createContainer = enableNewReconciler
@@ -176,18 +168,6 @@ export const createPortal = enableNewReconciler
176168
export const createComponentSelector = enableNewReconciler
177169
? createComponentSelector_new
178170
: createComponentSelector_old;
179-
export const DefaultEventPriority = enableNewReconciler
180-
? DefaultEventPriority_new
181-
: DefaultEventPriority_old;
182-
export const DiscreteEventPriority = enableNewReconciler
183-
? DiscreteEventPriority_new
184-
: DiscreteEventPriority_old;
185-
export const ContinuousEventPriority = enableNewReconciler
186-
? ContinuousEventPriority_new
187-
: ContinuousEventPriority_old;
188-
export const IdleEventPriority = enableNewReconciler
189-
? IdleEventPriority_new
190-
: IdleEventPriority_old;
191171

192172
//TODO: "psuedo" is spelled "pseudo"
193173
export const createHasPseudoClassSelector = enableNewReconciler

0 commit comments

Comments
 (0)