Skip to content

Commit

Permalink
old
Browse files Browse the repository at this point in the history
  • Loading branch information
lunaruan committed Jun 29, 2022
1 parent 03995a2 commit a320d29
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 44 deletions.
10 changes: 7 additions & 3 deletions packages/react-reconciler/src/ReactFiberBeginWork.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import type {
OffscreenProps,
OffscreenState,
OffscreenQueue,
OffscreenInstance,
} from './ReactFiberOffscreenComponent';
import type {
Cache,
Expand Down Expand Up @@ -785,7 +786,10 @@ function updateOffscreenComponent(
if (enableTransitionTracing) {
// We have now gone from hidden to visible, so any transitions should
// be added to the stack to get added to any Offscreen/suspense children
transitions = workInProgress.stateNode.transitions;
const instance: OffscreenInstance | null = workInProgress.stateNode;
if (instance !== null && instance.transitions !== null) {
transitions = Array.from(instance.transitions);
}
}

pushTransition(workInProgress, prevCachePool, transitions);
Expand Down Expand Up @@ -910,7 +914,7 @@ function updateTracingMarkerComponent(
}
}

const instance = workInProgress.stateNode;
const instance: TracingMarkerInstance | null = workInProgress.stateNode;
if (instance !== null) {
pushMarkerInstance(workInProgress, instance);
}
Expand Down Expand Up @@ -3714,7 +3718,7 @@ function attemptEarlyBailoutIfNoScheduledUpdate(
}
case TracingMarkerComponent: {
if (enableTransitionTracing) {
const instance: TracingMarkerInstance = workInProgress.stateNode;
const instance: TracingMarkerInstance | null = workInProgress.stateNode;
if (instance !== null) {
pushMarkerInstance(workInProgress, instance);
}
Expand Down
25 changes: 12 additions & 13 deletions packages/react-reconciler/src/ReactFiberCommitWork.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -2819,30 +2819,25 @@ function commitPassiveMountOnFiber(
transitionName: transition.name,
startTime: transition.startTime,
});

if (!incompleteTransitions.has(transition)) {
incompleteTransitions.set(transition, null);
}
});

clearTransitionsForLanes(finishedRoot, committedLanes);
}

if (incompleteTransitions !== null) {
incompleteTransitions.forEach((pendingBoundaries, transition) => {
if (pendingBoundaries === null || pendingBoundaries.size === 0) {
incompleteTransitions.forEach(
({pendingSuspenseBoundaries}, transition) => {
if (
pendingSuspenseBoundaries === null ||
pendingSuspenseBoundaries.size === 0
) {
addTransitionCompleteCallbackToPendingTransition({
transitionName: transition.name,
startTime: transition.startTime,
});
incompleteTransitions.delete(transition);
}
});

if (incompleteTransitions.size === 0) {
root.incompleteTransitions = null;
}
}
},
);

clearTransitionsForLanes(finishedRoot, committedLanes);
}
Expand Down Expand Up @@ -2908,6 +2903,10 @@ function commitPassiveMountOnFiber(
const markerInstances = queue.markerInstances;
if (markerInstances !== null) {
markerInstances.forEach(markerInstance => {
if (markerInstance.pendingSuspenseBoundaries === null) {
markerInstance.pendingSuspenseBoundaries = new Map();
}

const markerTransitions = markerInstance.transitions;
// There should only be a few tracing marker transitions because
// they should be only associated with the transition that
Expand Down
4 changes: 3 additions & 1 deletion packages/react-reconciler/src/ReactFiberCompleteWork.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import type {
} from './ReactFiberSuspenseComponent.old';
import type {SuspenseContext} from './ReactFiberSuspenseContext.old';
import type {OffscreenState} from './ReactFiberOffscreenComponent';
import type {TracingMarkerInstance} from './ReactFiberTracingMarkerComponent.old';
import type {Cache} from './ReactFiberCacheComponent.old';
import {
enableSuspenseAvoidThisFallback,
Expand Down Expand Up @@ -1589,7 +1590,8 @@ function completeWork(
}
case TracingMarkerComponent: {
if (enableTransitionTracing) {
if (workInProgress.stateNode !== null) {
const instance: TracingMarkerInstance | null = workInProgress.stateNode;
if (instance !== null) {
popMarkerInstance(workInProgress);
}
bubbleProperties(workInProgress);
Expand Down
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactFiberRoot.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function FiberRootNode(
for (let i = 0; i < TotalLanes; i++) {
transitionLanesMap.push(null);
}
this.incompleteTransitions = null;
this.incompleteTransitions = new Map();
}

if (enableProfilerTimer && enableProfilerCommitHooks) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,36 +117,26 @@ export function pushRootMarkerInstance(workInProgress: Fiber): void {
// marker does, so we can push it onto the marker instance stack
const transitions = getWorkInProgressTransitions();
const root = workInProgress.stateNode;
let incompleteTransitions = root.incompleteTransitions;
if (transitions !== null) {
// Create a mapping from transition to suspense boundaries
// We instantiate this lazily, only if transitions exist
if (incompleteTransitions === null) {
root.incompleteTransitions = incompleteTransitions = new Map();
}

if (transitions !== null) {
transitions.forEach(transition => {
// We need to create a new map here because we only have access to the
// object instance in the commit phase
incompleteTransitions.set(transition, new Map());
if (!root.incompleteTransitions.has(transition)) {
root.incompleteTransitions.set(transition, {
transitions: new Set([transition]),
pendingSuspenseBoundaries: null,
});
}
});
}

if (incompleteTransitions === null) {
push(markerInstanceStack, null, workInProgress);
} else {
const markerInstances = [];
// For ever transition on the suspense boundary, we push the transition
// along with its map of pending suspense boundaries onto the marker
// instance stack.
incompleteTransitions.forEach((pendingSuspenseBoundaries, transition) => {
markerInstances.push({
transitions: new Set([transition]),
pendingSuspenseBoundaries,
});
});
push(markerInstanceStack, markerInstances, workInProgress);
}
const markerInstances = [];
// For ever transition on the suspense boundary, we push the transition
// along with its map of pending suspense boundaries onto the marker
// instance stack.
root.incompleteTransitions.forEach(markerInstance => {
markerInstances.push(markerInstance);
});
push(markerInstanceStack, markerInstances, workInProgress);
}
}

Expand Down
5 changes: 4 additions & 1 deletion packages/react-reconciler/src/ReactFiberUnwindWork.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {Fiber, FiberRoot} from './ReactInternalTypes';
import type {Lanes} from './ReactFiberLane.old';
import type {SuspenseState} from './ReactFiberSuspenseComponent.old';
import type {Cache} from './ReactFiberCacheComponent.old';
import type {TracingMarkerInstance} from './ReactFiberTracingMarkerComponent.old';

import {resetWorkInProgressVersions as resetMutableSourceWorkInProgressVersions} from './ReactMutableSource.old';
import {
Expand Down Expand Up @@ -245,7 +246,9 @@ function unwindInterruptedWork(
break;
case TracingMarkerComponent:
if (enableTransitionTracing) {
if (interruptedWork.stateNode !== null) {
const instance: TracingMarkerInstance | null =
interruptedWork.stateNode;
if (instance !== null) {
popMarkerInstance(interruptedWork);
}
}
Expand Down

0 comments on commit a320d29

Please sign in to comment.