GeezerVison is showing github.com — Switch callsites over to update lane priority · react/react@431e76e
File treeExpand file treeCollapse file tree Open diff view settings packages/react-reconciler/src
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberCommitWork.new.js +9-10Lines changed: 9 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -17,12 +17,11 @@ import type { | 17 | 17 | } from './ReactFiberHostConfig'; | 18 | 18 | import type {Fiber} from './ReactInternalTypes'; | 19 | 19 | import type {FiberRoot} from './ReactInternalTypes'; | 20 | | -import type {Lanes} from './ReactFiberLane.new'; | | 20 | +import type {LanePriority, Lanes} from './ReactFiberLane.new'; | 21 | 21 | import type {SuspenseState} from './ReactFiberSuspenseComponent.new'; | 22 | 22 | import type {UpdateQueue} from './ReactUpdateQueue.new'; | 23 | 23 | import type {FunctionComponentUpdateQueue} from './ReactFiberHooks.new'; | 24 | 24 | import type {Wakeable} from 'shared/ReactTypes'; | 25 | | -import type {ReactPriorityLevel} from './ReactInternalTypes'; | 26 | 25 | import type {OffscreenState} from './ReactFiberOffscreenComponent'; | 27 | 26 | import type {HookFlags} from './ReactHookEffectTags'; | 28 | 27 |
| @@ -1057,7 +1056,7 @@ function commitUnmount( | 1057 | 1056 | finishedRoot: FiberRoot, | 1058 | 1057 | current: Fiber, | 1059 | 1058 | nearestMountedAncestor: Fiber, | 1060 | | - renderPriorityLevel: ReactPriorityLevel, | | 1059 | + renderPriorityLevel: LanePriority, | 1061 | 1060 | ): void { | 1062 | 1061 | onCommitUnmount(current); | 1063 | 1062 |
| @@ -1153,7 +1152,7 @@ function commitNestedUnmounts( | 1153 | 1152 | finishedRoot: FiberRoot, | 1154 | 1153 | root: Fiber, | 1155 | 1154 | nearestMountedAncestor: Fiber, | 1156 | | - renderPriorityLevel: ReactPriorityLevel, | | 1155 | + renderPriorityLevel: LanePriority, | 1157 | 1156 | ): void { | 1158 | 1157 | // While we're inside a removed host node we don't want to call | 1159 | 1158 | // removeChild on the inner nodes because they're removed by the top | @@ -1463,7 +1462,7 @@ function unmountHostComponents( | 1463 | 1462 | finishedRoot: FiberRoot, | 1464 | 1463 | current: Fiber, | 1465 | 1464 | nearestMountedAncestor: Fiber, | 1466 | | - renderPriorityLevel: ReactPriorityLevel, | | 1465 | + renderPriorityLevel: LanePriority, | 1467 | 1466 | ): void { | 1468 | 1467 | // We only have the top Fiber that was deleted but we need to recurse down its | 1469 | 1468 | // children to find all the terminal nodes. | @@ -1601,7 +1600,7 @@ function commitDeletion( | 1601 | 1600 | finishedRoot: FiberRoot, | 1602 | 1601 | current: Fiber, | 1603 | 1602 | nearestMountedAncestor: Fiber, | 1604 | | - renderPriorityLevel: ReactPriorityLevel, | | 1603 | + renderPriorityLevel: LanePriority, | 1605 | 1604 | ): void { | 1606 | 1605 | if (supportsMutation) { | 1607 | 1606 | // Recursively delete all host nodes from the parent. | @@ -1945,7 +1944,7 @@ function commitResetTextContent(current: Fiber) { | 1945 | 1944 |
| 1946 | 1945 | export function commitMutationEffects( | 1947 | 1946 | root: FiberRoot, | 1948 | | - renderPriorityLevel: ReactPriorityLevel, | | 1947 | + renderPriorityLevel: LanePriority, | 1949 | 1948 | firstChild: Fiber, | 1950 | 1949 | ) { | 1951 | 1950 | nextEffect = firstChild; | @@ -1954,7 +1953,7 @@ export function commitMutationEffects( | 1954 | 1953 |
| 1955 | 1954 | function commitMutationEffects_begin( | 1956 | 1955 | root: FiberRoot, | 1957 | | - renderPriorityLevel: ReactPriorityLevel, | | 1956 | + renderPriorityLevel: LanePriority, | 1958 | 1957 | ) { | 1959 | 1958 | while (nextEffect !== null) { | 1960 | 1959 | const fiber = nextEffect; | @@ -2000,7 +1999,7 @@ function commitMutationEffects_begin( | 2000 | 1999 |
| 2001 | 2000 | function commitMutationEffects_complete( | 2002 | 2001 | root: FiberRoot, | 2003 | | - renderPriorityLevel: ReactPriorityLevel, | | 2002 | + renderPriorityLevel: LanePriority, | 2004 | 2003 | ) { | 2005 | 2004 | while (nextEffect !== null) { | 2006 | 2005 | const fiber = nextEffect; | @@ -2041,7 +2040,7 @@ function commitMutationEffects_complete( | 2041 | 2040 | function commitMutationEffectsOnFiber( | 2042 | 2041 | finishedWork: Fiber, | 2043 | 2042 | root: FiberRoot, | 2044 | | - renderPriorityLevel: ReactPriorityLevel, | | 2043 | + renderPriorityLevel: LanePriority, | 2045 | 2044 | ) { | 2046 | 2045 | const flags = finishedWork.flags; | 2047 | 2046 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberCommitWork.old.js +9-10Lines changed: 9 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -17,12 +17,11 @@ import type { | 17 | 17 | } from './ReactFiberHostConfig'; | 18 | 18 | import type {Fiber} from './ReactInternalTypes'; | 19 | 19 | import type {FiberRoot} from './ReactInternalTypes'; | 20 | | -import type {Lanes} from './ReactFiberLane.old'; | | 20 | +import type {LanePriority, Lanes} from './ReactFiberLane.old'; | 21 | 21 | import type {SuspenseState} from './ReactFiberSuspenseComponent.old'; | 22 | 22 | import type {UpdateQueue} from './ReactUpdateQueue.old'; | 23 | 23 | import type {FunctionComponentUpdateQueue} from './ReactFiberHooks.old'; | 24 | 24 | import type {Wakeable} from 'shared/ReactTypes'; | 25 | | -import type {ReactPriorityLevel} from './ReactInternalTypes'; | 26 | 25 | import type {OffscreenState} from './ReactFiberOffscreenComponent'; | 27 | 26 | import type {HookFlags} from './ReactHookEffectTags'; | 28 | 27 |
| @@ -1057,7 +1056,7 @@ function commitUnmount( | 1057 | 1056 | finishedRoot: FiberRoot, | 1058 | 1057 | current: Fiber, | 1059 | 1058 | nearestMountedAncestor: Fiber, | 1060 | | - renderPriorityLevel: ReactPriorityLevel, | | 1059 | + renderPriorityLevel: LanePriority, | 1061 | 1060 | ): void { | 1062 | 1061 | onCommitUnmount(current); | 1063 | 1062 |
| @@ -1153,7 +1152,7 @@ function commitNestedUnmounts( | 1153 | 1152 | finishedRoot: FiberRoot, | 1154 | 1153 | root: Fiber, | 1155 | 1154 | nearestMountedAncestor: Fiber, | 1156 | | - renderPriorityLevel: ReactPriorityLevel, | | 1155 | + renderPriorityLevel: LanePriority, | 1157 | 1156 | ): void { | 1158 | 1157 | // While we're inside a removed host node we don't want to call | 1159 | 1158 | // removeChild on the inner nodes because they're removed by the top | @@ -1463,7 +1462,7 @@ function unmountHostComponents( | 1463 | 1462 | finishedRoot: FiberRoot, | 1464 | 1463 | current: Fiber, | 1465 | 1464 | nearestMountedAncestor: Fiber, | 1466 | | - renderPriorityLevel: ReactPriorityLevel, | | 1465 | + renderPriorityLevel: LanePriority, | 1467 | 1466 | ): void { | 1468 | 1467 | // We only have the top Fiber that was deleted but we need to recurse down its | 1469 | 1468 | // children to find all the terminal nodes. | @@ -1601,7 +1600,7 @@ function commitDeletion( | 1601 | 1600 | finishedRoot: FiberRoot, | 1602 | 1601 | current: Fiber, | 1603 | 1602 | nearestMountedAncestor: Fiber, | 1604 | | - renderPriorityLevel: ReactPriorityLevel, | | 1603 | + renderPriorityLevel: LanePriority, | 1605 | 1604 | ): void { | 1606 | 1605 | if (supportsMutation) { | 1607 | 1606 | // Recursively delete all host nodes from the parent. | @@ -1945,7 +1944,7 @@ function commitResetTextContent(current: Fiber) { | 1945 | 1944 |
| 1946 | 1945 | export function commitMutationEffects( | 1947 | 1946 | root: FiberRoot, | 1948 | | - renderPriorityLevel: ReactPriorityLevel, | | 1947 | + renderPriorityLevel: LanePriority, | 1949 | 1948 | firstChild: Fiber, | 1950 | 1949 | ) { | 1951 | 1950 | nextEffect = firstChild; | @@ -1954,7 +1953,7 @@ export function commitMutationEffects( | 1954 | 1953 |
| 1955 | 1954 | function commitMutationEffects_begin( | 1956 | 1955 | root: FiberRoot, | 1957 | | - renderPriorityLevel: ReactPriorityLevel, | | 1956 | + renderPriorityLevel: LanePriority, | 1958 | 1957 | ) { | 1959 | 1958 | while (nextEffect !== null) { | 1960 | 1959 | const fiber = nextEffect; | @@ -2000,7 +1999,7 @@ function commitMutationEffects_begin( | 2000 | 1999 |
| 2001 | 2000 | function commitMutationEffects_complete( | 2002 | 2001 | root: FiberRoot, | 2003 | | - renderPriorityLevel: ReactPriorityLevel, | | 2002 | + renderPriorityLevel: LanePriority, | 2004 | 2003 | ) { | 2005 | 2004 | while (nextEffect !== null) { | 2006 | 2005 | const fiber = nextEffect; | @@ -2041,7 +2040,7 @@ function commitMutationEffects_complete( | 2041 | 2040 | function commitMutationEffectsOnFiber( | 2042 | 2041 | finishedWork: Fiber, | 2043 | 2042 | root: FiberRoot, | 2044 | | - renderPriorityLevel: ReactPriorityLevel, | | 2043 | + renderPriorityLevel: LanePriority, | 2045 | 2044 | ) { | 2046 | 2045 | const flags = finishedWork.flags; | 2047 | 2046 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberDevToolsHook.new.js +13-6Lines changed: 13 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 9 | 9 |
| 10 | 10 | import {enableProfilerTimer} from 'shared/ReactFeatureFlags'; | 11 | 11 |
| 12 | | -import type {Fiber, FiberRoot, ReactPriorityLevel} from './ReactInternalTypes'; | | 12 | +import type {Fiber, FiberRoot} from './ReactInternalTypes'; | 13 | 13 | import type {ReactNodeList} from 'shared/ReactTypes'; | | 14 | +import type {LanePriority} from './ReactFiberLane.new'; | 14 | 15 |
| 15 | 16 | import {DidCapture} from './ReactFiberFlags'; | | 17 | +import { | | 18 | + lanePriorityToSchedulerPriority, | | 19 | + NoLanePriority, | | 20 | +} from './ReactFiberLane.new'; | | 21 | +import {NormalPriority} from './SchedulerWithReactIntegration.new'; | 16 | 22 |
| 17 | 23 | declare var __REACT_DEVTOOLS_GLOBAL_HOOK__: Object | void; | 18 | 24 |
| @@ -78,18 +84,19 @@ export function onScheduleRoot(root: FiberRoot, children: ReactNodeList) { | 78 | 84 | } | 79 | 85 | } | 80 | 86 |
| 81 | | -export function onCommitRoot( | 82 | | - root: FiberRoot, | 83 | | - priorityLevel: ReactPriorityLevel, | 84 | | -) { | | 87 | +export function onCommitRoot(root: FiberRoot, priorityLevel: LanePriority) { | 85 | 88 | if (injectedHook && typeof injectedHook.onCommitFiberRoot === 'function') { | 86 | 89 | try { | 87 | 90 | const didError = (root.current.flags & DidCapture) === DidCapture; | 88 | 91 | if (enableProfilerTimer) { | | 92 | + const schedulerPriority = | | 93 | + priorityLevel === NoLanePriority | | 94 | + ? NormalPriority | | 95 | + : lanePriorityToSchedulerPriority(priorityLevel); | 89 | 96 | injectedHook.onCommitFiberRoot( | 90 | 97 | rendererID, | 91 | 98 | root, | 92 | | - priorityLevel, | | 99 | + schedulerPriority, | 93 | 100 | didError, | 94 | 101 | ); | 95 | 102 | } else { | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberDevToolsHook.old.js +13-6Lines changed: 13 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 9 | 9 |
| 10 | 10 | import {enableProfilerTimer} from 'shared/ReactFeatureFlags'; | 11 | 11 |
| 12 | | -import type {Fiber, FiberRoot, ReactPriorityLevel} from './ReactInternalTypes'; | | 12 | +import type {Fiber, FiberRoot} from './ReactInternalTypes'; | 13 | 13 | import type {ReactNodeList} from 'shared/ReactTypes'; | | 14 | +import type {LanePriority} from './ReactFiberLane.old'; | 14 | 15 |
| 15 | 16 | import {DidCapture} from './ReactFiberFlags'; | | 17 | +import { | | 18 | + lanePriorityToSchedulerPriority, | | 19 | + NoLanePriority, | | 20 | +} from './ReactFiberLane.old'; | | 21 | +import {NormalPriority} from './SchedulerWithReactIntegration.old'; | 16 | 22 |
| 17 | 23 | declare var __REACT_DEVTOOLS_GLOBAL_HOOK__: Object | void; | 18 | 24 |
| @@ -78,18 +84,19 @@ export function onScheduleRoot(root: FiberRoot, children: ReactNodeList) { | 78 | 84 | } | 79 | 85 | } | 80 | 86 |
| 81 | | -export function onCommitRoot( | 82 | | - root: FiberRoot, | 83 | | - priorityLevel: ReactPriorityLevel, | 84 | | -) { | | 87 | +export function onCommitRoot(root: FiberRoot, priorityLevel: LanePriority) { | 85 | 88 | if (injectedHook && typeof injectedHook.onCommitFiberRoot === 'function') { | 86 | 89 | try { | 87 | 90 | const didError = (root.current.flags & DidCapture) === DidCapture; | 88 | 91 | if (enableProfilerTimer) { | | 92 | + const schedulerPriority = | | 93 | + priorityLevel === NoLanePriority | | 94 | + ? NormalPriority | | 95 | + : lanePriorityToSchedulerPriority(priorityLevel); | 89 | 96 | injectedHook.onCommitFiberRoot( | 90 | 97 | rendererID, | 91 | 98 | root, | 92 | | - priorityLevel, | | 99 | + schedulerPriority, | 93 | 100 | didError, | 94 | 101 | ); | 95 | 102 | } else { | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberWorkLoop.new.js +29-23Lines changed: 29 additions & 23 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 9 | 9 |
| 10 | 10 | import type {Thenable, Wakeable} from 'shared/ReactTypes'; | 11 | 11 | import type {Fiber, FiberRoot} from './ReactInternalTypes'; | 12 | | -import type {Lanes, Lane} from './ReactFiberLane.new'; | 13 | | -import type {ReactPriorityLevel} from './ReactInternalTypes'; | | 12 | +import type {Lanes, Lane, LanePriority} from './ReactFiberLane.new'; | 14 | 13 | import type {Interaction} from 'scheduler/src/Tracing'; | 15 | 14 | import type {SuspenseState} from './ReactFiberSuspenseComponent.new'; | 16 | 15 | import type {StackCursor} from './ReactFiberStack.new'; | @@ -46,7 +45,6 @@ import { | 46 | 45 | shouldYield, | 47 | 46 | requestPaint, | 48 | 47 | now, | 49 | | - NoPriority as NoSchedulerPriority, | 50 | 48 | ImmediatePriority as ImmediateSchedulerPriority, | 51 | 49 | UserBlockingPriority as UserBlockingSchedulerPriority, | 52 | 50 | NormalPriority as NormalSchedulerPriority, | @@ -173,6 +171,7 @@ import { | 173 | 171 | markRootFinished, | 174 | 172 | schedulerPriorityToLanePriority, | 175 | 173 | lanePriorityToSchedulerPriority, | | 174 | + higherLanePriority, | 176 | 175 | } from './ReactFiberLane.new'; | 177 | 176 | import {requestCurrentTransition, NoTransition} from './ReactFiberTransition'; | 178 | 177 | import {beginWork as originalBeginWork} from './ReactFiberBeginWork.new'; | @@ -333,7 +332,7 @@ let rootCommittingMutationOrLayoutEffects: FiberRoot | null = null; | 333 | 332 |
| 334 | 333 | let rootDoesHavePassiveEffects: boolean = false; | 335 | 334 | let rootWithPendingPassiveEffects: FiberRoot | null = null; | 336 | | -let pendingPassiveEffectsRenderPriority: ReactPriorityLevel = NoSchedulerPriority; | | 335 | +let pendingPassiveEffectsRenderPriority: LanePriority = NoLanePriority; | 337 | 336 | let pendingPassiveEffectsLanes: Lanes = NoLanes; | 338 | 337 | let pendingPassiveProfilerEffects: Array<Fiber> = []; | 339 | 338 |
| @@ -394,7 +393,7 @@ export function requestUpdateLane(fiber: Fiber): Lane { | 394 | 393 | if ((mode & BlockingMode) === NoMode) { | 395 | 394 | return (SyncLane: Lane); | 396 | 395 | } else if ((mode & ConcurrentMode) === NoMode) { | 397 | | - return getCurrentPriorityLevel() === ImmediateSchedulerPriority | | 396 | + return getCurrentUpdateLanePriority() === SyncLanePriority | 398 | 397 | ? (SyncLane: Lane) | 399 | 398 | : (SyncBatchedLane: Lane); | 400 | 399 | } else if ( | @@ -482,7 +481,7 @@ function requestRetryLane(fiber: Fiber) { | 482 | 481 | if ((mode & BlockingMode) === NoMode) { | 483 | 482 | return (SyncLane: Lane); | 484 | 483 | } else if ((mode & ConcurrentMode) === NoMode) { | 485 | | - return getCurrentPriorityLevel() === ImmediateSchedulerPriority | | 484 | + return getCurrentUpdateLanePriority() === SyncLanePriority | 486 | 485 | ? (SyncLane: Lane) | 487 | 486 | : (SyncBatchedLane: Lane); | 488 | 487 | } | @@ -596,9 +595,9 @@ export function scheduleUpdateOnFiber( | 596 | 595 | // Schedule a discrete update but only if it's not Sync. | 597 | 596 | if ( | 598 | 597 | (executionContext & DiscreteEventContext) !== NoContext && | 599 | | - // Only updates at user-blocking priority or greater are considered | 600 | | - // discrete, even inside a discrete event. | 601 | | - updateLanePriority === InputDiscreteLanePriority | | 598 | + // Only updates greater than default considered discrete, even inside a discrete event. | | 599 | + higherLanePriority(updateLanePriority, DefaultLanePriority) !== | | 600 | + DefaultLanePriority | 602 | 601 | ) { | 603 | 602 | // This is the result of a discrete event. Track the lowest priority | 604 | 603 | // discrete update per root so we can flush them early, if needed. | @@ -1751,11 +1750,17 @@ function completeUnitOfWork(unitOfWork: Fiber): void { | 1751 | 1750 | } | 1752 | 1751 |
| 1753 | 1752 | function commitRoot(root) { | 1754 | | - const renderPriorityLevel = getCurrentPriorityLevel(); | 1755 | | - runWithPriority( | 1756 | | - ImmediateSchedulerPriority, | 1757 | | - commitRootImpl.bind(null, root, renderPriorityLevel), | 1758 | | - ); | | 1753 | + const previousUpdateLanePriority = getCurrentUpdateLanePriority(); | | 1754 | + try { | | 1755 | + setCurrentUpdateLanePriority(SyncLanePriority); | | 1756 | + runWithPriority( | | 1757 | + ImmediateSchedulerPriority, | | 1758 | + commitRootImpl.bind(null, root, previousUpdateLanePriority), | | 1759 | + ); | | 1760 | + } finally { | | 1761 | + setCurrentUpdateLanePriority(previousUpdateLanePriority); | | 1762 | + } | | 1763 | + | 1759 | 1764 | return null; | 1760 | 1765 | } | 1761 | 1766 |
| @@ -1983,7 +1988,10 @@ function commitRootImpl(root, renderPriorityLevel) { | 1983 | 1988 | rootDoesHavePassiveEffects = false; | 1984 | 1989 | rootWithPendingPassiveEffects = root; | 1985 | 1990 | pendingPassiveEffectsLanes = lanes; | 1986 | | - pendingPassiveEffectsRenderPriority = renderPriorityLevel; | | 1991 | + pendingPassiveEffectsRenderPriority = | | 1992 | + renderPriorityLevel === NoLanePriority | | 1993 | + ? DefaultLanePriority | | 1994 | + : renderPriorityLevel; | 1987 | 1995 | } | 1988 | 1996 |
| 1989 | 1997 | // Read this again, since an effect might have updated it | @@ -2097,18 +2105,16 @@ function commitRootImpl(root, renderPriorityLevel) { | 2097 | 2105 |
| 2098 | 2106 | export function flushPassiveEffects(): boolean { | 2099 | 2107 | // Returns whether passive effects were flushed. | 2100 | | - if (pendingPassiveEffectsRenderPriority !== NoSchedulerPriority) { | | 2108 | + if (pendingPassiveEffectsRenderPriority !== NoLanePriority) { | 2101 | 2109 | const priorityLevel = | 2102 | | - pendingPassiveEffectsRenderPriority > NormalSchedulerPriority | 2103 | | - ? NormalSchedulerPriority | | 2110 | + pendingPassiveEffectsRenderPriority > DefaultLanePriority | | 2111 | + ? DefaultLanePriority | 2104 | 2112 | : pendingPassiveEffectsRenderPriority; | 2105 | | - pendingPassiveEffectsRenderPriority = NoSchedulerPriority; | | 2113 | + pendingPassiveEffectsRenderPriority = NoLanePriority; | 2106 | 2114 | const previousLanePriority = getCurrentUpdateLanePriority(); | 2107 | 2115 | try { | 2108 | | - setCurrentUpdateLanePriority( | 2109 | | - schedulerPriorityToLanePriority(priorityLevel), | 2110 | | - ); | 2111 | | - return runWithPriority(priorityLevel, flushPassiveEffectsImpl); | | 2116 | + setCurrentUpdateLanePriority(priorityLevel); | | 2117 | + return flushPassiveEffectsImpl(); | 2112 | 2118 | } finally { | 2113 | 2119 | setCurrentUpdateLanePriority(previousLanePriority); | 2114 | 2120 | } | |
|