Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move priorities to separate import to break cycle #21060

Merged
merged 1 commit into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions packages/react-art/src/ReactARTHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,11 @@

import Transform from 'art/core/transform';
import Mode from 'art/modes/current';
import {enableNewReconciler} from 'shared/ReactFeatureFlags';
import invariant from 'shared/invariant';

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

import {DefaultLanePriority as DefaultLanePriority_old} from 'react-reconciler/src/ReactFiberLane.old';
import {DefaultLanePriority as DefaultLanePriority_new} from 'react-reconciler/src/ReactFiberLane.new';

const DefaultLanePriority = enableNewReconciler
? DefaultLanePriority_new
: DefaultLanePriority_old;
import {DefaultEventPriority} from 'react-reconciler/src/ReactEventPriorities';

const pooledTransform = new Transform();

Expand Down Expand Up @@ -347,7 +341,7 @@ export function shouldSetTextContent(type, props) {
}

export function getCurrentEventPriority() {
return DefaultLanePriority;
return DefaultEventPriority;
}

// The ART renderer is secondary to the React DOM renderer.
Expand Down
10 changes: 2 additions & 8 deletions packages/react-dom/src/client/ReactDOMHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,11 @@ import {
enableSuspenseServerRenderer,
enableCreateEventHandleAPI,
enableScopeAPI,
enableNewReconciler,
} from 'shared/ReactFeatureFlags';
import {HostComponent, HostText} from 'react-reconciler/src/ReactWorkTags';
import {listenToAllSupportedEvents} from '../events/DOMPluginEventSystem';

import {DefaultLanePriority as DefaultLanePriority_old} from 'react-reconciler/src/ReactFiberLane.old';
import {DefaultLanePriority as DefaultLanePriority_new} from 'react-reconciler/src/ReactFiberLane.new';

const DefaultLanePriority = enableNewReconciler
? DefaultLanePriority_new
: DefaultLanePriority_old;
import {DefaultEventPriority} from 'react-reconciler/src/ReactEventPriorities';

export type Type = string;
export type Props = {
Expand Down Expand Up @@ -385,7 +379,7 @@ export function createTextInstance(
export function getCurrentEventPriority(): * {
const currentEvent = window.event;
if (currentEvent === undefined) {
return DefaultLanePriority;
return DefaultEventPriority;
}
return getEventPriority(currentEvent.type);
}
Expand Down
38 changes: 18 additions & 20 deletions packages/react-dom/src/events/ReactDOMEventListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {
} from 'react-reconciler/src/ReactInternalTypes';
import type {Container, SuspenseInstance} from '../client/ReactDOMHostConfig';
import type {DOMEventName} from '../events/DOMEventNames';
import type {LanePriority} from 'react-reconciler/src/ReactFiberLane.new';

import {
isReplayableDiscreteEvent,
Expand Down Expand Up @@ -49,18 +50,13 @@ import {

import {
InputContinuousLanePriority as InputContinuousLanePriority_old,
DefaultLanePriority as DefaultLanePriority_old,
getCurrentUpdateLanePriority as getCurrentUpdateLanePriority_old,
setCurrentUpdateLanePriority as setCurrentUpdateLanePriority_old,
} from 'react-reconciler/src/ReactFiberLane.old';
import {
InputContinuousLanePriority as InputContinuousLanePriority_new,
DefaultLanePriority as DefaultLanePriority_new,
getCurrentUpdateLanePriority as getCurrentUpdateLanePriority_new,
setCurrentUpdateLanePriority as setCurrentUpdateLanePriority_new,
SyncLanePriority,
IdleLanePriority,
NoLanePriority,
} from 'react-reconciler/src/ReactFiberLane.new';
import {getCurrentPriorityLevel as getCurrentPriorityLevel_old} from 'react-reconciler/src/SchedulerWithReactIntegration.old';
import {
Expand All @@ -71,14 +67,16 @@ import {
NormalPriority as NormalSchedulerPriority,
UserBlockingPriority as UserBlockingSchedulerPriority,
} from 'react-reconciler/src/SchedulerWithReactIntegration.new';
import type {LanePriority} from 'react-reconciler/src/ReactFiberLane.new';
import {
DiscreteEventPriority,
ContinuousEventPriority,
DefaultEventPriority,
IdleEventPriority,
} from 'react-reconciler/src/ReactEventPriorities';

const InputContinuousLanePriority = enableNewReconciler
? InputContinuousLanePriority_new
: InputContinuousLanePriority_old;
const DefaultLanePriority = enableNewReconciler
? DefaultLanePriority_new
: DefaultLanePriority_old;
const getCurrentUpdateLanePriority = enableNewReconciler
? getCurrentUpdateLanePriority_new
: getCurrentUpdateLanePriority_old;
Expand All @@ -94,17 +92,17 @@ function schedulerPriorityToLanePriority(
): LanePriority {
switch (schedulerPriorityLevel) {
case ImmediateSchedulerPriority:
return SyncLanePriority;
return DiscreteEventPriority;
case UserBlockingSchedulerPriority:
return InputContinuousLanePriority;
return ContinuousEventPriority;
case NormalSchedulerPriority:
case LowSchedulerPriority:
// TODO: Handle LowSchedulerPriority, somehow. Maybe the same lane as hydration.
return DefaultLanePriority;
return DefaultEventPriority;
case IdleSchedulerPriority:
return IdleLanePriority;
return IdleEventPriority;
default:
return NoLanePriority;
return DefaultEventPriority;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This used to be NoLane, now it's DefaultLane. Any differences?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that was just a mistake before. NoLanePriority would get passed to findUpdateLane, which would throw:

export function findUpdateLane(lanePriority: LanePriority): Lane {
switch (lanePriority) {
case NoLanePriority:
break;
case SyncLanePriority:
return SyncLane;
case SyncBatchedLanePriority:
return SyncBatchedLane;
case InputContinuousLanePriority:
return InputContinuousLane;
case DefaultLanePriority:
return DefaultLane;
case TransitionPriority: // Should be handled by findTransitionLane instead
case RetryLanePriority: // Should be handled by findRetryLane instead
break;
case IdleLanePriority:
return IdleLane;
default:
// The remaining priorities are not valid for updates
break;
}
invariant(
false,
'Invalid update priority: %s. This is a bug in React.',
lanePriority,
);
}

I suppose we never hit this internally because we don't have any native event handlers that aren't part of the big switch.

I'll add a regression test as a follow up.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I'll address this in the next PR. We're about to remove the LanePriority type in favor of returning a lane directly.

}
}

Expand Down Expand Up @@ -142,13 +140,13 @@ export function createEventListenerWrapperWithPriority(
const eventPriority = getEventPriority(domEventName);
let listenerWrapper;
switch (eventPriority) {
case SyncLanePriority:
case DiscreteEventPriority:
listenerWrapper = dispatchDiscreteEvent;
break;
case InputContinuousLanePriority:
case ContinuousEventPriority:
listenerWrapper = dispatchContinuousEvent;
break;
case DefaultLanePriority:
case DefaultEventPriority:
default:
listenerWrapper = dispatchEvent;
break;
Expand Down Expand Up @@ -407,7 +405,7 @@ export function getEventPriority(domEventName: DOMEventName): * {
case 'popstate':
case 'select':
case 'selectstart':
return SyncLanePriority;
return DiscreteEventPriority;
case 'drag':
case 'dragenter':
case 'dragexit':
Expand All @@ -427,7 +425,7 @@ export function getEventPriority(domEventName: DOMEventName): * {
// eslint-disable-next-line no-fallthrough
case 'mouseenter':
case 'mouseleave':
return InputContinuousLanePriority;
return ContinuousEventPriority;
case 'message': {
// We might be in the Scheduler callback.
// Eventually this mechanism will be replaced by a check
Expand All @@ -436,6 +434,6 @@ export function getEventPriority(domEventName: DOMEventName): * {
return schedulerPriorityToLanePriority(schedulerPriority);
}
default:
return DefaultLanePriority;
return DefaultEventPriority;
}
}
10 changes: 2 additions & 8 deletions packages/react-native-renderer/src/ReactFabricHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,11 @@ import type {
import {mountSafeCallback_NOT_REALLY_SAFE} from './NativeMethodsMixinUtils';
import {create, diff} from './ReactNativeAttributePayload';

import {enableNewReconciler} from 'shared/ReactFeatureFlags';
import invariant from 'shared/invariant';

import {dispatchEvent} from './ReactFabricEventEmitter';

import {DefaultLanePriority as DefaultLanePriority_old} from 'react-reconciler/src/ReactFiberLane.old';
import {DefaultLanePriority as DefaultLanePriority_new} from 'react-reconciler/src/ReactFiberLane.new';

const DefaultLanePriority = enableNewReconciler
? DefaultLanePriority_new
: DefaultLanePriority_old;
import {DefaultEventPriority} from 'react-reconciler/src/ReactEventPriorities';

// Modules provided by RN:
import {
Expand Down Expand Up @@ -349,7 +343,7 @@ export function shouldSetTextContent(type: string, props: Props): boolean {
}

export function getCurrentEventPriority(): * {
return DefaultLanePriority;
return DefaultEventPriority;
}

// The Fabric renderer is secondary to the existing React Native renderer.
Expand Down
10 changes: 2 additions & 8 deletions packages/react-native-renderer/src/ReactNativeHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import type {TouchedViewDataAtPoint} from './ReactNativeTypes';

import invariant from 'shared/invariant';
import {enableNewReconciler} from 'shared/ReactFeatureFlags';

// Modules provided by RN:
import {
Expand All @@ -27,12 +26,7 @@ import {
} from './ReactNativeComponentTree';
import ReactNativeFiberHostComponent from './ReactNativeFiberHostComponent';

import {DefaultLanePriority as DefaultLanePriority_old} from 'react-reconciler/src/ReactFiberLane.old';
import {DefaultLanePriority as DefaultLanePriority_new} from 'react-reconciler/src/ReactFiberLane.new';

const DefaultLanePriority = enableNewReconciler
? DefaultLanePriority_new
: DefaultLanePriority_old;
import {DefaultEventPriority} from 'react-reconciler/src/ReactEventPriorities';

const {get: getViewConfigForType} = ReactNativeViewConfigRegistry;

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

export function getCurrentEventPriority(): * {
return DefaultLanePriority;
return DefaultEventPriority;
}

// -------------------
Expand Down
5 changes: 4 additions & 1 deletion packages/react-noop-renderer/src/createReactNoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import ReactSharedInternals from 'shared/ReactSharedInternals';
import enqueueTask from 'shared/enqueueTask';
const {IsSomeRendererActing} = ReactSharedInternals;

// TODO: Publish public entry point that exports the event priority constants
const DefaultEventPriority = 8;

type Container = {
rootID: string,
children: Array<Instance | TextInstance>,
Expand Down Expand Up @@ -587,7 +590,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
const roots = new Map();
const DEFAULT_ROOT_ID = '<default>';

let currentEventPriority = NoopRenderer.DefaultEventPriority;
let currentEventPriority = DefaultEventPriority;

function childToJSX(child, text) {
if (text !== null) {
Expand Down
14 changes: 10 additions & 4 deletions packages/react-reconciler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,16 @@ This is a property (not a function) that should be set to `true` if your rendere
To implement this method, you'll need some constants available on the _returned_ `Renderer` object:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence is no longer true


```js
import {
DiscreteEventPriority,
ContinuousEventPriority,
DefaultEventPriority,
} from './ReactFiberReconciler/src/ReactEventPriorities';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. How does this work? It doesn't exist in the open source npm package. Should this suggest to copy-paste from our repo?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll send a follow-up PR

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


const HostConfig = {
// ...
getCurrentEventPriority() {
return MyRenderer.DefaultEventPriority;
return DefaultEventPriority;
},
// ...
}
Expand All @@ -232,11 +238,11 @@ const MyRenderer = Reconciler(HostConfig);

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`).

* **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.
* **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.

* **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.
* **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.

* **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.
* **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.

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

Expand Down
37 changes: 37 additions & 0 deletions packages/react-reconciler/src/ReactEventPriorities.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import {enableNewReconciler} from 'shared/ReactFeatureFlags';

import {
DiscreteEventPriority as DiscreteEventPriority_old,
ContinuousEventPriority as ContinuousEventPriority_old,
DefaultEventPriority as DefaultEventPriority_old,
IdleEventPriority as IdleEventPriority_old,
} from './ReactEventPriorities.old';

import {
DiscreteEventPriority as DiscreteEventPriority_new,
ContinuousEventPriority as ContinuousEventPriority_new,
DefaultEventPriority as DefaultEventPriority_new,
IdleEventPriority as IdleEventPriority_new,
} from './ReactEventPriorities.new';

export const DiscreteEventPriority = enableNewReconciler
? DiscreteEventPriority_new
: DiscreteEventPriority_old;
export const ContinuousEventPriority = enableNewReconciler
? ContinuousEventPriority_new
: ContinuousEventPriority_old;
export const DefaultEventPriority = enableNewReconciler
? DefaultEventPriority_new
: DefaultEventPriority_old;
export const IdleEventPriority = enableNewReconciler
? IdleEventPriority_new
: IdleEventPriority_old;
15 changes: 15 additions & 0 deletions packages/react-reconciler/src/ReactEventPriorities.new.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

export {
SyncLanePriority as DiscreteEventPriority,
InputContinuousLanePriority as ContinuousEventPriority,
DefaultLanePriority as DefaultEventPriority,
IdleLanePriority as IdleEventPriority,
} from './ReactFiberLane.new';
15 changes: 15 additions & 0 deletions packages/react-reconciler/src/ReactEventPriorities.old.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

export {
SyncLanePriority as DiscreteEventPriority,
InputContinuousLanePriority as ContinuousEventPriority,
DefaultLanePriority as DefaultEventPriority,
IdleLanePriority as IdleEventPriority,
} from './ReactFiberLane.old';
20 changes: 0 additions & 20 deletions packages/react-reconciler/src/ReactFiberReconciler.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ import {
registerMutableSourceForHydration as registerMutableSourceForHydration_old,
runWithPriority as runWithPriority_old,
getCurrentUpdateLanePriority as getCurrentUpdateLanePriority_old,
DefaultEventPriority as DefaultEventPriority_old,
DiscreteEventPriority as DiscreteEventPriority_old,
ContinuousEventPriority as ContinuousEventPriority_old,
IdleEventPriority as IdleEventPriority_old,
} from './ReactFiberReconciler.old';

import {
Expand Down Expand Up @@ -96,10 +92,6 @@ import {
registerMutableSourceForHydration as registerMutableSourceForHydration_new,
runWithPriority as runWithPriority_new,
getCurrentUpdateLanePriority as getCurrentUpdateLanePriority_new,
DefaultEventPriority as DefaultEventPriority_new,
DiscreteEventPriority as DiscreteEventPriority_new,
ContinuousEventPriority as ContinuousEventPriority_new,
IdleEventPriority as IdleEventPriority_new,
} from './ReactFiberReconciler.new';

export const createContainer = enableNewReconciler
Expand Down Expand Up @@ -176,18 +168,6 @@ export const createPortal = enableNewReconciler
export const createComponentSelector = enableNewReconciler
? createComponentSelector_new
: createComponentSelector_old;
export const DefaultEventPriority = enableNewReconciler
? DefaultEventPriority_new
: DefaultEventPriority_old;
export const DiscreteEventPriority = enableNewReconciler
? DiscreteEventPriority_new
: DiscreteEventPriority_old;
export const ContinuousEventPriority = enableNewReconciler
? ContinuousEventPriority_new
: ContinuousEventPriority_old;
export const IdleEventPriority = enableNewReconciler
? IdleEventPriority_new
: IdleEventPriority_old;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We currently reference these values in README. If we're removing them, can you update the README with a recommendation of what to do? E.g. just hardcoding numbers or telling people to look at this particular file. https://github.com/facebook/react/blob/master/packages/react-reconciler/README.md#getcurrenteventpriority


//TODO: "psuedo" is spelled "pseudo"
export const createHasPseudoClassSelector = enableNewReconciler
Expand Down
Loading