From 9a457da6581d4dac8feee30444c6d039fb3b6e9d Mon Sep 17 00:00:00 2001 From: Paul Doyle Date: Sun, 8 Nov 2020 22:40:10 -0800 Subject: [PATCH 1/3] Remove cycle between ReactFiberLane, SchedulerWithReactIntegartion, ReactInternalTypes. Necessitates making the Lane types non-opaque, very difficult to disentangle otherwise. --- .../src/ReactFiberHooks.old.js | 5 ++-- .../react-reconciler/src/ReactFiberLane.js | 30 ++++--------------- .../src/ReactFiberSchedulerPriorities.js | 22 ++++++++++++++ .../src/ReactFiberWorkLoop.old.js | 10 ++++--- .../src/ReactInternalTypes.js | 27 +++++++++++++++-- .../src/SchedulerWithReactIntegration.old.js | 19 +++++------- 6 files changed, 68 insertions(+), 45 deletions(-) create mode 100644 packages/react-reconciler/src/ReactFiberSchedulerPriorities.js diff --git a/packages/react-reconciler/src/ReactFiberHooks.old.js b/packages/react-reconciler/src/ReactFiberHooks.old.js index 98e5d709cd285..241f67ed23b37 100644 --- a/packages/react-reconciler/src/ReactFiberHooks.old.js +++ b/packages/react-reconciler/src/ReactFiberHooks.old.js @@ -13,10 +13,9 @@ import type { MutableSourceSubscribeFn, ReactContext, } from 'shared/ReactTypes'; -import type {Fiber, Dispatcher, HookType} from './ReactInternalTypes'; +import type {Fiber, Dispatcher, HookType, ReactPriorityLevel} from './ReactInternalTypes'; import type {Lanes, Lane} from './ReactFiberLane'; import type {HookFlags} from './ReactHookEffectTags'; -import type {ReactPriorityLevel} from './ReactInternalTypes'; import type {FiberRoot} from './ReactInternalTypes'; import type {OpaqueIDType} from './ReactFiberHostConfig'; @@ -72,6 +71,8 @@ import {markWorkInProgressReceivedUpdate} from './ReactFiberBeginWork.old'; import { UserBlockingPriority, NormalPriority, +} from './ReactFiberSchedulerPriorities'; +import { runWithPriority, getCurrentPriorityLevel, } from './SchedulerWithReactIntegration.old'; diff --git a/packages/react-reconciler/src/ReactFiberLane.js b/packages/react-reconciler/src/ReactFiberLane.js index 027754dd76ee0..5fcf76cad634f 100644 --- a/packages/react-reconciler/src/ReactFiberLane.js +++ b/packages/react-reconciler/src/ReactFiberLane.js @@ -7,30 +7,10 @@ * @flow */ -import type {FiberRoot, ReactPriorityLevel} from './ReactInternalTypes'; - -export opaque type LanePriority = - | 0 - | 1 - | 2 - | 3 - | 4 - | 5 - | 6 - | 7 - | 8 - | 9 - | 10 - | 11 - | 12 - | 13 - | 14 - | 15 - | 16 - | 17; -export opaque type Lanes = number; -export opaque type Lane = number; -export opaque type LaneMap = Array; +import type {FiberRoot, ReactPriorityLevel, Lane, LanePriority, LaneMap, Lanes} from './ReactInternalTypes'; + +// unwind-cycles: Re-export lane definitions here +export type {Lane, LanePriority, LaneMap, Lanes}; import invariant from 'shared/invariant'; @@ -41,7 +21,7 @@ import { LowPriority as LowSchedulerPriority, IdlePriority as IdleSchedulerPriority, NoPriority as NoSchedulerPriority, -} from './SchedulerWithReactIntegration.new'; +} from './ReactFiberSchedulerPriorities'; export const SyncLanePriority: LanePriority = 15; export const SyncBatchedLanePriority: LanePriority = 14; diff --git a/packages/react-reconciler/src/ReactFiberSchedulerPriorities.js b/packages/react-reconciler/src/ReactFiberSchedulerPriorities.js new file mode 100644 index 0000000000000..6499267c4af2d --- /dev/null +++ b/packages/react-reconciler/src/ReactFiberSchedulerPriorities.js @@ -0,0 +1,22 @@ +/** + * 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 + */ + +// unwind-cycles: Extract type and constant definitions to common dependency +export type ReactPriorityLevel = 99 | 98 | 97 | 96 | 95 | 90; + +// Except for NoPriority, these correspond to Scheduler priorities. We use +// ascending numbers so we can compare them like numbers. They start at 90 to +// avoid clashing with Scheduler's priorities. +export const ImmediatePriority: ReactPriorityLevel = 99; +export const UserBlockingPriority: ReactPriorityLevel = 98; +export const NormalPriority: ReactPriorityLevel = 97; +export const LowPriority: ReactPriorityLevel = 96; +export const IdlePriority: ReactPriorityLevel = 95; +// NoPriority is the absence of priority. Also React-only. +export const NoPriority: ReactPriorityLevel = 90; diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.old.js b/packages/react-reconciler/src/ReactFiberWorkLoop.old.js index b4852f120db94..1c03ff484a62f 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.old.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.old.js @@ -35,6 +35,12 @@ import { import ReactSharedInternals from 'shared/ReactSharedInternals'; import invariant from 'shared/invariant'; +import { + NoPriority as NoSchedulerPriority, + ImmediatePriority as ImmediateSchedulerPriority, + UserBlockingPriority as UserBlockingSchedulerPriority, + NormalPriority as NormalSchedulerPriority, +} from './ReactFiberSchedulerPriorities'; import { scheduleCallback, cancelCallback, @@ -43,10 +49,6 @@ import { shouldYield, requestPaint, now, - NoPriority as NoSchedulerPriority, - ImmediatePriority as ImmediateSchedulerPriority, - UserBlockingPriority as UserBlockingSchedulerPriority, - NormalPriority as NormalSchedulerPriority, flushSyncCallbackQueue, scheduleSyncCallback, } from './SchedulerWithReactIntegration.old'; diff --git a/packages/react-reconciler/src/ReactInternalTypes.js b/packages/react-reconciler/src/ReactInternalTypes.js index f63495cdce655..576b68ebc0867 100644 --- a/packages/react-reconciler/src/ReactInternalTypes.js +++ b/packages/react-reconciler/src/ReactInternalTypes.js @@ -20,13 +20,13 @@ import type {SuspenseInstance} from './ReactFiberHostConfig'; import type {WorkTag} from './ReactWorkTags'; import type {TypeOfMode} from './ReactTypeOfMode'; import type {Flags} from './ReactFiberFlags'; -import type {Lane, LanePriority, Lanes, LaneMap} from './ReactFiberLane'; import type {RootTag} from './ReactRootTags'; import type {TimeoutHandle, NoTimeout} from './ReactFiberHostConfig'; import type {Wakeable} from 'shared/ReactTypes'; import type {Interaction} from 'scheduler/src/Tracing'; -// Unwind Circular: moved from ReactFiberHooks.old +export type {ReactPriorityLevel} from './ReactFiberSchedulerPriorities'; + export type HookType = | 'useState' | 'useReducer' @@ -43,7 +43,28 @@ export type HookType = | 'useMutableSource' | 'useOpaqueIdentifier'; -export type ReactPriorityLevel = 99 | 98 | 97 | 96 | 95 | 90; +export type LanePriority = + | 0 + | 1 + | 2 + | 3 + | 4 + | 5 + | 6 + | 7 + | 8 + | 9 + | 10 + | 11 + | 12 + | 13 + | 14 + | 15 + | 16 + | 17; +export type Lanes = number; +export type Lane = number; +export type LaneMap = Array; export type ContextDependency = { context: ReactContext, diff --git a/packages/react-reconciler/src/SchedulerWithReactIntegration.old.js b/packages/react-reconciler/src/SchedulerWithReactIntegration.old.js index 606a90252077e..bf209bc913478 100644 --- a/packages/react-reconciler/src/SchedulerWithReactIntegration.old.js +++ b/packages/react-reconciler/src/SchedulerWithReactIntegration.old.js @@ -8,6 +8,14 @@ */ import type {ReactPriorityLevel} from './ReactInternalTypes'; +import { + ImmediatePriority, + UserBlockingPriority, + NormalPriority, + LowPriority, + IdlePriority, + NoPriority, +} from './ReactFiberSchedulerPriorities'; // Intentionally not named imports because Rollup would use dynamic dispatch for // CommonJS interop named imports. @@ -59,17 +67,6 @@ type SchedulerCallbackOptions = {timeout?: number, ...}; const fakeCallbackNode = {}; -// Except for NoPriority, these correspond to Scheduler priorities. We use -// ascending numbers so we can compare them like numbers. They start at 90 to -// avoid clashing with Scheduler's priorities. -export const ImmediatePriority: ReactPriorityLevel = 99; -export const UserBlockingPriority: ReactPriorityLevel = 98; -export const NormalPriority: ReactPriorityLevel = 97; -export const LowPriority: ReactPriorityLevel = 96; -export const IdlePriority: ReactPriorityLevel = 95; -// NoPriority is the absence of priority. Also React-only. -export const NoPriority: ReactPriorityLevel = 90; - export const shouldYield = Scheduler_shouldYield; export const requestPaint = // Fall back gracefully if we're running an older version of Scheduler. From a692fab1c965d1cecfff7186e600b89942559016 Mon Sep 17 00:00:00 2001 From: Paul Doyle Date: Fri, 13 Nov 2020 15:22:19 -0800 Subject: [PATCH 2/3] Run lint and prettier --- packages/react-reconciler/src/ReactFiberHooks.old.js | 7 ++++++- packages/react-reconciler/src/ReactFiberLane.js | 9 ++++++++- .../src/SchedulerWithReactIntegration.old.js | 1 - 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/react-reconciler/src/ReactFiberHooks.old.js b/packages/react-reconciler/src/ReactFiberHooks.old.js index 241f67ed23b37..95a805342f6e9 100644 --- a/packages/react-reconciler/src/ReactFiberHooks.old.js +++ b/packages/react-reconciler/src/ReactFiberHooks.old.js @@ -13,7 +13,12 @@ import type { MutableSourceSubscribeFn, ReactContext, } from 'shared/ReactTypes'; -import type {Fiber, Dispatcher, HookType, ReactPriorityLevel} from './ReactInternalTypes'; +import type { + Fiber, + Dispatcher, + HookType, + ReactPriorityLevel, +} from './ReactInternalTypes'; import type {Lanes, Lane} from './ReactFiberLane'; import type {HookFlags} from './ReactHookEffectTags'; import type {FiberRoot} from './ReactInternalTypes'; diff --git a/packages/react-reconciler/src/ReactFiberLane.js b/packages/react-reconciler/src/ReactFiberLane.js index 5fcf76cad634f..c9a900fbf7cc2 100644 --- a/packages/react-reconciler/src/ReactFiberLane.js +++ b/packages/react-reconciler/src/ReactFiberLane.js @@ -7,7 +7,14 @@ * @flow */ -import type {FiberRoot, ReactPriorityLevel, Lane, LanePriority, LaneMap, Lanes} from './ReactInternalTypes'; +import type { + FiberRoot, + ReactPriorityLevel, + Lane, + LanePriority, + LaneMap, + Lanes, +} from './ReactInternalTypes'; // unwind-cycles: Re-export lane definitions here export type {Lane, LanePriority, LaneMap, Lanes}; diff --git a/packages/react-reconciler/src/SchedulerWithReactIntegration.old.js b/packages/react-reconciler/src/SchedulerWithReactIntegration.old.js index bf209bc913478..9fc93b418011f 100644 --- a/packages/react-reconciler/src/SchedulerWithReactIntegration.old.js +++ b/packages/react-reconciler/src/SchedulerWithReactIntegration.old.js @@ -14,7 +14,6 @@ import { NormalPriority, LowPriority, IdlePriority, - NoPriority, } from './ReactFiberSchedulerPriorities'; // Intentionally not named imports because Rollup would use dynamic dispatch for From f580128ea11a551fd7004992bd2c4d1d5f1b1232 Mon Sep 17 00:00:00 2001 From: Paul Doyle Date: Fri, 13 Nov 2020 17:06:56 -0800 Subject: [PATCH 3/3] Rename file, remove some unhelpful comments --- packages/react-reconciler/src/ReactFiberHooks.old.js | 5 +---- packages/react-reconciler/src/ReactFiberLane.js | 3 +-- packages/react-reconciler/src/ReactFiberWorkLoop.old.js | 2 +- packages/react-reconciler/src/ReactInternalTypes.js | 2 +- ...eactFiberSchedulerPriorities.js => ReactPriorityLevel.js} | 1 - .../src/SchedulerWithReactIntegration.old.js | 2 +- 6 files changed, 5 insertions(+), 10 deletions(-) rename packages/react-reconciler/src/{ReactFiberSchedulerPriorities.js => ReactPriorityLevel.js} (91%) diff --git a/packages/react-reconciler/src/ReactFiberHooks.old.js b/packages/react-reconciler/src/ReactFiberHooks.old.js index 95a805342f6e9..8e47dfba7d7cc 100644 --- a/packages/react-reconciler/src/ReactFiberHooks.old.js +++ b/packages/react-reconciler/src/ReactFiberHooks.old.js @@ -73,10 +73,7 @@ import invariant from 'shared/invariant'; import getComponentName from 'shared/getComponentName'; import is from 'shared/objectIs'; import {markWorkInProgressReceivedUpdate} from './ReactFiberBeginWork.old'; -import { - UserBlockingPriority, - NormalPriority, -} from './ReactFiberSchedulerPriorities'; +import {UserBlockingPriority, NormalPriority} from './ReactPriorityLevel'; import { runWithPriority, getCurrentPriorityLevel, diff --git a/packages/react-reconciler/src/ReactFiberLane.js b/packages/react-reconciler/src/ReactFiberLane.js index c9a900fbf7cc2..2cf0725c4af14 100644 --- a/packages/react-reconciler/src/ReactFiberLane.js +++ b/packages/react-reconciler/src/ReactFiberLane.js @@ -16,7 +16,6 @@ import type { Lanes, } from './ReactInternalTypes'; -// unwind-cycles: Re-export lane definitions here export type {Lane, LanePriority, LaneMap, Lanes}; import invariant from 'shared/invariant'; @@ -28,7 +27,7 @@ import { LowPriority as LowSchedulerPriority, IdlePriority as IdleSchedulerPriority, NoPriority as NoSchedulerPriority, -} from './ReactFiberSchedulerPriorities'; +} from './ReactPriorityLevel'; export const SyncLanePriority: LanePriority = 15; export const SyncBatchedLanePriority: LanePriority = 14; diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.old.js b/packages/react-reconciler/src/ReactFiberWorkLoop.old.js index 1c03ff484a62f..ae05723d6a61c 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.old.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.old.js @@ -40,7 +40,7 @@ import { ImmediatePriority as ImmediateSchedulerPriority, UserBlockingPriority as UserBlockingSchedulerPriority, NormalPriority as NormalSchedulerPriority, -} from './ReactFiberSchedulerPriorities'; +} from './ReactPriorityLevel'; import { scheduleCallback, cancelCallback, diff --git a/packages/react-reconciler/src/ReactInternalTypes.js b/packages/react-reconciler/src/ReactInternalTypes.js index 576b68ebc0867..cc7ff0dc1e979 100644 --- a/packages/react-reconciler/src/ReactInternalTypes.js +++ b/packages/react-reconciler/src/ReactInternalTypes.js @@ -25,7 +25,7 @@ import type {TimeoutHandle, NoTimeout} from './ReactFiberHostConfig'; import type {Wakeable} from 'shared/ReactTypes'; import type {Interaction} from 'scheduler/src/Tracing'; -export type {ReactPriorityLevel} from './ReactFiberSchedulerPriorities'; +export type {ReactPriorityLevel} from './ReactPriorityLevel'; export type HookType = | 'useState' diff --git a/packages/react-reconciler/src/ReactFiberSchedulerPriorities.js b/packages/react-reconciler/src/ReactPriorityLevel.js similarity index 91% rename from packages/react-reconciler/src/ReactFiberSchedulerPriorities.js rename to packages/react-reconciler/src/ReactPriorityLevel.js index 6499267c4af2d..ef6afc6402968 100644 --- a/packages/react-reconciler/src/ReactFiberSchedulerPriorities.js +++ b/packages/react-reconciler/src/ReactPriorityLevel.js @@ -7,7 +7,6 @@ * @flow */ -// unwind-cycles: Extract type and constant definitions to common dependency export type ReactPriorityLevel = 99 | 98 | 97 | 96 | 95 | 90; // Except for NoPriority, these correspond to Scheduler priorities. We use diff --git a/packages/react-reconciler/src/SchedulerWithReactIntegration.old.js b/packages/react-reconciler/src/SchedulerWithReactIntegration.old.js index 9fc93b418011f..5ff5e16cec780 100644 --- a/packages/react-reconciler/src/SchedulerWithReactIntegration.old.js +++ b/packages/react-reconciler/src/SchedulerWithReactIntegration.old.js @@ -14,7 +14,7 @@ import { NormalPriority, LowPriority, IdlePriority, -} from './ReactFiberSchedulerPriorities'; +} from './ReactPriorityLevel'; // Intentionally not named imports because Rollup would use dynamic dispatch for // CommonJS interop named imports.