GeezerVison is showing github.com — Revert "[Transition Tracing] Refactor Transition Tracing Root Code (#… · react/react@e61fd91
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 +9-28Lines changed: 9 additions & 28 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -27,7 +27,6 @@ import type { | 27 | 27 | OffscreenProps, | 28 | 28 | OffscreenState, | 29 | 29 | OffscreenQueue, | 30 | | - OffscreenInstance, | 31 | 30 | } from './ReactFiberOffscreenComponent'; | 32 | 31 | import type { | 33 | 32 | Cache, | @@ -263,9 +262,8 @@ import { | 263 | 262 | getPendingTransitions, | 264 | 263 | } from './ReactFiberTransition.new'; | 265 | 264 | import { | 266 | | - getMarkerInstances, | 267 | | - pushMarkerInstance, | 268 | | - pushRootMarkerInstance, | | 265 | + getTracingMarkers, | | 266 | + pushTracingMarker, | 269 | 267 | } from './ReactFiberTracingMarkerComponent.new'; | 270 | 268 |
| 271 | 269 | const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner; | @@ -781,10 +779,7 @@ function updateOffscreenComponent( | 781 | 779 | if (enableTransitionTracing) { | 782 | 780 | // We have now gone from hidden to visible, so any transitions should | 783 | 781 | // be added to the stack to get added to any Offscreen/suspense children | 784 | | - const instance: OffscreenInstance | null = workInProgress.stateNode; | 785 | | - if (instance !== null && instance.transitions != null) { | 786 | | - transitions = Array.from(instance.transitions); | 787 | | - } | | 782 | + transitions = workInProgress.stateNode.transitions; | 788 | 783 | } | 789 | 784 |
| 790 | 785 | pushTransition(workInProgress, prevCachePool, transitions); | @@ -914,10 +909,7 @@ function updateTracingMarkerComponent( | 914 | 909 | } | 915 | 910 | } | 916 | 911 |
| 917 | | - const instance: TracingMarkerInstance | null = workInProgress.stateNode; | 918 | | - if (instance !== null) { | 919 | | - pushMarkerInstance(workInProgress, instance); | 920 | | - } | | 912 | + pushTracingMarker(workInProgress); | 921 | 913 | const nextChildren = workInProgress.pendingProps.children; | 922 | 914 | reconcileChildren(current, workInProgress, nextChildren, renderLanes); | 923 | 915 | return workInProgress.child; | @@ -1321,10 +1313,6 @@ function updateHostRoot(current, workInProgress, renderLanes) { | 1321 | 1313 | const root: FiberRoot = workInProgress.stateNode; | 1322 | 1314 | pushRootTransition(workInProgress, root, renderLanes); | 1323 | 1315 |
| 1324 | | - if (enableTransitionTracing) { | 1325 | | - pushRootMarkerInstance(workInProgress); | 1326 | | - } | 1327 | | - | 1328 | 1316 | if (enableCache) { | 1329 | 1317 | const nextCache: Cache = nextState.cache; | 1330 | 1318 | pushCacheProvider(workInProgress, nextCache); | @@ -2110,10 +2098,10 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) { | 2110 | 2098 | const currentTransitions = getPendingTransitions(); | 2111 | 2099 | if (currentTransitions !== null) { | 2112 | 2100 | // If there are no transitions, we don't need to keep track of tracing markers | 2113 | | - const parentMarkerInstances = getMarkerInstances(); | | 2101 | + const currentTracingMarkers = getTracingMarkers(); | 2114 | 2102 | const primaryChildUpdateQueue: OffscreenQueue = { | 2115 | 2103 | transitions: currentTransitions, | 2116 | | - markerInstances: parentMarkerInstances, | | 2104 | + tracingMarkers: currentTracingMarkers, | 2117 | 2105 | }; | 2118 | 2106 | primaryChildFragment.updateQueue = primaryChildUpdateQueue; | 2119 | 2107 | } | @@ -2200,10 +2188,10 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) { | 2200 | 2188 | if (enableTransitionTracing) { | 2201 | 2189 | const currentTransitions = getPendingTransitions(); | 2202 | 2190 | if (currentTransitions !== null) { | 2203 | | - const parentMarkerInstances = getMarkerInstances(); | | 2191 | + const currentTracingMarkers = getTracingMarkers(); | 2204 | 2192 | const primaryChildUpdateQueue: OffscreenQueue = { | 2205 | 2193 | transitions: currentTransitions, | 2206 | | - markerInstances: parentMarkerInstances, | | 2194 | + tracingMarkers: currentTracingMarkers, | 2207 | 2195 | }; | 2208 | 2196 | primaryChildFragment.updateQueue = primaryChildUpdateQueue; | 2209 | 2197 | } | @@ -3521,10 +3509,6 @@ function attemptEarlyBailoutIfNoScheduledUpdate( | 3521 | 3509 | const root: FiberRoot = workInProgress.stateNode; | 3522 | 3510 | pushRootTransition(workInProgress, root, renderLanes); | 3523 | 3511 |
| 3524 | | - if (enableTransitionTracing) { | 3525 | | - pushRootMarkerInstance(workInProgress); | 3526 | | - } | 3527 | | - | 3528 | 3512 | if (enableCache) { | 3529 | 3513 | const cache: Cache = current.memoizedState.cache; | 3530 | 3514 | pushCacheProvider(workInProgress, cache); | @@ -3710,10 +3694,7 @@ function attemptEarlyBailoutIfNoScheduledUpdate( | 3710 | 3694 | } | 3711 | 3695 | case TracingMarkerComponent: { | 3712 | 3696 | if (enableTransitionTracing) { | 3713 | | - const instance: TracingMarkerInstance | null = workInProgress.stateNode; | 3714 | | - if (instance !== null) { | 3715 | | - pushMarkerInstance(workInProgress, instance); | 3716 | | - } | | 3697 | + pushTracingMarker(workInProgress); | 3717 | 3698 | } | 3718 | 3699 | } | 3719 | 3700 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberBeginWork.old.js +9-28Lines changed: 9 additions & 28 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -27,7 +27,6 @@ import type { | 27 | 27 | OffscreenProps, | 28 | 28 | OffscreenState, | 29 | 29 | OffscreenQueue, | 30 | | - OffscreenInstance, | 31 | 30 | } from './ReactFiberOffscreenComponent'; | 32 | 31 | import type { | 33 | 32 | Cache, | @@ -260,9 +259,8 @@ import { | 260 | 259 | getPendingTransitions, | 261 | 260 | } from './ReactFiberTransition.old'; | 262 | 261 | import { | 263 | | - getMarkerInstances, | 264 | | - pushMarkerInstance, | 265 | | - pushRootMarkerInstance, | | 262 | + getTracingMarkers, | | 263 | + pushTracingMarker, | 266 | 264 | } from './ReactFiberTracingMarkerComponent.old'; | 267 | 265 |
| 268 | 266 | const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner; | @@ -786,10 +784,7 @@ function updateOffscreenComponent( | 786 | 784 | if (enableTransitionTracing) { | 787 | 785 | // We have now gone from hidden to visible, so any transitions should | 788 | 786 | // be added to the stack to get added to any Offscreen/suspense children | 789 | | - const instance: OffscreenInstance | null = workInProgress.stateNode; | 790 | | - if (instance !== null && instance.transitions != null) { | 791 | | - transitions = Array.from(instance.transitions); | 792 | | - } | | 787 | + transitions = workInProgress.stateNode.transitions; | 793 | 788 | } | 794 | 789 |
| 795 | 790 | pushTransition(workInProgress, prevCachePool, transitions); | @@ -914,10 +909,7 @@ function updateTracingMarkerComponent( | 914 | 909 | } | 915 | 910 | } | 916 | 911 |
| 917 | | - const instance: TracingMarkerInstance | null = workInProgress.stateNode; | 918 | | - if (instance !== null) { | 919 | | - pushMarkerInstance(workInProgress, instance); | 920 | | - } | | 912 | + pushTracingMarker(workInProgress); | 921 | 913 | const nextChildren = workInProgress.pendingProps.children; | 922 | 914 | reconcileChildren(current, workInProgress, nextChildren, renderLanes); | 923 | 915 | return workInProgress.child; | @@ -1321,10 +1313,6 @@ function updateHostRoot(current, workInProgress, renderLanes) { | 1321 | 1313 | const root: FiberRoot = workInProgress.stateNode; | 1322 | 1314 | pushRootTransition(workInProgress, root, renderLanes); | 1323 | 1315 |
| 1324 | | - if (enableTransitionTracing) { | 1325 | | - pushRootMarkerInstance(workInProgress); | 1326 | | - } | 1327 | | - | 1328 | 1316 | if (enableCache) { | 1329 | 1317 | const nextCache: Cache = nextState.cache; | 1330 | 1318 | pushCacheProvider(workInProgress, nextCache); | @@ -2126,10 +2114,10 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) { | 2126 | 2114 | const currentTransitions = getPendingTransitions(); | 2127 | 2115 | if (currentTransitions !== null) { | 2128 | 2116 | // If there are no transitions, we don't need to keep track of tracing markers | 2129 | | - const parentMarkerInstances = getMarkerInstances(); | | 2117 | + const currentTracingMarkers = getTracingMarkers(); | 2130 | 2118 | const primaryChildUpdateQueue: OffscreenQueue = { | 2131 | 2119 | transitions: currentTransitions, | 2132 | | - markerInstances: parentMarkerInstances, | | 2120 | + tracingMarkers: currentTracingMarkers, | 2133 | 2121 | }; | 2134 | 2122 | primaryChildFragment.updateQueue = primaryChildUpdateQueue; | 2135 | 2123 | } | @@ -2212,10 +2200,10 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) { | 2212 | 2200 | if (enableTransitionTracing) { | 2213 | 2201 | const currentTransitions = getPendingTransitions(); | 2214 | 2202 | if (currentTransitions !== null) { | 2215 | | - const parentMarkerInstances = getMarkerInstances(); | | 2203 | + const currentTracingMarkers = getTracingMarkers(); | 2216 | 2204 | const primaryChildUpdateQueue: OffscreenQueue = { | 2217 | 2205 | transitions: currentTransitions, | 2218 | | - markerInstances: parentMarkerInstances, | | 2206 | + tracingMarkers: currentTracingMarkers, | 2219 | 2207 | }; | 2220 | 2208 | primaryChildFragment.updateQueue = primaryChildUpdateQueue; | 2221 | 2209 | } | @@ -3522,10 +3510,6 @@ function attemptEarlyBailoutIfNoScheduledUpdate( | 3522 | 3510 | const root: FiberRoot = workInProgress.stateNode; | 3523 | 3511 | pushRootTransition(workInProgress, root, renderLanes); | 3524 | 3512 |
| 3525 | | - if (enableTransitionTracing) { | 3526 | | - pushRootMarkerInstance(workInProgress); | 3527 | | - } | 3528 | | - | 3529 | 3513 | if (enableCache) { | 3530 | 3514 | const cache: Cache = current.memoizedState.cache; | 3531 | 3515 | pushCacheProvider(workInProgress, cache); | @@ -3718,10 +3702,7 @@ function attemptEarlyBailoutIfNoScheduledUpdate( | 3718 | 3702 | } | 3719 | 3703 | case TracingMarkerComponent: { | 3720 | 3704 | if (enableTransitionTracing) { | 3721 | | - const instance: TracingMarkerInstance | null = workInProgress.stateNode; | 3722 | | - if (instance !== null) { | 3723 | | - pushMarkerInstance(workInProgress, instance); | 3724 | | - } | | 3705 | + pushTracingMarker(workInProgress); | 3725 | 3706 | } | 3726 | 3707 | } | 3727 | 3708 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberCommitWork.new.js +63-30Lines changed: 63 additions & 30 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2811,35 +2811,47 @@ function commitPassiveMountOnFiber( | 2811 | 2811 | // Get the transitions that were initiatized during the render | 2812 | 2812 | // and add a start transition callback for each of them | 2813 | 2813 | const root = finishedWork.stateNode; | 2814 | | - const incompleteTransitions = root.incompleteTransitions; | | 2814 | + let incompleteTransitions = root.incompleteTransitions; | 2815 | 2815 | // Initial render | 2816 | 2816 | if (committedTransitions !== null) { | | 2817 | + if (incompleteTransitions === null) { | | 2818 | + root.incompleteTransitions = incompleteTransitions = new Map(); | | 2819 | + } | | 2820 | + | 2817 | 2821 | committedTransitions.forEach(transition => { | 2818 | 2822 | addTransitionStartCallbackToPendingTransition({ | 2819 | 2823 | transitionName: transition.name, | 2820 | 2824 | startTime: transition.startTime, | 2821 | 2825 | }); | | 2826 | + | | 2827 | + if (!incompleteTransitions.has(transition)) { | | 2828 | + incompleteTransitions.set(transition, null); | | 2829 | + } | 2822 | 2830 | }); | 2823 | 2831 |
| 2824 | 2832 | clearTransitionsForLanes(finishedRoot, committedLanes); | 2825 | 2833 | } | 2826 | 2834 |
| 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) { | 2833 | 2838 | addTransitionCompleteCallbackToPendingTransition({ | 2834 | 2839 | transitionName: transition.name, | 2835 | 2840 | startTime: transition.startTime, | 2836 | 2841 | }); | 2837 | 2842 | incompleteTransitions.delete(transition); | 2838 | 2843 | } | 2839 | | - }, | 2840 | | - ); | | 2844 | + }); | | 2845 | + } | 2841 | 2846 |
| 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 | + } | 2843 | 2855 | } | 2844 | 2856 | break; | 2845 | 2857 | } | @@ -2884,50 +2896,71 @@ function commitPassiveMountOnFiber( | 2884 | 2896 | if (isFallback) { | 2885 | 2897 | const transitions = queue.transitions; | 2886 | 2898 | let prevTransitions = instance.transitions; | | 2899 | + let rootIncompleteTransitions = 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 = new Map(); | | 2906 | + } | 2887 | 2907 | if (instance.pendingMarkers === null) { | 2888 | 2908 | instance.pendingMarkers = new Set(); | 2889 | 2909 | } | 2890 | 2910 | if (transitions !== null && prevTransitions === null) { | 2891 | 2911 | instance.transitions = prevTransitions = new Set(); | 2892 | 2912 | } | 2893 | 2913 |
| | 2914 | + // TODO(luna): Combine the root code with the tracing marker code | 2894 | 2915 | if (transitions !== null) { | 2895 | 2916 | transitions.forEach(transition => { | 2896 | 2917 | // Add all the transitions saved in the update queue during | 2897 | 2918 | // the render phase (ie the transitions associated with this boundary) | 2898 | 2919 | // into the transitions set. | 2899 | 2920 | prevTransitions.add(transition); | 2900 | | - }); | 2901 | | - } | 2902 | 2921 |
| 2903 | | - const markerInstances = queue.markerInstances; | 2904 | | - if (markerInstances !== null) { | 2905 | | - markerInstances.forEach(markerInstance => { | 2906 | | - if (markerInstance.pendingSuspenseBoundaries === null) { | 2907 | | - markerInstance.pendingSuspenseBoundaries = new Map(); | | 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, new Map()); | | 2929 | + } | | 2930 | + instance.pendingMarkers.add( | | 2931 | + rootIncompleteTransitions.get(transition), | | 2932 | + ); | 2908 | 2933 | } | | 2934 | + }); | | 2935 | + } | 2909 | 2936 |
| 2910 | | - const markerTransitions = markerInstance.transitions; | | 2937 | + const tracingMarkers = queue.tracingMarkers; | | 2938 | + if (tracingMarkers !== null) { | | 2939 | + tracingMarkers.forEach(marker => { | | 2940 | + const markerInstance = marker.stateNode; | 2911 | 2941 | // There should only be a few tracing marker transitions because | 2912 | 2942 | // they should be only associated with the transition that | 2913 | 2943 | // 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 | + }); | 2923 | 2951 | }); | 2924 | 2952 | } | 2925 | 2953 | } | 2926 | 2954 |
| 2927 | | - finishedWork.updateQueue = null; | 2928 | | - } | | 2955 | + commitTransitionProgress(finishedWork); | 2929 | 2956 |
| 2930 | | - commitTransitionProgress(finishedWork); | | 2957 | + if ( | | 2958 | + instance.pendingMarkers === null || | | 2959 | + instance.pendingMarkers.size === 0 | | 2960 | + ) { | | 2961 | + finishedWork.updateQueue = null; | | 2962 | + } | | 2963 | + } | 2931 | 2964 | } | 2932 | 2965 |
| 2933 | 2966 | break; | |
|