GeezerVison is showing github.com — [Transition Tracing] Add transition to OffscreenState and pendingSusp… · react/react@fea6f8d
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/ReactFiberBeginWork.new.js +7-11Lines changed: 7 additions & 11 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -236,7 +236,6 @@ import { | 236 | 236 | markSkippedUpdateLanes, | 237 | 237 | getWorkInProgressRoot, | 238 | 238 | pushRenderLanes, | 239 | | - getWorkInProgressTransitions, | 240 | 239 | } from './ReactFiberWorkLoop.new'; | 241 | 240 | import {setWorkInProgressVersion} from './ReactMutableSource.new'; | 242 | 241 | import {pushCacheProvider, CacheContext} from './ReactFiberCacheComponent.new'; | @@ -652,9 +651,11 @@ function updateOffscreenComponent( | 652 | 651 | // Rendering a hidden tree. | 653 | 652 | if ((workInProgress.mode & ConcurrentMode) === NoMode) { | 654 | 653 | // In legacy sync mode, don't defer the subtree. Render it now. | | 654 | + // TODO: Consider how Offscreen should work with transitions in the future | 655 | 655 | const nextState: OffscreenState = { | 656 | 656 | baseLanes: NoLanes, | 657 | 657 | cachePool: null, | | 658 | + transitions: null, | 658 | 659 | }; | 659 | 660 | workInProgress.memoizedState = nextState; | 660 | 661 | if (enableCache) { | @@ -688,6 +689,7 @@ function updateOffscreenComponent( | 688 | 689 | const nextState: OffscreenState = { | 689 | 690 | baseLanes: nextBaseLanes, | 690 | 691 | cachePool: spawnedCachePool, | | 692 | + transitions: null, | 691 | 693 | }; | 692 | 694 | workInProgress.memoizedState = nextState; | 693 | 695 | workInProgress.updateQueue = null; | @@ -723,6 +725,7 @@ function updateOffscreenComponent( | 723 | 725 | const nextState: OffscreenState = { | 724 | 726 | baseLanes: NoLanes, | 725 | 727 | cachePool: null, | | 728 | + transitions: null, | 726 | 729 | }; | 727 | 730 | workInProgress.memoizedState = nextState; | 728 | 731 | // Push the lanes that were skipped when we bailed out. | @@ -1345,13 +1348,6 @@ function updateHostRoot(current, workInProgress, renderLanes) { | 1345 | 1348 | } | 1346 | 1349 | } | 1347 | 1350 |
| 1348 | | - if (enableTransitionTracing) { | 1349 | | - // FIXME: Slipped past code review. This is not a safe mutation: | 1350 | | - // workInProgress.memoizedState is a shared object. Need to fix before | 1351 | | - // rolling out the Transition Tracing experiment. | 1352 | | - workInProgress.memoizedState.transitions = getWorkInProgressTransitions(); | 1353 | | - } | 1354 | | - | 1355 | 1351 | // Caution: React DevTools currently depends on this property | 1356 | 1352 | // being called "element". | 1357 | 1353 | const nextChildren = nextState.element; | @@ -1365,6 +1361,7 @@ function updateHostRoot(current, workInProgress, renderLanes) { | 1365 | 1361 | element: nextChildren, | 1366 | 1362 | isDehydrated: false, | 1367 | 1363 | cache: nextState.cache, | | 1364 | + pendingSuspenseBoundaries: nextState.pendingSuspenseBoundaries, | 1368 | 1365 | transitions: nextState.transitions, | 1369 | 1366 | }; | 1370 | 1367 | const updateQueue: UpdateQueue<RootState> = (workInProgress.updateQueue: any); | @@ -1982,6 +1979,7 @@ function mountSuspenseOffscreenState(renderLanes: Lanes): OffscreenState { | 1982 | 1979 | return { | 1983 | 1980 | baseLanes: renderLanes, | 1984 | 1981 | cachePool: getSuspendedCache(), | | 1982 | + transitions: null, | 1985 | 1983 | }; | 1986 | 1984 | } | 1987 | 1985 |
| @@ -2016,6 +2014,7 @@ function updateSuspenseOffscreenState( | 2016 | 2014 | return { | 2017 | 2015 | baseLanes: mergeLanes(prevOffscreenState.baseLanes, renderLanes), | 2018 | 2016 | cachePool, | | 2017 | + transitions: prevOffscreenState.transitions, | 2019 | 2018 | }; | 2020 | 2019 | } | 2021 | 2020 |
| @@ -3582,9 +3581,6 @@ function attemptEarlyBailoutIfNoScheduledUpdate( | 3582 | 3581 | const cache: Cache = current.memoizedState.cache; | 3583 | 3582 | pushCacheProvider(workInProgress, cache); | 3584 | 3583 | } | 3585 | | - if (enableTransitionTracing) { | 3586 | | - workInProgress.memoizedState.transitions = getWorkInProgressTransitions(); | 3587 | | - } | 3588 | 3584 | resetHydrationState(); | 3589 | 3585 | break; | 3590 | 3586 | case HostComponent: | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberBeginWork.old.js +7-11Lines changed: 7 additions & 11 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -236,7 +236,6 @@ import { | 236 | 236 | markSkippedUpdateLanes, | 237 | 237 | getWorkInProgressRoot, | 238 | 238 | pushRenderLanes, | 239 | | - getWorkInProgressTransitions, | 240 | 239 | } from './ReactFiberWorkLoop.old'; | 241 | 240 | import {setWorkInProgressVersion} from './ReactMutableSource.old'; | 242 | 241 | import {pushCacheProvider, CacheContext} from './ReactFiberCacheComponent.old'; | @@ -652,9 +651,11 @@ function updateOffscreenComponent( | 652 | 651 | // Rendering a hidden tree. | 653 | 652 | if ((workInProgress.mode & ConcurrentMode) === NoMode) { | 654 | 653 | // In legacy sync mode, don't defer the subtree. Render it now. | | 654 | + // TODO: Consider how Offscreen should work with transitions in the future | 655 | 655 | const nextState: OffscreenState = { | 656 | 656 | baseLanes: NoLanes, | 657 | 657 | cachePool: null, | | 658 | + transitions: null, | 658 | 659 | }; | 659 | 660 | workInProgress.memoizedState = nextState; | 660 | 661 | if (enableCache) { | @@ -688,6 +689,7 @@ function updateOffscreenComponent( | 688 | 689 | const nextState: OffscreenState = { | 689 | 690 | baseLanes: nextBaseLanes, | 690 | 691 | cachePool: spawnedCachePool, | | 692 | + transitions: null, | 691 | 693 | }; | 692 | 694 | workInProgress.memoizedState = nextState; | 693 | 695 | workInProgress.updateQueue = null; | @@ -723,6 +725,7 @@ function updateOffscreenComponent( | 723 | 725 | const nextState: OffscreenState = { | 724 | 726 | baseLanes: NoLanes, | 725 | 727 | cachePool: null, | | 728 | + transitions: null, | 726 | 729 | }; | 727 | 730 | workInProgress.memoizedState = nextState; | 728 | 731 | // Push the lanes that were skipped when we bailed out. | @@ -1345,13 +1348,6 @@ function updateHostRoot(current, workInProgress, renderLanes) { | 1345 | 1348 | } | 1346 | 1349 | } | 1347 | 1350 |
| 1348 | | - if (enableTransitionTracing) { | 1349 | | - // FIXME: Slipped past code review. This is not a safe mutation: | 1350 | | - // workInProgress.memoizedState is a shared object. Need to fix before | 1351 | | - // rolling out the Transition Tracing experiment. | 1352 | | - workInProgress.memoizedState.transitions = getWorkInProgressTransitions(); | 1353 | | - } | 1354 | | - | 1355 | 1351 | // Caution: React DevTools currently depends on this property | 1356 | 1352 | // being called "element". | 1357 | 1353 | const nextChildren = nextState.element; | @@ -1365,6 +1361,7 @@ function updateHostRoot(current, workInProgress, renderLanes) { | 1365 | 1361 | element: nextChildren, | 1366 | 1362 | isDehydrated: false, | 1367 | 1363 | cache: nextState.cache, | | 1364 | + pendingSuspenseBoundaries: nextState.pendingSuspenseBoundaries, | 1368 | 1365 | transitions: nextState.transitions, | 1369 | 1366 | }; | 1370 | 1367 | const updateQueue: UpdateQueue<RootState> = (workInProgress.updateQueue: any); | @@ -1982,6 +1979,7 @@ function mountSuspenseOffscreenState(renderLanes: Lanes): OffscreenState { | 1982 | 1979 | return { | 1983 | 1980 | baseLanes: renderLanes, | 1984 | 1981 | cachePool: getSuspendedCache(), | | 1982 | + transitions: null, | 1985 | 1983 | }; | 1986 | 1984 | } | 1987 | 1985 |
| @@ -2016,6 +2014,7 @@ function updateSuspenseOffscreenState( | 2016 | 2014 | return { | 2017 | 2015 | baseLanes: mergeLanes(prevOffscreenState.baseLanes, renderLanes), | 2018 | 2016 | cachePool, | | 2017 | + transitions: prevOffscreenState.transitions, | 2019 | 2018 | }; | 2020 | 2019 | } | 2021 | 2020 |
| @@ -3582,9 +3581,6 @@ function attemptEarlyBailoutIfNoScheduledUpdate( | 3582 | 3581 | const cache: Cache = current.memoizedState.cache; | 3583 | 3582 | pushCacheProvider(workInProgress, cache); | 3584 | 3583 | } | 3585 | | - if (enableTransitionTracing) { | 3586 | | - workInProgress.memoizedState.transitions = getWorkInProgressTransitions(); | 3587 | | - } | 3588 | 3584 | resetHydrationState(); | 3589 | 3585 | break; | 3590 | 3586 | case HostComponent: | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberCommitWork.new.js +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2725,9 +2725,8 @@ function commitPassiveMountOnFiber( | 2725 | 2725 | } | 2726 | 2726 |
| 2727 | 2727 | if (enableTransitionTracing) { | 2728 | | - const transitions = finishedWork.memoizedState.transitions; | 2729 | | - if (transitions !== null) { | 2730 | | - transitions.forEach(transition => { | | 2728 | + if (committedTransitions !== null) { | | 2729 | + committedTransitions.forEach(transition => { | 2731 | 2730 | // TODO(luna) Do we want to log TransitionStart in the startTransition callback instead? | 2732 | 2731 | addTransitionStartCallbackToPendingTransition({ | 2733 | 2732 | transitionName: transition.name, | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberCommitWork.old.js +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2725,9 +2725,8 @@ function commitPassiveMountOnFiber( | 2725 | 2725 | } | 2726 | 2726 |
| 2727 | 2727 | if (enableTransitionTracing) { | 2728 | | - const transitions = finishedWork.memoizedState.transitions; | 2729 | | - if (transitions !== null) { | 2730 | | - transitions.forEach(transition => { | | 2728 | + if (committedTransitions !== null) { | | 2729 | + committedTransitions.forEach(transition => { | 2731 | 2730 | // TODO(luna) Do we want to log TransitionStart in the startTransition callback instead? | 2732 | 2731 | addTransitionStartCallbackToPendingTransition({ | 2733 | 2732 | transitionName: transition.name, | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberOffscreenComponent.js +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 10 | 10 | import type {ReactNodeList, OffscreenMode} from 'shared/ReactTypes'; | 11 | 11 | import type {Lanes} from './ReactFiberLane.old'; | 12 | 12 | import type {SpawnedCachePool} from './ReactFiberCacheComponent.new'; | 13 | | - | | 13 | +import type {Transition} from './ReactFiberTracingMarkerComponent.new'; | 14 | 14 | export type OffscreenProps = {| | 15 | 15 | // TODO: Pick an API before exposing the Offscreen type. I've chosen an enum | 16 | 16 | // for now, since we might have multiple variants. For example, hiding the | @@ -30,6 +30,7 @@ export type OffscreenState = {| | 30 | 30 | // order to unhide the component. | 31 | 31 | baseLanes: Lanes, | 32 | 32 | cachePool: SpawnedCachePool | null, | | 33 | + transitions: Set<Transition> | null, | 33 | 34 | |}; | 34 | 35 |
| 35 | 36 | export type OffscreenInstance = {}; |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberRoot.new.js +8-2Lines changed: 8 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -15,7 +15,10 @@ import type { | 15 | 15 | } from './ReactInternalTypes'; | 16 | 16 | import type {RootTag} from './ReactRootTags'; | 17 | 17 | import type {Cache} from './ReactFiberCacheComponent.new'; | 18 | | -import type {Transition} from './ReactFiberTracingMarkerComponent.new'; | | 18 | +import type { | | 19 | + PendingSuspenseBoundaries, | | 20 | + Transition, | | 21 | +} from './ReactFiberTracingMarkerComponent.new'; | 19 | 22 |
| 20 | 23 | import {noTimeout, supportsHydration} from './ReactFiberHostConfig'; | 21 | 24 | import {createHostRootFiber} from './ReactFiber.new'; | @@ -42,7 +45,8 @@ export type RootState = { | 42 | 45 | element: any, | 43 | 46 | isDehydrated: boolean, | 44 | 47 | cache: Cache, | 45 | | - transitions: Array<Transition> | null, | | 48 | + pendingSuspenseBoundaries: PendingSuspenseBoundaries | null, | | 49 | + transitions: Set<Transition> | null, | 46 | 50 | }; | 47 | 51 |
| 48 | 52 | function FiberRootNode( | @@ -184,6 +188,7 @@ export function createFiberRoot( | 184 | 188 | isDehydrated: hydrate, | 185 | 189 | cache: initialCache, | 186 | 190 | transitions: null, | | 191 | + pendingSuspenseBoundaries: null, | 187 | 192 | }; | 188 | 193 | uninitializedFiber.memoizedState = initialState; | 189 | 194 | } else { | @@ -192,6 +197,7 @@ export function createFiberRoot( | 192 | 197 | isDehydrated: hydrate, | 193 | 198 | cache: (null: any), // not enabled yet | 194 | 199 | transitions: null, | | 200 | + pendingSuspenseBoundaries: null, | 195 | 201 | }; | 196 | 202 | uninitializedFiber.memoizedState = initialState; | 197 | 203 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberRoot.old.js +8-2Lines changed: 8 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -15,7 +15,10 @@ import type { | 15 | 15 | } from './ReactInternalTypes'; | 16 | 16 | import type {RootTag} from './ReactRootTags'; | 17 | 17 | import type {Cache} from './ReactFiberCacheComponent.old'; | 18 | | -import type {Transition} from './ReactFiberTracingMarkerComponent.old'; | | 18 | +import type { | | 19 | + PendingSuspenseBoundaries, | | 20 | + Transition, | | 21 | +} from './ReactFiberTracingMarkerComponent.old'; | 19 | 22 |
| 20 | 23 | import {noTimeout, supportsHydration} from './ReactFiberHostConfig'; | 21 | 24 | import {createHostRootFiber} from './ReactFiber.old'; | @@ -42,7 +45,8 @@ export type RootState = { | 42 | 45 | element: any, | 43 | 46 | isDehydrated: boolean, | 44 | 47 | cache: Cache, | 45 | | - transitions: Array<Transition> | null, | | 48 | + pendingSuspenseBoundaries: PendingSuspenseBoundaries | null, | | 49 | + transitions: Set<Transition> | null, | 46 | 50 | }; | 47 | 51 |
| 48 | 52 | function FiberRootNode( | @@ -184,6 +188,7 @@ export function createFiberRoot( | 184 | 188 | isDehydrated: hydrate, | 185 | 189 | cache: initialCache, | 186 | 190 | transitions: null, | | 191 | + pendingSuspenseBoundaries: null, | 187 | 192 | }; | 188 | 193 | uninitializedFiber.memoizedState = initialState; | 189 | 194 | } else { | @@ -192,6 +197,7 @@ export function createFiberRoot( | 192 | 197 | isDehydrated: hydrate, | 193 | 198 | cache: (null: any), // not enabled yet | 194 | 199 | transitions: null, | | 200 | + pendingSuspenseBoundaries: null, | 195 | 201 | }; | 196 | 202 | uninitializedFiber.memoizedState = initialState; | 197 | 203 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberSuspenseComponent.new.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -29,6 +29,7 @@ export type SuspenseProps = {| | 29 | 29 | suspenseCallback?: (Set<Wakeable> | null) => mixed, | 30 | 30 |
| 31 | 31 | unstable_expectedLoadTime?: number, | | 32 | + unstable_name?: string, | 32 | 33 | |}; | 33 | 34 |
| 34 | 35 | // A null SuspenseState represents an unsuspended normal Suspense boundary. | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberSuspenseComponent.old.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -29,6 +29,7 @@ export type SuspenseProps = {| | 29 | 29 | suspenseCallback?: (Set<Wakeable> | null) => mixed, | 30 | 30 |
| 31 | 31 | unstable_expectedLoadTime?: number, | | 32 | + unstable_name?: string, | 32 | 33 | |}; | 33 | 34 |
| 34 | 35 | // A null SuspenseState represents an unsuspended normal Suspense boundary. | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberTracingMarkerComponent.new.js +4-6Lines changed: 4 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 7 | 7 | * @flow | 8 | 8 | */ | 9 | 9 |
| 10 | | -import type {TransitionTracingCallbacks} from './ReactInternalTypes'; | 11 | | -import type {Fiber} from 'react-reconciler/src/ReactInternalTypes'; | | 10 | +import type {TransitionTracingCallbacks, Fiber} from './ReactInternalTypes'; | | 11 | +import type {OffscreenInstance} from './ReactFiberOffscreenComponent'; | | 12 | + | 12 | 13 | import {enableTransitionTracing} from 'shared/ReactFeatureFlags'; | 13 | 14 |
| 14 | 15 | export type SuspenseInfo = {name: string | null}; | @@ -34,10 +35,7 @@ export type BatchConfigTransition = { | 34 | 35 | _updatedFibers?: Set<Fiber>, | 35 | 36 | }; | 36 | 37 |
| 37 | | -export type TransitionCallback = 0 | 1; | 38 | | - | 39 | | -export const TransitionStart = 0; | 40 | | -export const TransitionComplete = 1; | | 38 | +export type PendingSuspenseBoundaries = Map<OffscreenInstance, SuspenseInfo>; | 41 | 39 |
| 42 | 40 | export function processTransitionCallbacks( | 43 | 41 | pendingTransitions: PendingTransitionCallbacks, | |
|