mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Make opaque EventPriority type a Lane internally (#21065)
Instead of LanePriority, we can use a Lane and skip the extra conversion. Eventually I want to get rid of LanePriority completely.
This commit is contained in:
+17
-25
@@ -8,13 +8,9 @@
|
||||
*/
|
||||
|
||||
import type {AnyNativeEvent} from '../events/PluginModuleType';
|
||||
import type {
|
||||
FiberRoot,
|
||||
ReactPriorityLevel,
|
||||
} from 'react-reconciler/src/ReactInternalTypes';
|
||||
import type {FiberRoot} 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,
|
||||
@@ -74,6 +70,8 @@ import {
|
||||
IdleEventPriority,
|
||||
} from 'react-reconciler/src/ReactEventPriorities';
|
||||
|
||||
// TODO: These should use the opaque EventPriority type instead of LanePriority.
|
||||
// Then internally we can use a Lane.
|
||||
const InputContinuousLanePriority = enableNewReconciler
|
||||
? InputContinuousLanePriority_new
|
||||
: InputContinuousLanePriority_old;
|
||||
@@ -87,25 +85,6 @@ const getCurrentPriorityLevel = enableNewReconciler
|
||||
? getCurrentPriorityLevel_new
|
||||
: getCurrentPriorityLevel_old;
|
||||
|
||||
function schedulerPriorityToLanePriority(
|
||||
schedulerPriorityLevel: ReactPriorityLevel,
|
||||
): LanePriority {
|
||||
switch (schedulerPriorityLevel) {
|
||||
case ImmediateSchedulerPriority:
|
||||
return DiscreteEventPriority;
|
||||
case UserBlockingSchedulerPriority:
|
||||
return ContinuousEventPriority;
|
||||
case NormalSchedulerPriority:
|
||||
case LowSchedulerPriority:
|
||||
// TODO: Handle LowSchedulerPriority, somehow. Maybe the same lane as hydration.
|
||||
return DefaultEventPriority;
|
||||
case IdleSchedulerPriority:
|
||||
return IdleEventPriority;
|
||||
default:
|
||||
return DefaultEventPriority;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: can we stop exporting these?
|
||||
export let _enabled = true;
|
||||
|
||||
@@ -431,7 +410,20 @@ export function getEventPriority(domEventName: DOMEventName): * {
|
||||
// Eventually this mechanism will be replaced by a check
|
||||
// of the current priority on the native scheduler.
|
||||
const schedulerPriority = getCurrentPriorityLevel();
|
||||
return schedulerPriorityToLanePriority(schedulerPriority);
|
||||
switch (schedulerPriority) {
|
||||
case ImmediateSchedulerPriority:
|
||||
return DiscreteEventPriority;
|
||||
case UserBlockingSchedulerPriority:
|
||||
return ContinuousEventPriority;
|
||||
case NormalSchedulerPriority:
|
||||
case LowSchedulerPriority:
|
||||
// TODO: Handle LowSchedulerPriority, somehow. Maybe the same lane as hydration.
|
||||
return DefaultEventPriority;
|
||||
case IdleSchedulerPriority:
|
||||
return IdleEventPriority;
|
||||
default:
|
||||
return DefaultEventPriority;
|
||||
}
|
||||
}
|
||||
default:
|
||||
return DefaultEventPriority;
|
||||
|
||||
+2
-1
@@ -23,6 +23,7 @@ import * as Scheduler from 'scheduler/unstable_mock';
|
||||
import {REACT_FRAGMENT_TYPE, REACT_ELEMENT_TYPE} from 'shared/ReactSymbols';
|
||||
import {
|
||||
DefaultEventPriority,
|
||||
IdleEventPriority,
|
||||
ConcurrentRoot,
|
||||
LegacyRoot,
|
||||
} from 'react-reconciler/constants';
|
||||
@@ -909,7 +910,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
|
||||
|
||||
idleUpdates<T>(fn: () => T): T {
|
||||
const prevEventPriority = currentEventPriority;
|
||||
currentEventPriority = NoopRenderer.IdleEventPriority;
|
||||
currentEventPriority = IdleEventPriority;
|
||||
try {
|
||||
fn();
|
||||
} finally {
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
*/
|
||||
|
||||
export {
|
||||
SyncLanePriority as DiscreteEventPriority,
|
||||
InputContinuousLanePriority as ContinuousEventPriority,
|
||||
DefaultLanePriority as DefaultEventPriority,
|
||||
IdleLanePriority as IdleEventPriority,
|
||||
SyncLane as DiscreteEventPriority,
|
||||
InputContinuousLane as ContinuousEventPriority,
|
||||
DefaultLane as DefaultEventPriority,
|
||||
IdleLane as IdleEventPriority,
|
||||
} from './ReactFiberLane.new';
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
*/
|
||||
|
||||
export {
|
||||
SyncLanePriority as DiscreteEventPriority,
|
||||
InputContinuousLanePriority as ContinuousEventPriority,
|
||||
DefaultLanePriority as DefaultEventPriority,
|
||||
IdleLanePriority as IdleEventPriority,
|
||||
SyncLane as DiscreteEventPriority,
|
||||
InputContinuousLane as ContinuousEventPriority,
|
||||
DefaultLane as DefaultEventPriority,
|
||||
IdleLane as IdleEventPriority,
|
||||
} from './ReactFiberLane.old';
|
||||
|
||||
@@ -118,7 +118,7 @@ export const SelectiveHydrationLane: Lane = /* */ 0b0001000000000000000
|
||||
const NonIdleLanes = /* */ 0b0001111111111111111111111111111;
|
||||
|
||||
export const IdleHydrationLane: Lane = /* */ 0b0010000000000000000000000000000;
|
||||
const IdleLane: Lanes = /* */ 0b0100000000000000000000000000000;
|
||||
export const IdleLane: Lanes = /* */ 0b0100000000000000000000000000000;
|
||||
|
||||
export const OffscreenLane: Lane = /* */ 0b1000000000000000000000000000000;
|
||||
|
||||
|
||||
@@ -118,7 +118,7 @@ export const SelectiveHydrationLane: Lane = /* */ 0b0001000000000000000
|
||||
const NonIdleLanes = /* */ 0b0001111111111111111111111111111;
|
||||
|
||||
export const IdleHydrationLane: Lane = /* */ 0b0010000000000000000000000000000;
|
||||
const IdleLane: Lanes = /* */ 0b0100000000000000000000000000000;
|
||||
export const IdleLane: Lanes = /* */ 0b0100000000000000000000000000000;
|
||||
|
||||
export const OffscreenLane: Lane = /* */ 0b1000000000000000000000000000000;
|
||||
|
||||
|
||||
@@ -93,16 +93,6 @@ import {
|
||||
} from './ReactFiberHotReloading.new';
|
||||
import {markRenderScheduled} from './SchedulingProfiler';
|
||||
|
||||
// Ideally host configs would import these constants from the reconciler
|
||||
// entry point, but we can't do this because of a circular dependency.
|
||||
// They are used by third-party renderers so they need to stay up to date.
|
||||
export {
|
||||
SyncLanePriority as DiscreteEventPriority,
|
||||
InputContinuousLanePriority as ContinuousEventPriority,
|
||||
DefaultLanePriority as DefaultEventPriority,
|
||||
IdleLanePriority as IdleEventPriority,
|
||||
} from './ReactFiberLane.new';
|
||||
|
||||
export {registerMutableSourceForHydration} from './ReactMutableSource.new';
|
||||
export {createPortal} from './ReactPortal';
|
||||
export {
|
||||
|
||||
@@ -93,16 +93,6 @@ import {
|
||||
} from './ReactFiberHotReloading.old';
|
||||
import {markRenderScheduled} from './SchedulingProfiler';
|
||||
|
||||
// Ideally host configs would import these constants from the reconciler
|
||||
// entry point, but we can't do this because of a circular dependency.
|
||||
// They are used by third-party renderers so they need to stay up to date.
|
||||
export {
|
||||
SyncLanePriority as DiscreteEventPriority,
|
||||
InputContinuousLanePriority as ContinuousEventPriority,
|
||||
DefaultLanePriority as DefaultEventPriority,
|
||||
IdleLanePriority as IdleEventPriority,
|
||||
} from './ReactFiberLane.old';
|
||||
|
||||
export {registerMutableSourceForHydration} from './ReactMutableSource.old';
|
||||
export {createPortal} from './ReactPortal';
|
||||
export {
|
||||
|
||||
@@ -436,8 +436,11 @@ export function requestUpdateLane(fiber: Fiber): Lane {
|
||||
|
||||
// This update originated outside React. Ask the host environement for an
|
||||
// appropriate priority, based on the type of event.
|
||||
const eventLanePriority = getCurrentEventPriority();
|
||||
return findUpdateLane(eventLanePriority);
|
||||
//
|
||||
// The opaque type returned by the host config is internally a lane, so we can
|
||||
// use that directly.
|
||||
const eventLane = getCurrentEventPriority();
|
||||
return eventLane;
|
||||
}
|
||||
|
||||
function requestRetryLane(fiber: Fiber) {
|
||||
|
||||
@@ -436,8 +436,11 @@ export function requestUpdateLane(fiber: Fiber): Lane {
|
||||
|
||||
// This update originated outside React. Ask the host environement for an
|
||||
// appropriate priority, based on the type of event.
|
||||
const eventLanePriority = getCurrentEventPriority();
|
||||
return findUpdateLane(eventLanePriority);
|
||||
//
|
||||
// The opaque type returned by the host config is internally a lane, so we can
|
||||
// use that directly.
|
||||
const eventLane = getCurrentEventPriority();
|
||||
return eventLane;
|
||||
}
|
||||
|
||||
function requestRetryLane(fiber: Fiber) {
|
||||
|
||||
@@ -14,5 +14,6 @@ export {
|
||||
DiscreteEventPriority,
|
||||
ContinuousEventPriority,
|
||||
DefaultEventPriority,
|
||||
IdleEventPriority,
|
||||
} from './ReactEventPriorities';
|
||||
export {ConcurrentRoot, LegacyRoot} from './ReactRootTags';
|
||||
|
||||
Reference in New Issue
Block a user