GeezerVison is showing github.com — [Fiber] Move updatePriority tracking to renderers (#28751) · react/react@ce4fe7d
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/ReactFiberConfigART.js +18-3Lines changed: 18 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 5 | 5 | * LICENSE file in the root directory of this source tree. | 6 | 6 | */ | 7 | 7 |
| | 8 | +import type {EventPriority} from 'react-reconciler/src/ReactEventPriorities'; | | 9 | + | 8 | 10 | import Transform from 'art/core/transform'; | 9 | 11 | import Mode from 'art/modes/current'; | 10 | 12 |
| 11 | 13 | import {TYPES, EVENT_TYPES, childrenAsString} from './ReactARTInternals'; | 12 | 14 |
| 13 | | -import {DefaultEventPriority} from 'react-reconciler/src/ReactEventPriorities'; | | 15 | +import { | | 16 | + DefaultEventPriority, | | 17 | + NoEventPriority, | | 18 | +} from 'react-reconciler/src/ReactEventPriorities'; | 14 | 19 |
| 15 | 20 | const pooledTransform = new Transform(); | 16 | 21 |
| @@ -336,8 +341,18 @@ export function shouldSetTextContent(type, props) { | 336 | 341 | ); | 337 | 342 | } | 338 | 343 |
| 339 | | -export function getCurrentEventPriority() { | 340 | | - return DefaultEventPriority; | | 344 | +let currentUpdatePriority: EventPriority = NoEventPriority; | | 345 | + | | 346 | +export function setCurrentUpdatePriority(newPriority: EventPriority): void { | | 347 | + currentUpdatePriority = newPriority; | | 348 | +} | | 349 | + | | 350 | +export function getCurrentUpdatePriority(): EventPriority { | | 351 | + return currentUpdatePriority; | | 352 | +} | | 353 | + | | 354 | +export function resolveUpdatePriority(): EventPriority { | | 355 | + return currentUpdatePriority || DefaultEventPriority; | 341 | 356 | } | 342 | 357 |
| 343 | 358 | export function shouldAttemptEagerTransition() { | |
Collapse file Copy file name to clipboard +55Lines changed: 55 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +/** | | 2 | + * Copyright (c) Meta Platforms, Inc. and 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 type {EventPriority} from 'react-reconciler/src/ReactEventPriorities'; | | 11 | + | | 12 | +import {getEventPriority} from '../events/ReactDOMEventListener'; | | 13 | +import { | | 14 | + NoEventPriority, | | 15 | + DefaultEventPriority, | | 16 | +} from 'react-reconciler/src/ReactEventPriorities'; | | 17 | + | | 18 | +import ReactDOMSharedInternals from 'shared/ReactDOMSharedInternals'; | | 19 | + | | 20 | +export function setCurrentUpdatePriority( | | 21 | + newPriority: EventPriority, | | 22 | + // Closure will consistently not inline this function when it has arity 1 | | 23 | + // however when it has arity 2 even if the second arg is omitted at every | | 24 | + // callsite it seems to inline it even when the internal length of the function | | 25 | + // is much longer. I hope this is consistent enough to rely on across builds | | 26 | + IntentionallyUnusedArgument?: empty, | | 27 | +): void { | | 28 | + ReactDOMSharedInternals.up = newPriority; | | 29 | +} | | 30 | + | | 31 | +export function getCurrentUpdatePriority(): EventPriority { | | 32 | + return ReactDOMSharedInternals.up; | | 33 | +} | | 34 | + | | 35 | +export function resolveUpdatePriority(): EventPriority { | | 36 | + const updatePriority = ReactDOMSharedInternals.up; | | 37 | + if (updatePriority !== NoEventPriority) { | | 38 | + return updatePriority; | | 39 | + } | | 40 | + const currentEvent = window.event; | | 41 | + if (currentEvent === undefined) { | | 42 | + return DefaultEventPriority; | | 43 | + } | | 44 | + return getEventPriority(currentEvent.type); | | 45 | +} | | 46 | + | | 47 | +export function runWithPriority<T>(priority: EventPriority, fn: () => T): T { | | 48 | + const previousPriority = getCurrentUpdatePriority(); | | 49 | + try { | | 50 | + setCurrentUpdatePriority(priority); | | 51 | + return fn(); | | 52 | + } finally { | | 53 | + setCurrentUpdatePriority(previousPriority); | | 54 | + } | | 55 | +} |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js +5-11Lines changed: 5 additions & 11 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 7 | 7 | * @flow | 8 | 8 | */ | 9 | 9 |
| 10 | | -import type {EventPriority} from 'react-reconciler/src/ReactEventPriorities'; | 11 | 10 | import type {DOMEventName} from '../events/DOMEventNames'; | 12 | 11 | import type {Fiber, FiberRoot} from 'react-reconciler/src/ReactInternalTypes'; | 13 | 12 | import type { | @@ -29,11 +28,15 @@ import type { | 29 | 28 |
| 30 | 29 | import {NotPending} from 'react-dom-bindings/src/shared/ReactDOMFormActions'; | 31 | 30 | import {getCurrentRootHostContainer} from 'react-reconciler/src/ReactFiberHostContext'; | 32 | | -import {DefaultEventPriority} from 'react-reconciler/src/ReactEventPriorities'; | 33 | 31 |
| 34 | 32 | import hasOwnProperty from 'shared/hasOwnProperty'; | 35 | 33 | import {checkAttributeStringCoercion} from 'shared/CheckStringCoercion'; | 36 | 34 |
| | 35 | +export { | | 36 | + setCurrentUpdatePriority, | | 37 | + getCurrentUpdatePriority, | | 38 | + resolveUpdatePriority, | | 39 | +} from './ReactDOMUpdatePriority'; | 37 | 40 | import { | 38 | 41 | precacheFiberNode, | 39 | 42 | updateFiberProps, | @@ -69,7 +72,6 @@ import { | 69 | 72 | import { | 70 | 73 | isEnabled as ReactBrowserEventEmitterIsEnabled, | 71 | 74 | setEnabled as ReactBrowserEventEmitterSetEnabled, | 72 | | - getEventPriority, | 73 | 75 | } from '../events/ReactDOMEventListener'; | 74 | 76 | import {SVG_NAMESPACE, MATH_NAMESPACE} from './DOMNamespaces'; | 75 | 77 | import { | @@ -572,14 +574,6 @@ export function createTextInstance( | 572 | 574 | return textNode; | 573 | 575 | } | 574 | 576 |
| 575 | | -export function getCurrentEventPriority(): EventPriority { | 576 | | - const currentEvent = window.event; | 577 | | - if (currentEvent === undefined) { | 578 | | - return DefaultEventPriority; | 579 | | - } | 580 | | - return getEventPriority(currentEvent.type); | 581 | | -} | 582 | | - | 583 | 577 | let currentPopstateTransitionEvent: Event | null = null; | 584 | 578 | export function shouldAttemptEagerTransition(): boolean { | 585 | 579 | const event = window.event; | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom-bindings/src/events/ReactDOMEventListener.js +6-4Lines changed: 6 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -34,6 +34,10 @@ import { | 34 | 34 | } from '../client/ReactDOMComponentTree'; | 35 | 35 |
| 36 | 36 | import {dispatchEventForPluginEventSystem} from './DOMPluginEventSystem'; | | 37 | +import { | | 38 | + getCurrentUpdatePriority, | | 39 | + setCurrentUpdatePriority, | | 40 | +} from '../client/ReactDOMUpdatePriority'; | 37 | 41 |
| 38 | 42 | import { | 39 | 43 | getCurrentPriorityLevel as getCurrentSchedulerPriorityLevel, | @@ -48,8 +52,6 @@ import { | 48 | 52 | ContinuousEventPriority, | 49 | 53 | DefaultEventPriority, | 50 | 54 | IdleEventPriority, | 51 | | - getCurrentUpdatePriority, | 52 | | - setCurrentUpdatePriority, | 53 | 55 | } from 'react-reconciler/src/ReactEventPriorities'; | 54 | 56 | import ReactSharedInternals from 'shared/ReactSharedInternals'; | 55 | 57 | import {isRootDehydrated} from 'react-reconciler/src/ReactFiberShellHydration'; | @@ -115,9 +117,9 @@ function dispatchDiscreteEvent( | 115 | 117 | container: EventTarget, | 116 | 118 | nativeEvent: AnyNativeEvent, | 117 | 119 | ) { | 118 | | - const previousPriority = getCurrentUpdatePriority(); | 119 | 120 | const prevTransition = ReactCurrentBatchConfig.transition; | 120 | 121 | ReactCurrentBatchConfig.transition = null; | | 122 | + const previousPriority = getCurrentUpdatePriority(); | 121 | 123 | try { | 122 | 124 | setCurrentUpdatePriority(DiscreteEventPriority); | 123 | 125 | dispatchEvent(domEventName, eventSystemFlags, container, nativeEvent); | @@ -133,9 +135,9 @@ function dispatchContinuousEvent( | 133 | 135 | container: EventTarget, | 134 | 136 | nativeEvent: AnyNativeEvent, | 135 | 137 | ) { | 136 | | - const previousPriority = getCurrentUpdatePriority(); | 137 | 138 | const prevTransition = ReactCurrentBatchConfig.transition; | 138 | 139 | ReactCurrentBatchConfig.transition = null; | | 140 | + const previousPriority = getCurrentUpdatePriority(); | 139 | 141 | try { | 140 | 142 | setCurrentUpdatePriority(ContinuousEventPriority); | 141 | 143 | dispatchEvent(domEventName, eventSystemFlags, container, nativeEvent); | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom-bindings/src/events/ReactDOMEventReplaying.js +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -37,15 +37,15 @@ import {HostRoot, SuspenseComponent} from 'react-reconciler/src/ReactWorkTags'; | 37 | 37 | import {isHigherEventPriority} from 'react-reconciler/src/ReactEventPriorities'; | 38 | 38 | import {isRootDehydrated} from 'react-reconciler/src/ReactFiberShellHydration'; | 39 | 39 | import {dispatchReplayedFormAction} from './plugins/FormActionEventPlugin'; | | 40 | +import { | | 41 | + getCurrentUpdatePriority, | | 42 | + runWithPriority as attemptHydrationAtPriority, | | 43 | +} from '../client/ReactDOMUpdatePriority'; | 40 | 44 |
| 41 | 45 | import { | 42 | 46 | attemptContinuousHydration, | 43 | 47 | attemptHydrationAtCurrentPriority, | 44 | 48 | } from 'react-reconciler/src/ReactFiberReconciler'; | 45 | | -import { | 46 | | - runWithPriority as attemptHydrationAtPriority, | 47 | | - getCurrentUpdatePriority, | 48 | | -} from 'react-reconciler/src/ReactEventPriorities'; | 49 | 49 |
| 50 | 50 | // TODO: Upgrade this definition once we're on a newer version of Flow that | 51 | 51 | // has this definition built-in. | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/ReactDOMSharedInternals.js +8-3Lines changed: 8 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 7 | 7 | * @flow | 8 | 8 | */ | 9 | 9 |
| | 10 | +import type {EventPriority} from 'react-reconciler/src/ReactEventPriorities'; | 10 | 11 | import type {HostDispatcher} from './shared/ReactDOMTypes'; | 11 | 12 |
| | 13 | +import {NoEventPriority} from 'react-reconciler/src/ReactEventPriorities'; | | 14 | + | 12 | 15 | type InternalsType = { | 13 | 16 | usingClientEntryPoint: boolean, | 14 | 17 | Events: [any, any, any, any, any, any], | @@ -20,6 +23,7 @@ type InternalsType = { | 20 | 23 | | (( | 21 | 24 | componentOrElement: React$Component<any, any>, | 22 | 25 | ) => null | Element | Text), | | 26 | + up /* currentUpdatePriority */: EventPriority, | 23 | 27 | }; | 24 | 28 |
| 25 | 29 | function noop() {} | @@ -34,13 +38,14 @@ const DefaultDispatcher: HostDispatcher = { | 34 | 38 | preinitModuleScript: noop, | 35 | 39 | }; | 36 | 40 |
| 37 | | -const Internals: InternalsType = ({ | | 41 | +const Internals: InternalsType = { | 38 | 42 | usingClientEntryPoint: false, | 39 | | - Events: null, | | 43 | + Events: (null: any), | 40 | 44 | ReactDOMCurrentDispatcher: { | 41 | 45 | current: DefaultDispatcher, | 42 | 46 | }, | 43 | 47 | findDOMNode: null, | 44 | | -}: any); | | 48 | + up /* currentUpdatePriority */: NoEventPriority, | | 49 | +}; | 45 | 50 |
| 46 | 51 | export default Internals; |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/client/ReactDOM.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -20,14 +20,14 @@ import { | 20 | 20 | isValidContainer, | 21 | 21 | } from './ReactDOMRoot'; | 22 | 22 | import {createEventHandle} from 'react-dom-bindings/src/client/ReactDOMEventHandle'; | | 23 | +import {runWithPriority} from 'react-dom-bindings/src/client/ReactDOMUpdatePriority'; | 23 | 24 |
| 24 | 25 | import { | 25 | 26 | flushSync as flushSyncWithoutWarningIfAlreadyRendering, | 26 | 27 | isAlreadyRendering, | 27 | 28 | injectIntoDevTools, | 28 | 29 | findHostInstance, | 29 | 30 | } from 'react-reconciler/src/ReactFiberReconciler'; | 30 | | -import {runWithPriority} from 'react-reconciler/src/ReactEventPriorities'; | 31 | 31 | import {createPortal as createPortalImpl} from 'react-reconciler/src/ReactPortal'; | 32 | 32 | import {canUseDOM} from 'shared/ExecutionEnvironment'; | 33 | 33 | import ReactVersion from 'shared/ReactVersion'; | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-native-renderer/src/ReactFiberConfigFabric.js +15-1Lines changed: 15 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -15,6 +15,7 @@ import type { | 15 | 15 | import {create, diff} from './ReactNativeAttributePayload'; | 16 | 16 | import {dispatchEvent} from './ReactFabricEventEmitter'; | 17 | 17 | import { | | 18 | + NoEventPriority, | 18 | 19 | DefaultEventPriority, | 19 | 20 | DiscreteEventPriority, | 20 | 21 | type EventPriority, | @@ -311,7 +312,20 @@ export function shouldSetTextContent(type: string, props: Props): boolean { | 311 | 312 | return false; | 312 | 313 | } | 313 | 314 |
| 314 | | -export function getCurrentEventPriority(): EventPriority { | | 315 | +let currentUpdatePriority: EventPriority = NoEventPriority; | | 316 | +export function setCurrentUpdatePriority(newPriority: EventPriority): void { | | 317 | + currentUpdatePriority = newPriority; | | 318 | +} | | 319 | + | | 320 | +export function getCurrentUpdatePriority(): EventPriority { | | 321 | + return currentUpdatePriority; | | 322 | +} | | 323 | + | | 324 | +export function resolveUpdatePriority(): EventPriority { | | 325 | + if (currentUpdatePriority !== NoEventPriority) { | | 326 | + return currentUpdatePriority; | | 327 | + } | | 328 | + | 315 | 329 | const currentEventPriority = fabricGetCurrentEventPriority | 316 | 330 | ? fabricGetCurrentEventPriority() | 317 | 331 | : null; | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-native-renderer/src/ReactFiberConfigNative.js +14-1Lines changed: 14 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -26,6 +26,7 @@ import ReactNativeFiberHostComponent from './ReactNativeFiberHostComponent'; | 26 | 26 |
| 27 | 27 | import { | 28 | 28 | DefaultEventPriority, | | 29 | + NoEventPriority, | 29 | 30 | type EventPriority, | 30 | 31 | } from 'react-reconciler/src/ReactEventPriorities'; | 31 | 32 | import type {Fiber} from 'react-reconciler/src/ReactInternalTypes'; | @@ -253,7 +254,19 @@ export function shouldSetTextContent(type: string, props: Props): boolean { | 253 | 254 | return false; | 254 | 255 | } | 255 | 256 |
| 256 | | -export function getCurrentEventPriority(): EventPriority { | | 257 | +let currentUpdatePriority: EventPriority = NoEventPriority; | | 258 | +export function setCurrentUpdatePriority(newPriority: EventPriority): void { | | 259 | + currentUpdatePriority = newPriority; | | 260 | +} | | 261 | + | | 262 | +export function getCurrentUpdatePriority(): EventPriority { | | 263 | + return currentUpdatePriority; | | 264 | +} | | 265 | + | | 266 | +export function resolveUpdatePriority(): EventPriority { | | 267 | + if (currentUpdatePriority !== NoEventPriority) { | | 268 | + return currentUpdatePriority; | | 269 | + } | 257 | 270 | return DefaultEventPriority; | 258 | 271 | } | 259 | 272 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/react-noop-renderer/src/createReactNoop.js +30-2Lines changed: 30 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -21,12 +21,14 @@ import type { | 21 | 21 | import type {UpdateQueue} from 'react-reconciler/src/ReactFiberClassUpdateQueue'; | 22 | 22 | import type {ReactNodeList} from 'shared/ReactTypes'; | 23 | 23 | import type {RootTag} from 'react-reconciler/src/ReactRootTags'; | | 24 | +import type {EventPriority} from 'react-reconciler/src/ReactEventPriorities'; | 24 | 25 |
| 25 | 26 | import * as Scheduler from 'scheduler/unstable_mock'; | 26 | 27 | import {REACT_FRAGMENT_TYPE, REACT_ELEMENT_TYPE} from 'shared/ReactSymbols'; | 27 | 28 | import isArray from 'shared/isArray'; | 28 | 29 | import {checkPropStringCoercion} from 'shared/CheckStringCoercion'; | 29 | 30 | import { | | 31 | + NoEventPriority, | 30 | 32 | DefaultEventPriority, | 31 | 33 | IdleEventPriority, | 32 | 34 | ConcurrentRoot, | @@ -512,7 +514,13 @@ function createReactNoop(reconciler: Function, useMutation: boolean) { | 512 | 514 |
| 513 | 515 | resetAfterCommit(): void {}, | 514 | 516 |
| 515 | | - getCurrentEventPriority() { | | 517 | + setCurrentUpdatePriority, | | 518 | + getCurrentUpdatePriority, | | 519 | + | | 520 | + resolveUpdatePriority() { | | 521 | + if (currentUpdatePriority !== NoEventPriority) { | | 522 | + return currentUpdatePriority; | | 523 | + } | 516 | 524 | return currentEventPriority; | 517 | 525 | }, | 518 | 526 |
| @@ -786,6 +794,15 @@ function createReactNoop(reconciler: Function, useMutation: boolean) { | 786 | 794 | const roots = new Map(); | 787 | 795 | const DEFAULT_ROOT_ID = '<default>'; | 788 | 796 |
| | 797 | + let currentUpdatePriority = NoEventPriority; | | 798 | + function setCurrentUpdatePriority(newPriority: EventPriority): void { | | 799 | + currentUpdatePriority = newPriority; | | 800 | + } | | 801 | + | | 802 | + function getCurrentUpdatePriority(): EventPriority { | | 803 | + return currentUpdatePriority; | | 804 | + } | | 805 | + | 789 | 806 | let currentEventPriority = DefaultEventPriority; | 790 | 807 |
| 791 | 808 | function createJSXElementForTestComparison(type, props) { | @@ -1223,7 +1240,18 @@ function createReactNoop(reconciler: Function, useMutation: boolean) { | 1223 | 1240 | return Scheduler.unstable_flushExpired(); | 1224 | 1241 | }, | 1225 | 1242 |
| 1226 | | - unstable_runWithPriority: NoopRenderer.runWithPriority, | | 1243 | + unstable_runWithPriority: function runWithPriority<T>( | | 1244 | + priority: EventPriority, | | 1245 | + fn: () => T, | | 1246 | + ): T { | | 1247 | + const previousPriority = getCurrentUpdatePriority(); | | 1248 | + try { | | 1249 | + setCurrentUpdatePriority(priority); | | 1250 | + return fn(); | | 1251 | + } finally { | | 1252 | + setCurrentUpdatePriority(previousPriority); | | 1253 | + } | | 1254 | + }, | 1227 | 1255 |
| 1228 | 1256 | batchedUpdates: NoopRenderer.batchedUpdates, | 1229 | 1257 |
| |
|