Skip to content

Commit 4ee0c29

Browse files
committed
old
1 parent b3ceed9 commit 4ee0c29

File tree

6 files changed

+90
-6
lines changed

6 files changed

+90
-6
lines changed

packages/react-reconciler/src/ReactFiber.old.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import type {
1919
OffscreenProps,
2020
OffscreenInstance,
2121
} from './ReactFiberOffscreenComponent';
22+
import type {TracingMarkerInstance} from './ReactFiberTracingMarkerComponent.old';
2223

2324
import {
2425
createRootStrictEffectsByDefault,
@@ -757,6 +758,11 @@ export function createFiberFromTracingMarker(
757758
const fiber = createFiber(TracingMarkerComponent, pendingProps, key, mode);
758759
fiber.elementType = REACT_TRACING_MARKER_TYPE;
759760
fiber.lanes = lanes;
761+
const tracingMarkerInstance: TracingMarkerInstance = {
762+
transitions: null,
763+
pendingSuspenseBoundaries: null,
764+
};
765+
fiber.stateNode = tracingMarkerInstance;
760766
return fiber;
761767
}
762768

packages/react-reconciler/src/ReactFiberBeginWork.old.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import type {
3535
} from './ReactFiberCacheComponent.old';
3636
import type {UpdateQueue} from './ReactFiberClassUpdateQueue.old';
3737
import type {RootState} from './ReactFiberRoot.old';
38+
import type {TracingMarkerInstance} from './ReactFiberTracingMarkerComponent.old';
3839
import {
3940
enableSuspenseAvoidThisFallback,
4041
enableCPUSuspense,
@@ -255,9 +256,12 @@ import {
255256
getSuspendedCache,
256257
pushTransition,
257258
getOffscreenDeferredCache,
258-
getSuspendedTransitions,
259+
getPendingTransitions,
259260
} from './ReactFiberTransition.old';
260-
import {pushTracingMarker} from './ReactFiberTracingMarkerComponent.old';
261+
import {
262+
getTracingMarkers,
263+
pushTracingMarker,
264+
} from './ReactFiberTracingMarkerComponent.old';
261265

262266
const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
263267

@@ -891,6 +895,20 @@ function updateTracingMarkerComponent(
891895
return null;
892896
}
893897

898+
// TODO: (luna) Only update the tracing marker if it's newly rendered or it's name changed.
899+
// A tracing marker is only associated with the transitions that rendered
900+
// or updated it, so we can create a new set of transitions each time
901+
if (current === null) {
902+
const currentTransitions = getPendingTransitions();
903+
if (currentTransitions !== null) {
904+
const markerInstance: TracingMarkerInstance = {
905+
transitions: new Set(currentTransitions),
906+
pendingSuspenseBoundaries: new Map(),
907+
};
908+
workInProgress.stateNode = markerInstance;
909+
}
910+
}
911+
894912
pushTracingMarker(workInProgress);
895913
const nextChildren = workInProgress.pendingProps.children;
896914
reconcileChildren(current, workInProgress, nextChildren, renderLanes);
@@ -2094,10 +2112,13 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) {
20942112
);
20952113
workInProgress.memoizedState = SUSPENDED_MARKER;
20962114
if (enableTransitionTracing) {
2097-
const currentTransitions = getSuspendedTransitions();
2115+
const currentTransitions = getPendingTransitions();
20982116
if (currentTransitions !== null) {
2117+
// If there are no transitions, we don't need to keep track of tracing markers
2118+
const currentTracingMarkers = getTracingMarkers();
20992119
const primaryChildUpdateQueue: OffscreenQueue = {
21002120
transitions: currentTransitions,
2121+
tracingMarkers: currentTracingMarkers,
21012122
};
21022123
primaryChildFragment.updateQueue = primaryChildUpdateQueue;
21032124
}
@@ -2178,10 +2199,12 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) {
21782199
? mountSuspenseOffscreenState(renderLanes)
21792200
: updateSuspenseOffscreenState(prevOffscreenState, renderLanes);
21802201
if (enableTransitionTracing) {
2181-
const currentTransitions = getSuspendedTransitions();
2202+
const currentTransitions = getPendingTransitions();
21822203
if (currentTransitions !== null) {
2204+
const currentTracingMarkers = getTracingMarkers();
21832205
const primaryChildUpdateQueue: OffscreenQueue = {
21842206
transitions: currentTransitions,
2207+
tracingMarkers: currentTracingMarkers,
21852208
};
21862209
primaryChildFragment.updateQueue = primaryChildUpdateQueue;
21872210
}

packages/react-reconciler/src/ReactFiberCommitWork.old.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ import {
138138
restorePendingUpdaters,
139139
addTransitionStartCallbackToPendingTransition,
140140
addTransitionCompleteCallbackToPendingTransition,
141+
addMarkerCompleteCallbackToPendingTransition,
141142
setIsRunningInsertionEffect,
142143
} from './ReactFiberWorkLoop.old';
143144
import {
@@ -2913,6 +2914,7 @@ function commitPassiveMountOnFiber(
29132914
instance.transitions = prevTransitions = new Set();
29142915
}
29152916

2917+
// TODO(luna): Combine the root code with the tracing marker code
29162918
if (transitions !== null) {
29172919
transitions.forEach(transition => {
29182920
// Add all the transitions saved in the update queue during
@@ -2932,6 +2934,23 @@ function commitPassiveMountOnFiber(
29322934
);
29332935
});
29342936
}
2937+
2938+
const tracingMarkers = queue.tracingMarkers;
2939+
if (tracingMarkers !== null) {
2940+
tracingMarkers.forEach(marker => {
2941+
const markerInstance = marker.stateNode;
2942+
// There should only be a few tracing marker transitions because
2943+
// they should be only associated with the transition that
2944+
// caused them
2945+
markerInstance.transitions.forEach(transition => {
2946+
if (instance.transitions.has(transition)) {
2947+
instance.pendingMarkers.add(
2948+
markerInstance.pendingSuspenseBoundaries,
2949+
);
2950+
}
2951+
});
2952+
});
2953+
}
29352954
}
29362955

29372956
commitTransitionProgress(finishedWork);
@@ -2968,6 +2987,28 @@ function commitPassiveMountOnFiber(
29682987
}
29692988
break;
29702989
}
2990+
case TracingMarkerComponent: {
2991+
if (enableTransitionTracing) {
2992+
// Get the transitions that were initiatized during the render
2993+
// and add a start transition callback for each of them
2994+
const instance = finishedWork.stateNode;
2995+
if (
2996+
instance.pendingSuspenseBoundaries === null ||
2997+
instance.pendingSuspenseBoundaries.size === 0
2998+
) {
2999+
instance.transitions.forEach(transition => {
3000+
addMarkerCompleteCallbackToPendingTransition({
3001+
transitionName: transition.name,
3002+
startTime: transition.startTime,
3003+
markerName: finishedWork.memoizedProps.name,
3004+
});
3005+
});
3006+
instance.transitions = null;
3007+
instance.pendingSuspenseBoundaries = null;
3008+
}
3009+
}
3010+
break;
3011+
}
29713012
}
29723013
}
29733014

packages/react-reconciler/src/ReactFiberCompleteWork.old.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1581,9 +1581,18 @@ function completeWork(
15811581
}
15821582
case TracingMarkerComponent: {
15831583
if (enableTransitionTracing) {
1584-
// Bubble subtree flags before so we can set the flag property
15851584
popTracingMarker(workInProgress);
15861585
bubbleProperties(workInProgress);
1586+
1587+
if (
1588+
current === null ||
1589+
(workInProgress.subtreeFlags & Visibility) !== NoFlags
1590+
) {
1591+
// If any of our suspense children toggle visibility, this means that
1592+
// the pending boundaries array needs to be updated, which we only
1593+
// do in the passive phase.
1594+
workInProgress.flags |= Passive;
1595+
}
15871596
}
15881597
return null;
15891598
}

packages/react-reconciler/src/ReactFiberTracingMarkerComponent.old.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ export type BatchConfigTransition = {
3939
_updatedFibers?: Set<Fiber>,
4040
};
4141

42+
export type TracingMarkerInstance = {|
43+
pendingSuspenseBoundaries: PendingSuspenseBoundaries | null,
44+
transitions: Set<Transition> | null,
45+
|} | null;
46+
4247
export type PendingSuspenseBoundaries = Map<OffscreenInstance, SuspenseInfo>;
4348

4449
export function processTransitionCallbacks(

packages/react-reconciler/src/ReactFiberTransition.old.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export function popTransition(workInProgress: Fiber, current: Fiber | null) {
149149
}
150150
}
151151

152-
export function getSuspendedTransitions(): Array<Transition> | null {
152+
export function getPendingTransitions(): Array<Transition> | null {
153153
if (!enableTransitionTracing) {
154154
return null;
155155
}

0 commit comments

Comments
 (0)