Skip to content

Commit e61fd91

Browse files
authored
Revert "[Transition Tracing] Refactor Transition Tracing Root Code (#24766)" (#24829)
This reverts commit 4012963 because it's failing on main, likely due to conflict with something that landed before the PR was merged. Need to rebase and fix.
1 parent 4012963 commit e61fd91

14 files changed

Lines changed: 179 additions & 309 deletions

‎packages/react-reconciler/src/ReactFiberBeginWork.new.js‎

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import type {
2727
OffscreenProps,
2828
OffscreenState,
2929
OffscreenQueue,
30-
OffscreenInstance,
3130
}from'./ReactFiberOffscreenComponent';
3231
importtype{
3332
Cache,
@@ -263,9 +262,8 @@ import {
263262
getPendingTransitions,
264263
}from'./ReactFiberTransition.new';
265264
import{
266-
getMarkerInstances,
267-
pushMarkerInstance,
268-
pushRootMarkerInstance,
265+
getTracingMarkers,
266+
pushTracingMarker,
269267
}from'./ReactFiberTracingMarkerComponent.new';
270268

271269
constReactCurrentOwner=ReactSharedInternals.ReactCurrentOwner;
@@ -781,10 +779,7 @@ function updateOffscreenComponent(
781779
if(enableTransitionTracing){
782780
// We have now gone from hidden to visible, so any transitions should
783781
// be added to the stack to get added to any Offscreen/suspense children
784-
constinstance: OffscreenInstance|null=workInProgress.stateNode;
785-
if(instance!==null&&instance.transitions!=null){
786-
transitions=Array.from(instance.transitions);
787-
}
782+
transitions=workInProgress.stateNode.transitions;
788783
}
789784

790785
pushTransition(workInProgress,prevCachePool,transitions);
@@ -914,10 +909,7 @@ function updateTracingMarkerComponent(
914909
}
915910
}
916911

917-
constinstance: TracingMarkerInstance|null=workInProgress.stateNode;
918-
if(instance!==null){
919-
pushMarkerInstance(workInProgress,instance);
920-
}
912+
pushTracingMarker(workInProgress);
921913
constnextChildren=workInProgress.pendingProps.children;
922914
reconcileChildren(current,workInProgress,nextChildren,renderLanes);
923915
returnworkInProgress.child;
@@ -1321,10 +1313,6 @@ function updateHostRoot(current, workInProgress, renderLanes) {
13211313
constroot: FiberRoot=workInProgress.stateNode;
13221314
pushRootTransition(workInProgress,root,renderLanes);
13231315

1324-
if(enableTransitionTracing){
1325-
pushRootMarkerInstance(workInProgress);
1326-
}
1327-
13281316
if(enableCache){
13291317
constnextCache: Cache=nextState.cache;
13301318
pushCacheProvider(workInProgress,nextCache);
@@ -2110,10 +2098,10 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) {
21102098
constcurrentTransitions=getPendingTransitions();
21112099
if(currentTransitions!==null){
21122100
// If there are no transitions, we don't need to keep track of tracing markers
2113-
constparentMarkerInstances=getMarkerInstances();
2101+
constcurrentTracingMarkers=getTracingMarkers();
21142102
constprimaryChildUpdateQueue: OffscreenQueue={
21152103
transitions: currentTransitions,
2116-
markerInstances: parentMarkerInstances,
2104+
tracingMarkers: currentTracingMarkers,
21172105
};
21182106
primaryChildFragment.updateQueue=primaryChildUpdateQueue;
21192107
}
@@ -2200,10 +2188,10 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) {
22002188
if(enableTransitionTracing){
22012189
constcurrentTransitions=getPendingTransitions();
22022190
if(currentTransitions!==null){
2203-
constparentMarkerInstances=getMarkerInstances();
2191+
constcurrentTracingMarkers=getTracingMarkers();
22042192
constprimaryChildUpdateQueue: OffscreenQueue={
22052193
transitions: currentTransitions,
2206-
markerInstances: parentMarkerInstances,
2194+
tracingMarkers: currentTracingMarkers,
22072195
};
22082196
primaryChildFragment.updateQueue=primaryChildUpdateQueue;
22092197
}
@@ -3521,10 +3509,6 @@ function attemptEarlyBailoutIfNoScheduledUpdate(
35213509
constroot: FiberRoot=workInProgress.stateNode;
35223510
pushRootTransition(workInProgress,root,renderLanes);
35233511

3524-
if(enableTransitionTracing){
3525-
pushRootMarkerInstance(workInProgress);
3526-
}
3527-
35283512
if(enableCache){
35293513
constcache: Cache=current.memoizedState.cache;
35303514
pushCacheProvider(workInProgress,cache);
@@ -3710,10 +3694,7 @@ function attemptEarlyBailoutIfNoScheduledUpdate(
37103694
}
37113695
case TracingMarkerComponent: {
37123696
if(enableTransitionTracing){
3713-
constinstance: TracingMarkerInstance|null=workInProgress.stateNode;
3714-
if(instance!==null){
3715-
pushMarkerInstance(workInProgress,instance);
3716-
}
3697+
pushTracingMarker(workInProgress);
37173698
}
37183699
}
37193700
}

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

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import type {
2727
OffscreenProps,
2828
OffscreenState,
2929
OffscreenQueue,
30-
OffscreenInstance,
3130
}from'./ReactFiberOffscreenComponent';
3231
importtype{
3332
Cache,
@@ -260,9 +259,8 @@ import {
260259
getPendingTransitions,
261260
}from'./ReactFiberTransition.old';
262261
import{
263-
getMarkerInstances,
264-
pushMarkerInstance,
265-
pushRootMarkerInstance,
262+
getTracingMarkers,
263+
pushTracingMarker,
266264
}from'./ReactFiberTracingMarkerComponent.old';
267265

268266
constReactCurrentOwner=ReactSharedInternals.ReactCurrentOwner;
@@ -786,10 +784,7 @@ function updateOffscreenComponent(
786784
if(enableTransitionTracing){
787785
// We have now gone from hidden to visible, so any transitions should
788786
// be added to the stack to get added to any Offscreen/suspense children
789-
constinstance: OffscreenInstance|null=workInProgress.stateNode;
790-
if(instance!==null&&instance.transitions!=null){
791-
transitions=Array.from(instance.transitions);
792-
}
787+
transitions=workInProgress.stateNode.transitions;
793788
}
794789

795790
pushTransition(workInProgress,prevCachePool,transitions);
@@ -914,10 +909,7 @@ function updateTracingMarkerComponent(
914909
}
915910
}
916911

917-
constinstance: TracingMarkerInstance|null=workInProgress.stateNode;
918-
if(instance!==null){
919-
pushMarkerInstance(workInProgress,instance);
920-
}
912+
pushTracingMarker(workInProgress);
921913
constnextChildren=workInProgress.pendingProps.children;
922914
reconcileChildren(current,workInProgress,nextChildren,renderLanes);
923915
returnworkInProgress.child;
@@ -1321,10 +1313,6 @@ function updateHostRoot(current, workInProgress, renderLanes) {
13211313
constroot: FiberRoot=workInProgress.stateNode;
13221314
pushRootTransition(workInProgress,root,renderLanes);
13231315

1324-
if(enableTransitionTracing){
1325-
pushRootMarkerInstance(workInProgress);
1326-
}
1327-
13281316
if(enableCache){
13291317
constnextCache: Cache=nextState.cache;
13301318
pushCacheProvider(workInProgress,nextCache);
@@ -2126,10 +2114,10 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) {
21262114
constcurrentTransitions=getPendingTransitions();
21272115
if(currentTransitions!==null){
21282116
// If there are no transitions, we don't need to keep track of tracing markers
2129-
constparentMarkerInstances=getMarkerInstances();
2117+
constcurrentTracingMarkers=getTracingMarkers();
21302118
constprimaryChildUpdateQueue: OffscreenQueue={
21312119
transitions: currentTransitions,
2132-
markerInstances: parentMarkerInstances,
2120+
tracingMarkers: currentTracingMarkers,
21332121
};
21342122
primaryChildFragment.updateQueue=primaryChildUpdateQueue;
21352123
}
@@ -2212,10 +2200,10 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) {
22122200
if(enableTransitionTracing){
22132201
constcurrentTransitions=getPendingTransitions();
22142202
if(currentTransitions!==null){
2215-
constparentMarkerInstances=getMarkerInstances();
2203+
constcurrentTracingMarkers=getTracingMarkers();
22162204
constprimaryChildUpdateQueue: OffscreenQueue={
22172205
transitions: currentTransitions,
2218-
markerInstances: parentMarkerInstances,
2206+
tracingMarkers: currentTracingMarkers,
22192207
};
22202208
primaryChildFragment.updateQueue=primaryChildUpdateQueue;
22212209
}
@@ -3522,10 +3510,6 @@ function attemptEarlyBailoutIfNoScheduledUpdate(
35223510
constroot: FiberRoot=workInProgress.stateNode;
35233511
pushRootTransition(workInProgress,root,renderLanes);
35243512

3525-
if(enableTransitionTracing){
3526-
pushRootMarkerInstance(workInProgress);
3527-
}
3528-
35293513
if(enableCache){
35303514
constcache: Cache=current.memoizedState.cache;
35313515
pushCacheProvider(workInProgress,cache);
@@ -3718,10 +3702,7 @@ function attemptEarlyBailoutIfNoScheduledUpdate(
37183702
}
37193703
case TracingMarkerComponent: {
37203704
if(enableTransitionTracing){
3721-
constinstance: TracingMarkerInstance|null=workInProgress.stateNode;
3722-
if(instance!==null){
3723-
pushMarkerInstance(workInProgress,instance);
3724-
}
3705+
pushTracingMarker(workInProgress);
37253706
}
37263707
}
37273708
}

‎packages/react-reconciler/src/ReactFiberCommitWork.new.js‎

Lines changed: 63 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2811,35 +2811,47 @@ function commitPassiveMountOnFiber(
28112811
// Get the transitions that were initiatized during the render
28122812
// and add a start transition callback for each of them
28132813
constroot=finishedWork.stateNode;
2814-
constincompleteTransitions=root.incompleteTransitions;
2814+
letincompleteTransitions=root.incompleteTransitions;
28152815
// Initial render
28162816
if(committedTransitions!==null){
2817+
if(incompleteTransitions===null){
2818+
root.incompleteTransitions=incompleteTransitions=newMap();
2819+
}
2820+
28172821
committedTransitions.forEach(transition=>{
28182822
addTransitionStartCallbackToPendingTransition({
28192823
transitionName: transition.name,
28202824
startTime: transition.startTime,
28212825
});
2826+
2827+
if(!incompleteTransitions.has(transition)){
2828+
incompleteTransitions.set(transition,null);
2829+
}
28222830
});
28232831

28242832
clearTransitionsForLanes(finishedRoot,committedLanes);
28252833
}
28262834

2827-
incompleteTransitions.forEach(
2828-
({pendingSuspenseBoundaries},transition)=>{
2829-
if(
2830-
pendingSuspenseBoundaries===null||
2831-
pendingSuspenseBoundaries.size===0
2832-
){
2835+
if(incompleteTransitions!==null){
2836+
incompleteTransitions.forEach((pendingBoundaries,transition)=>{
2837+
if(pendingBoundaries===null||pendingBoundaries.size===0){
28332838
addTransitionCompleteCallbackToPendingTransition({
28342839
transitionName: transition.name,
28352840
startTime: transition.startTime,
28362841
});
28372842
incompleteTransitions.delete(transition);
28382843
}
2839-
},
2840-
);
2844+
});
2845+
}
28412846

2842-
clearTransitionsForLanes(finishedRoot,committedLanes);
2847+
// If there are no more pending suspense boundaries we
2848+
// clear the transitions because they are all complete.
2849+
if(
2850+
incompleteTransitions===null||
2851+
incompleteTransitions.size===0
2852+
){
2853+
root.incompleteTransitions=null;
2854+
}
28432855
}
28442856
break;
28452857
}
@@ -2884,50 +2896,71 @@ function commitPassiveMountOnFiber(
28842896
if(isFallback){
28852897
consttransitions=queue.transitions;
28862898
letprevTransitions=instance.transitions;
2899+
letrootIncompleteTransitions=finishedRoot.incompleteTransitions;
2900+
2901+
// We lazily instantiate transition tracing relevant maps
2902+
// and sets in the commit phase as we need to use them. We only
2903+
// instantiate them in the fallback phase on an as needed basis
2904+
if(rootIncompleteTransitions===null){
2905+
finishedRoot.incompleteTransitions=rootIncompleteTransitions=newMap();
2906+
}
28872907
if(instance.pendingMarkers===null){
28882908
instance.pendingMarkers=newSet();
28892909
}
28902910
if(transitions!==null&&prevTransitions===null){
28912911
instance.transitions=prevTransitions=newSet();
28922912
}
28932913

2914+
// TODO(luna): Combine the root code with the tracing marker code
28942915
if(transitions!==null){
28952916
transitions.forEach(transition=>{
28962917
// Add all the transitions saved in the update queue during
28972918
// the render phase (ie the transitions associated with this boundary)
28982919
// into the transitions set.
28992920
prevTransitions.add(transition);
2900-
});
2901-
}
29022921

2903-
constmarkerInstances=queue.markerInstances;
2904-
if(markerInstances!==null){
2905-
markerInstances.forEach(markerInstance=>{
2906-
if(markerInstance.pendingSuspenseBoundaries===null){
2907-
markerInstance.pendingSuspenseBoundaries=newMap();
2922+
// Add the root transition's pending suspense boundary set to
2923+
// the queue's marker set. We will iterate through the marker
2924+
// set when we toggle state on the suspense boundary and
2925+
// add or remove the pending suspense boundaries as needed.
2926+
if(rootIncompleteTransitions!==null){
2927+
if(!rootIncompleteTransitions.has(transition)){
2928+
rootIncompleteTransitions.set(transition,newMap());
2929+
}
2930+
instance.pendingMarkers.add(
2931+
rootIncompleteTransitions.get(transition),
2932+
);
29082933
}
2934+
});
2935+
}
29092936

2910-
constmarkerTransitions=markerInstance.transitions;
2937+
consttracingMarkers=queue.tracingMarkers;
2938+
if(tracingMarkers!==null){
2939+
tracingMarkers.forEach(marker=>{
2940+
constmarkerInstance=marker.stateNode;
29112941
// There should only be a few tracing marker transitions because
29122942
// they should be only associated with the transition that
29132943
// caused them
2914-
if(markerTransitions!==null){
2915-
markerTransitions.forEach(transition=>{
2916-
if(instance.transitions.has(transition)){
2917-
instance.pendingMarkers.add(
2918-
markerInstance.pendingSuspenseBoundaries,
2919-
);
2920-
}
2921-
});
2922-
}
2944+
markerInstance.transitions.forEach(transition=>{
2945+
if(instance.transitions.has(transition)){
2946+
instance.pendingMarkers.add(
2947+
markerInstance.pendingSuspenseBoundaries,
2948+
);
2949+
}
2950+
});
29232951
});
29242952
}
29252953
}
29262954

2927-
finishedWork.updateQueue=null;
2928-
}
2955+
commitTransitionProgress(finishedWork);
29292956

2930-
commitTransitionProgress(finishedWork);
2957+
if(
2958+
instance.pendingMarkers===null||
2959+
instance.pendingMarkers.size===0
2960+
){
2961+
finishedWork.updateQueue=null;
2962+
}
2963+
}
29312964
}
29322965

29332966
break;

0 commit comments

Comments
 (0)