GeezerVison is showing github.com — Move priorities to separate import to break cycle (#21060) · react/react@d0eaf78
File treeExpand file treeCollapse file tree Open diff view settings react-native-renderer/src
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-art/src/ReactARTHostConfig.js +2-8Lines changed: 2 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 7 | 7 |
| 8 | 8 | import Transform from 'art/core/transform'; | 9 | 9 | import Mode from 'art/modes/current'; | 10 | | -import {enableNewReconciler} from 'shared/ReactFeatureFlags'; | 11 | 10 | import invariant from 'shared/invariant'; | 12 | 11 |
| 13 | 12 | import {TYPES, EVENT_TYPES, childrenAsString} from './ReactARTInternals'; | 14 | 13 |
| 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'; | 21 | 15 |
| 22 | 16 | const pooledTransform = new Transform(); | 23 | 17 |
| @@ -347,7 +341,7 @@ export function shouldSetTextContent(type, props) { | 347 | 341 | } | 348 | 342 |
| 349 | 343 | export function getCurrentEventPriority() { | 350 | | - return DefaultLanePriority; | | 344 | + return DefaultEventPriority; | 351 | 345 | } | 352 | 346 |
| 353 | 347 | // The ART renderer is secondary to the React DOM renderer. | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/client/ReactDOMHostConfig.js +2-8Lines changed: 2 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -67,17 +67,11 @@ import { | 67 | 67 | enableSuspenseServerRenderer, | 68 | 68 | enableCreateEventHandleAPI, | 69 | 69 | enableScopeAPI, | 70 | | - enableNewReconciler, | 71 | 70 | } from 'shared/ReactFeatureFlags'; | 72 | 71 | import {HostComponent, HostText} from 'react-reconciler/src/ReactWorkTags'; | 73 | 72 | import {listenToAllSupportedEvents} from '../events/DOMPluginEventSystem'; | 74 | 73 |
| 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'; | 81 | 75 |
| 82 | 76 | export type Type = string; | 83 | 77 | export type Props = { | @@ -385,7 +379,7 @@ export function createTextInstance( | 385 | 379 | export function getCurrentEventPriority(): * { | 386 | 380 | const currentEvent = window.event; | 387 | 381 | if (currentEvent === undefined) { | 388 | | - return DefaultLanePriority; | | 382 | + return DefaultEventPriority; | 389 | 383 | } | 390 | 384 | return getEventPriority(currentEvent.type); | 391 | 385 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/events/ReactDOMEventListener.js +18-20Lines changed: 18 additions & 20 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -14,6 +14,7 @@ import type { | 14 | 14 | } from 'react-reconciler/src/ReactInternalTypes'; | 15 | 15 | import type {Container, SuspenseInstance} from '../client/ReactDOMHostConfig'; | 16 | 16 | import type {DOMEventName} from '../events/DOMEventNames'; | | 17 | +import type {LanePriority} from 'react-reconciler/src/ReactFiberLane.new'; | 17 | 18 |
| 18 | 19 | import { | 19 | 20 | isReplayableDiscreteEvent, | @@ -49,18 +50,13 @@ import { | 49 | 50 |
| 50 | 51 | import { | 51 | 52 | InputContinuousLanePriority as InputContinuousLanePriority_old, | 52 | | - DefaultLanePriority as DefaultLanePriority_old, | 53 | 53 | getCurrentUpdateLanePriority as getCurrentUpdateLanePriority_old, | 54 | 54 | setCurrentUpdateLanePriority as setCurrentUpdateLanePriority_old, | 55 | 55 | } from 'react-reconciler/src/ReactFiberLane.old'; | 56 | 56 | import { | 57 | 57 | InputContinuousLanePriority as InputContinuousLanePriority_new, | 58 | | - DefaultLanePriority as DefaultLanePriority_new, | 59 | 58 | getCurrentUpdateLanePriority as getCurrentUpdateLanePriority_new, | 60 | 59 | setCurrentUpdateLanePriority as setCurrentUpdateLanePriority_new, | 61 | | - SyncLanePriority, | 62 | | - IdleLanePriority, | 63 | | - NoLanePriority, | 64 | 60 | } from 'react-reconciler/src/ReactFiberLane.new'; | 65 | 61 | import {getCurrentPriorityLevel as getCurrentPriorityLevel_old} from 'react-reconciler/src/SchedulerWithReactIntegration.old'; | 66 | 62 | import { | @@ -71,14 +67,16 @@ import { | 71 | 67 | NormalPriority as NormalSchedulerPriority, | 72 | 68 | UserBlockingPriority as UserBlockingSchedulerPriority, | 73 | 69 | } 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'; | 75 | 76 |
| 76 | 77 | const InputContinuousLanePriority = enableNewReconciler | 77 | 78 | ? InputContinuousLanePriority_new | 78 | 79 | : InputContinuousLanePriority_old; | 79 | | -const DefaultLanePriority = enableNewReconciler | 80 | | - ? DefaultLanePriority_new | 81 | | - : DefaultLanePriority_old; | 82 | 80 | const getCurrentUpdateLanePriority = enableNewReconciler | 83 | 81 | ? getCurrentUpdateLanePriority_new | 84 | 82 | : getCurrentUpdateLanePriority_old; | @@ -94,17 +92,17 @@ function schedulerPriorityToLanePriority( | 94 | 92 | ): LanePriority { | 95 | 93 | switch (schedulerPriorityLevel) { | 96 | 94 | case ImmediateSchedulerPriority: | 97 | | - return SyncLanePriority; | | 95 | + return DiscreteEventPriority; | 98 | 96 | case UserBlockingSchedulerPriority: | 99 | | - return InputContinuousLanePriority; | | 97 | + return ContinuousEventPriority; | 100 | 98 | case NormalSchedulerPriority: | 101 | 99 | case LowSchedulerPriority: | 102 | 100 | // TODO: Handle LowSchedulerPriority, somehow. Maybe the same lane as hydration. | 103 | | - return DefaultLanePriority; | | 101 | + return DefaultEventPriority; | 104 | 102 | case IdleSchedulerPriority: | 105 | | - return IdleLanePriority; | | 103 | + return IdleEventPriority; | 106 | 104 | default: | 107 | | - return NoLanePriority; | | 105 | + return DefaultEventPriority; | 108 | 106 | } | 109 | 107 | } | 110 | 108 |
| @@ -142,13 +140,13 @@ export function createEventListenerWrapperWithPriority( | 142 | 140 | const eventPriority = getEventPriority(domEventName); | 143 | 141 | let listenerWrapper; | 144 | 142 | switch (eventPriority) { | 145 | | - case SyncLanePriority: | | 143 | + case DiscreteEventPriority: | 146 | 144 | listenerWrapper = dispatchDiscreteEvent; | 147 | 145 | break; | 148 | | - case InputContinuousLanePriority: | | 146 | + case ContinuousEventPriority: | 149 | 147 | listenerWrapper = dispatchContinuousEvent; | 150 | 148 | break; | 151 | | - case DefaultLanePriority: | | 149 | + case DefaultEventPriority: | 152 | 150 | default: | 153 | 151 | listenerWrapper = dispatchEvent; | 154 | 152 | break; | @@ -407,7 +405,7 @@ export function getEventPriority(domEventName: DOMEventName): * { | 407 | 405 | case 'popstate': | 408 | 406 | case 'select': | 409 | 407 | case 'selectstart': | 410 | | - return SyncLanePriority; | | 408 | + return DiscreteEventPriority; | 411 | 409 | case 'drag': | 412 | 410 | case 'dragenter': | 413 | 411 | case 'dragexit': | @@ -427,7 +425,7 @@ export function getEventPriority(domEventName: DOMEventName): * { | 427 | 425 | // eslint-disable-next-line no-fallthrough | 428 | 426 | case 'mouseenter': | 429 | 427 | case 'mouseleave': | 430 | | - return InputContinuousLanePriority; | | 428 | + return ContinuousEventPriority; | 431 | 429 | case 'message': { | 432 | 430 | // We might be in the Scheduler callback. | 433 | 431 | // Eventually this mechanism will be replaced by a check | @@ -436,6 +434,6 @@ export function getEventPriority(domEventName: DOMEventName): * { | 436 | 434 | return schedulerPriorityToLanePriority(schedulerPriority); | 437 | 435 | } | 438 | 436 | default: | 439 | | - return DefaultLanePriority; | | 437 | + return DefaultEventPriority; | 440 | 438 | } | 441 | 439 | } |
Collapse file Copy file name to clipboardExpand all lines: packages/react-native-renderer/src/ReactFabricHostConfig.js +2-8Lines changed: 2 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -21,17 +21,11 @@ import type { | 21 | 21 | import {mountSafeCallback_NOT_REALLY_SAFE} from './NativeMethodsMixinUtils'; | 22 | 22 | import {create, diff} from './ReactNativeAttributePayload'; | 23 | 23 |
| 24 | | -import {enableNewReconciler} from 'shared/ReactFeatureFlags'; | 25 | 24 | import invariant from 'shared/invariant'; | 26 | 25 |
| 27 | 26 | import {dispatchEvent} from './ReactFabricEventEmitter'; | 28 | 27 |
| 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'; | 35 | 29 |
| 36 | 30 | // Modules provided by RN: | 37 | 31 | import { | @@ -349,7 +343,7 @@ export function shouldSetTextContent(type: string, props: Props): boolean { | 349 | 343 | } | 350 | 344 |
| 351 | 345 | export function getCurrentEventPriority(): * { | 352 | | - return DefaultLanePriority; | | 346 | + return DefaultEventPriority; | 353 | 347 | } | 354 | 348 |
| 355 | 349 | // The Fabric renderer is secondary to the existing React Native renderer. | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-native-renderer/src/ReactNativeHostConfig.js +2-8Lines changed: 2 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 10 | 10 | import type {TouchedViewDataAtPoint} from './ReactNativeTypes'; | 11 | 11 |
| 12 | 12 | import invariant from 'shared/invariant'; | 13 | | -import {enableNewReconciler} from 'shared/ReactFeatureFlags'; | 14 | 13 |
| 15 | 14 | // Modules provided by RN: | 16 | 15 | import { | @@ -27,12 +26,7 @@ import { | 27 | 26 | } from './ReactNativeComponentTree'; | 28 | 27 | import ReactNativeFiberHostComponent from './ReactNativeFiberHostComponent'; | 29 | 28 |
| 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'; | 36 | 30 |
| 37 | 31 | const {get: getViewConfigForType} = ReactNativeViewConfigRegistry; | 38 | 32 |
| @@ -268,7 +262,7 @@ export function shouldSetTextContent(type: string, props: Props): boolean { | 268 | 262 | } | 269 | 263 |
| 270 | 264 | export function getCurrentEventPriority(): * { | 271 | | - return DefaultLanePriority; | | 265 | + return DefaultEventPriority; | 272 | 266 | } | 273 | 267 |
| 274 | 268 | // ------------------- | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-noop-renderer/src/createReactNoop.js +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -27,6 +27,9 @@ import ReactSharedInternals from 'shared/ReactSharedInternals'; | 27 | 27 | import enqueueTask from 'shared/enqueueTask'; | 28 | 28 | const {IsSomeRendererActing} = ReactSharedInternals; | 29 | 29 |
| | 30 | +// TODO: Publish public entry point that exports the event priority constants | | 31 | +const DefaultEventPriority = 8; | | 32 | + | 30 | 33 | type Container = { | 31 | 34 | rootID: string, | 32 | 35 | children: Array<Instance | TextInstance>, | @@ -587,7 +590,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) { | 587 | 590 | const roots = new Map(); | 588 | 591 | const DEFAULT_ROOT_ID = '<default>'; | 589 | 592 |
| 590 | | - let currentEventPriority = NoopRenderer.DefaultEventPriority; | | 593 | + let currentEventPriority = DefaultEventPriority; | 591 | 594 |
| 592 | 595 | function childToJSX(child, text) { | 593 | 596 | if (text !== null) { | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/README.md +10-4Lines changed: 10 additions & 4 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -219,10 +219,16 @@ This is a property (not a function) that should be set to `true` if your rendere | 219 | 219 | To implement this method, you'll need some constants available on the _returned_ `Renderer` object: | 220 | 220 |
| 221 | 221 | ```js | | 222 | +import { | | 223 | + DiscreteEventPriority, | | 224 | + ContinuousEventPriority, | | 225 | + DefaultEventPriority, | | 226 | +} from './ReactFiberReconciler/src/ReactEventPriorities'; | | 227 | + | 222 | 228 | const HostConfig = { | 223 | 229 | // ... | 224 | 230 | getCurrentEventPriority() { | 225 | | - return MyRenderer.DefaultEventPriority; | | 231 | + return DefaultEventPriority; | 226 | 232 | }, | 227 | 233 | // ... | 228 | 234 | } | @@ -232,11 +238,11 @@ const MyRenderer = Reconciler(HostConfig); | 232 | 238 |
| 233 | 239 | 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`). | 234 | 240 |
| 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. | 236 | 242 |
| 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. | 238 | 244 |
| 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. | 240 | 246 |
| 241 | 247 | You can consult the `getCurrentEventPriority()` implementation in `ReactDOMHostConfig.js` for a reference implementation. | 242 | 248 |
| |
Collapse file Copy file name to clipboard +37Lines changed: 37 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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; |
Collapse file Copy file name to clipboard +15Lines changed: 15 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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'; |
Collapse file Copy file name to clipboard +15Lines changed: 15 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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'; |
|