GeezerVison is showing github.com — [DevTools][Transition Tracing] onTransitionComplete and onTransitionS… · react/react@42f15b3
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-debug-tools/src/ReactDebugHooks.js +5-1Lines changed: 5 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -13,6 +13,7 @@ import type { | 13 | 13 | MutableSourceSubscribeFn, | 14 | 14 | ReactContext, | 15 | 15 | ReactProviderType, | | 16 | + StartTransitionOptions, | 16 | 17 | } from 'shared/ReactTypes'; | 17 | 18 | import type { | 18 | 19 | Fiber, | @@ -291,7 +292,10 @@ function useSyncExternalStore<T>( | 291 | 292 | return value; | 292 | 293 | } | 293 | 294 |
| 294 | | -function useTransition(): [boolean, (() => void) => void] { | | 295 | +function useTransition(): [ | | 296 | + boolean, | | 297 | + (callback: () => void, options?: StartTransitionOptions) => void, | | 298 | +] { | 295 | 299 | // useTransition() composes multiple hooks internally. | 296 | 300 | // Advance the current hook index the same number of times | 297 | 301 | // so that subsequent hooks have the right memoized state. | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberBeginWork.new.js +9-1Lines changed: 9 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -226,6 +226,7 @@ import { | 226 | 226 | markSkippedUpdateLanes, | 227 | 227 | getWorkInProgressRoot, | 228 | 228 | pushRenderLanes, | | 229 | + getWorkInProgressTransitions, | 229 | 230 | } from './ReactFiberWorkLoop.new'; | 230 | 231 | import {setWorkInProgressVersion} from './ReactMutableSource.new'; | 231 | 232 | import { | @@ -1336,6 +1337,10 @@ function updateHostRoot(current, workInProgress, renderLanes) { | 1336 | 1337 | } | 1337 | 1338 | } | 1338 | 1339 |
| | 1340 | + if (enableTransitionTracing) { | | 1341 | + workInProgress.memoizedState.transitions = getWorkInProgressTransitions(); | | 1342 | + } | | 1343 | + | 1339 | 1344 | // Caution: React DevTools currently depends on this property | 1340 | 1345 | // being called "element". | 1341 | 1346 | const nextChildren = nextState.element; | @@ -3495,12 +3500,15 @@ function attemptEarlyBailoutIfNoScheduledUpdate( | 3495 | 3500 | switch (workInProgress.tag) { | 3496 | 3501 | case HostRoot: | 3497 | 3502 | pushHostRootContext(workInProgress); | | 3503 | + const root: FiberRoot = workInProgress.stateNode; | 3498 | 3504 | if (enableCache) { | 3499 | | - const root: FiberRoot = workInProgress.stateNode; | 3500 | 3505 | const cache: Cache = current.memoizedState.cache; | 3501 | 3506 | pushCacheProvider(workInProgress, cache); | 3502 | 3507 | pushRootCachePool(root); | 3503 | 3508 | } | | 3509 | + if (enableTransitionTracing) { | | 3510 | + workInProgress.memoizedState.transitions = getWorkInProgressTransitions(); | | 3511 | + } | 3504 | 3512 | resetHydrationState(); | 3505 | 3513 | break; | 3506 | 3514 | case HostComponent: | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberBeginWork.old.js +9-1Lines changed: 9 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -226,6 +226,7 @@ import { | 226 | 226 | markSkippedUpdateLanes, | 227 | 227 | getWorkInProgressRoot, | 228 | 228 | pushRenderLanes, | | 229 | + getWorkInProgressTransitions, | 229 | 230 | } from './ReactFiberWorkLoop.old'; | 230 | 231 | import {setWorkInProgressVersion} from './ReactMutableSource.old'; | 231 | 232 | import { | @@ -1336,6 +1337,10 @@ function updateHostRoot(current, workInProgress, renderLanes) { | 1336 | 1337 | } | 1337 | 1338 | } | 1338 | 1339 |
| | 1340 | + if (enableTransitionTracing) { | | 1341 | + workInProgress.memoizedState.transitions = getWorkInProgressTransitions(); | | 1342 | + } | | 1343 | + | 1339 | 1344 | // Caution: React DevTools currently depends on this property | 1340 | 1345 | // being called "element". | 1341 | 1346 | const nextChildren = nextState.element; | @@ -3495,12 +3500,15 @@ function attemptEarlyBailoutIfNoScheduledUpdate( | 3495 | 3500 | switch (workInProgress.tag) { | 3496 | 3501 | case HostRoot: | 3497 | 3502 | pushHostRootContext(workInProgress); | | 3503 | + const root: FiberRoot = workInProgress.stateNode; | 3498 | 3504 | if (enableCache) { | 3499 | | - const root: FiberRoot = workInProgress.stateNode; | 3500 | 3505 | const cache: Cache = current.memoizedState.cache; | 3501 | 3506 | pushCacheProvider(workInProgress, cache); | 3502 | 3507 | pushRootCachePool(root); | 3503 | 3508 | } | | 3509 | + if (enableTransitionTracing) { | | 3510 | + workInProgress.memoizedState.transitions = getWorkInProgressTransitions(); | | 3511 | + } | 3504 | 3512 | resetHydrationState(); | 3505 | 3513 | break; | 3506 | 3514 | case HostComponent: | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberCommitWork.new.js +43-7Lines changed: 43 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -40,6 +40,7 @@ import { | 40 | 40 | enableSuspenseLayoutEffectSemantics, | 41 | 41 | enableUpdaterTracking, | 42 | 42 | enableCache, | | 43 | + enableTransitionTracing, | 43 | 44 | } from 'shared/ReactFeatureFlags'; | 44 | 45 | import { | 45 | 46 | FunctionComponent, | @@ -132,6 +133,8 @@ import { | 132 | 133 | markCommitTimeOfFallback, | 133 | 134 | enqueuePendingPassiveProfilerEffect, | 134 | 135 | restorePendingUpdaters, | | 136 | + addTransitionStartCallbackToPendingTransition, | | 137 | + addTransitionCompleteCallbackToPendingTransition, | 135 | 138 | } from './ReactFiberWorkLoop.new'; | 136 | 139 | import { | 137 | 140 | NoFlags as NoHookEffect, | @@ -156,6 +159,7 @@ import { | 156 | 159 | onCommitUnmount, | 157 | 160 | } from './ReactFiberDevToolsHook.new'; | 158 | 161 | import {releaseCache, retainCache} from './ReactFiberCacheComponent.new'; | | 162 | +import {clearTransitionsForLanes} from './ReactFiberLane.new'; | 159 | 163 |
| 160 | 164 | let didWarnAboutUndefinedSnapshotBeforeUpdate: Set<mixed> | null = null; | 161 | 165 | if (__DEV__) { | @@ -983,8 +987,10 @@ function commitLayoutEffectOnFiber( | 983 | 987 | case IncompleteClassComponent: | 984 | 988 | case ScopeComponent: | 985 | 989 | case OffscreenComponent: | 986 | | - case LegacyHiddenComponent: | | 990 | + case LegacyHiddenComponent: { | 987 | 991 | break; | | 992 | + } | | 993 | + | 988 | 994 | default: | 989 | 995 | throw new Error( | 990 | 996 | 'This unit of work tag should not have side-effects. This error is ' + | @@ -2137,13 +2143,13 @@ export function commitMutationEffects( | 2137 | 2143 | inProgressRoot = root; | 2138 | 2144 | nextEffect = firstChild; | 2139 | 2145 |
| 2140 | | - commitMutationEffects_begin(root); | | 2146 | + commitMutationEffects_begin(root, committedLanes); | 2141 | 2147 |
| 2142 | 2148 | inProgressLanes = null; | 2143 | 2149 | inProgressRoot = null; | 2144 | 2150 | } | 2145 | 2151 |
| 2146 | | -function commitMutationEffects_begin(root: FiberRoot) { | | 2152 | +function commitMutationEffects_begin(root: FiberRoot, lanes: Lanes) { | 2147 | 2153 | while (nextEffect !== null) { | 2148 | 2154 | const fiber = nextEffect; | 2149 | 2155 |
| @@ -2166,17 +2172,17 @@ function commitMutationEffects_begin(root: FiberRoot) { | 2166 | 2172 | ensureCorrectReturnPointer(child, fiber); | 2167 | 2173 | nextEffect = child; | 2168 | 2174 | } else { | 2169 | | - commitMutationEffects_complete(root); | | 2175 | + commitMutationEffects_complete(root, lanes); | 2170 | 2176 | } | 2171 | 2177 | } | 2172 | 2178 | } | 2173 | 2179 |
| 2174 | | -function commitMutationEffects_complete(root: FiberRoot) { | | 2180 | +function commitMutationEffects_complete(root: FiberRoot, lanes: Lanes) { | 2175 | 2181 | while (nextEffect !== null) { | 2176 | 2182 | const fiber = nextEffect; | 2177 | 2183 | setCurrentDebugFiberInDEV(fiber); | 2178 | 2184 | try { | 2179 | | - commitMutationEffectsOnFiber(fiber, root); | | 2185 | + commitMutationEffectsOnFiber(fiber, root, lanes); | 2180 | 2186 | } catch (error) { | 2181 | 2187 | reportUncaughtErrorInDEV(error); | 2182 | 2188 | captureCommitPhaseError(fiber, fiber.return, error); | @@ -2194,13 +2200,43 @@ function commitMutationEffects_complete(root: FiberRoot) { | 2194 | 2200 | } | 2195 | 2201 | } | 2196 | 2202 |
| 2197 | | -function commitMutationEffectsOnFiber(finishedWork: Fiber, root: FiberRoot) { | | 2203 | +function commitMutationEffectsOnFiber( | | 2204 | + finishedWork: Fiber, | | 2205 | + root: FiberRoot, | | 2206 | + lanes: Lanes, | | 2207 | +) { | 2198 | 2208 | // TODO: The factoring of this phase could probably be improved. Consider | 2199 | 2209 | // switching on the type of work before checking the flags. That's what | 2200 | 2210 | // we do in all the other phases. I think this one is only different | 2201 | 2211 | // because of the shared reconciliation logic below. | 2202 | 2212 | const flags = finishedWork.flags; | 2203 | 2213 |
| | 2214 | + if (enableTransitionTracing) { | | 2215 | + switch (finishedWork.tag) { | | 2216 | + case HostRoot: { | | 2217 | + const state = finishedWork.memoizedState; | | 2218 | + const transitions = state.transitions; | | 2219 | + if (transitions !== null) { | | 2220 | + transitions.forEach(transition => { | | 2221 | + // TODO(luna) Do we want to log TransitionStart in the startTransition callback instead? | | 2222 | + addTransitionStartCallbackToPendingTransition({ | | 2223 | + transitionName: transition.name, | | 2224 | + startTime: transition.startTime, | | 2225 | + }); | | 2226 | + | | 2227 | + addTransitionCompleteCallbackToPendingTransition({ | | 2228 | + transitionName: transition.name, | | 2229 | + startTime: transition.startTime, | | 2230 | + }); | | 2231 | + }); | | 2232 | + | | 2233 | + clearTransitionsForLanes(root, lanes); | | 2234 | + state.transitions = null; | | 2235 | + } | | 2236 | + } | | 2237 | + } | | 2238 | + } | | 2239 | + | 2204 | 2240 | if (flags & ContentReset) { | 2205 | 2241 | commitResetTextContent(finishedWork); | 2206 | 2242 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberCommitWork.old.js +43-7Lines changed: 43 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -40,6 +40,7 @@ import { | 40 | 40 | enableSuspenseLayoutEffectSemantics, | 41 | 41 | enableUpdaterTracking, | 42 | 42 | enableCache, | | 43 | + enableTransitionTracing, | 43 | 44 | } from 'shared/ReactFeatureFlags'; | 44 | 45 | import { | 45 | 46 | FunctionComponent, | @@ -132,6 +133,8 @@ import { | 132 | 133 | markCommitTimeOfFallback, | 133 | 134 | enqueuePendingPassiveProfilerEffect, | 134 | 135 | restorePendingUpdaters, | | 136 | + addTransitionStartCallbackToPendingTransition, | | 137 | + addTransitionCompleteCallbackToPendingTransition, | 135 | 138 | } from './ReactFiberWorkLoop.old'; | 136 | 139 | import { | 137 | 140 | NoFlags as NoHookEffect, | @@ -156,6 +159,7 @@ import { | 156 | 159 | onCommitUnmount, | 157 | 160 | } from './ReactFiberDevToolsHook.old'; | 158 | 161 | import {releaseCache, retainCache} from './ReactFiberCacheComponent.old'; | | 162 | +import {clearTransitionsForLanes} from './ReactFiberLane.old'; | 159 | 163 |
| 160 | 164 | let didWarnAboutUndefinedSnapshotBeforeUpdate: Set<mixed> | null = null; | 161 | 165 | if (__DEV__) { | @@ -983,8 +987,10 @@ function commitLayoutEffectOnFiber( | 983 | 987 | case IncompleteClassComponent: | 984 | 988 | case ScopeComponent: | 985 | 989 | case OffscreenComponent: | 986 | | - case LegacyHiddenComponent: | | 990 | + case LegacyHiddenComponent: { | 987 | 991 | break; | | 992 | + } | | 993 | + | 988 | 994 | default: | 989 | 995 | throw new Error( | 990 | 996 | 'This unit of work tag should not have side-effects. This error is ' + | @@ -2137,13 +2143,13 @@ export function commitMutationEffects( | 2137 | 2143 | inProgressRoot = root; | 2138 | 2144 | nextEffect = firstChild; | 2139 | 2145 |
| 2140 | | - commitMutationEffects_begin(root); | | 2146 | + commitMutationEffects_begin(root, committedLanes); | 2141 | 2147 |
| 2142 | 2148 | inProgressLanes = null; | 2143 | 2149 | inProgressRoot = null; | 2144 | 2150 | } | 2145 | 2151 |
| 2146 | | -function commitMutationEffects_begin(root: FiberRoot) { | | 2152 | +function commitMutationEffects_begin(root: FiberRoot, lanes: Lanes) { | 2147 | 2153 | while (nextEffect !== null) { | 2148 | 2154 | const fiber = nextEffect; | 2149 | 2155 |
| @@ -2166,17 +2172,17 @@ function commitMutationEffects_begin(root: FiberRoot) { | 2166 | 2172 | ensureCorrectReturnPointer(child, fiber); | 2167 | 2173 | nextEffect = child; | 2168 | 2174 | } else { | 2169 | | - commitMutationEffects_complete(root); | | 2175 | + commitMutationEffects_complete(root, lanes); | 2170 | 2176 | } | 2171 | 2177 | } | 2172 | 2178 | } | 2173 | 2179 |
| 2174 | | -function commitMutationEffects_complete(root: FiberRoot) { | | 2180 | +function commitMutationEffects_complete(root: FiberRoot, lanes: Lanes) { | 2175 | 2181 | while (nextEffect !== null) { | 2176 | 2182 | const fiber = nextEffect; | 2177 | 2183 | setCurrentDebugFiberInDEV(fiber); | 2178 | 2184 | try { | 2179 | | - commitMutationEffectsOnFiber(fiber, root); | | 2185 | + commitMutationEffectsOnFiber(fiber, root, lanes); | 2180 | 2186 | } catch (error) { | 2181 | 2187 | reportUncaughtErrorInDEV(error); | 2182 | 2188 | captureCommitPhaseError(fiber, fiber.return, error); | @@ -2194,13 +2200,43 @@ function commitMutationEffects_complete(root: FiberRoot) { | 2194 | 2200 | } | 2195 | 2201 | } | 2196 | 2202 |
| 2197 | | -function commitMutationEffectsOnFiber(finishedWork: Fiber, root: FiberRoot) { | | 2203 | +function commitMutationEffectsOnFiber( | | 2204 | + finishedWork: Fiber, | | 2205 | + root: FiberRoot, | | 2206 | + lanes: Lanes, | | 2207 | +) { | 2198 | 2208 | // TODO: The factoring of this phase could probably be improved. Consider | 2199 | 2209 | // switching on the type of work before checking the flags. That's what | 2200 | 2210 | // we do in all the other phases. I think this one is only different | 2201 | 2211 | // because of the shared reconciliation logic below. | 2202 | 2212 | const flags = finishedWork.flags; | 2203 | 2213 |
| | 2214 | + if (enableTransitionTracing) { | | 2215 | + switch (finishedWork.tag) { | | 2216 | + case HostRoot: { | | 2217 | + const state = finishedWork.memoizedState; | | 2218 | + const transitions = state.transitions; | | 2219 | + if (transitions !== null) { | | 2220 | + transitions.forEach(transition => { | | 2221 | + // TODO(luna) Do we want to log TransitionStart in the startTransition callback instead? | | 2222 | + addTransitionStartCallbackToPendingTransition({ | | 2223 | + transitionName: transition.name, | | 2224 | + startTime: transition.startTime, | | 2225 | + }); | | 2226 | + | | 2227 | + addTransitionCompleteCallbackToPendingTransition({ | | 2228 | + transitionName: transition.name, | | 2229 | + startTime: transition.startTime, | | 2230 | + }); | | 2231 | + }); | | 2232 | + | | 2233 | + clearTransitionsForLanes(root, lanes); | | 2234 | + state.transitions = null; | | 2235 | + } | | 2236 | + } | | 2237 | + } | | 2238 | + } | | 2239 | + | 2204 | 2240 | if (flags & ContentReset) { | 2205 | 2241 | commitResetTextContent(finishedWork); | 2206 | 2242 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberCompleteWork.new.js +10-1Lines changed: 10 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -62,6 +62,7 @@ import { | 62 | 62 | OffscreenComponent, | 63 | 63 | LegacyHiddenComponent, | 64 | 64 | CacheComponent, | | 65 | + TracingMarkerComponent, | 65 | 66 | } from './ReactWorkTags'; | 66 | 67 | import {NoMode, ConcurrentMode, ProfileMode} from './ReactTypeOfMode'; | 67 | 68 | import { | @@ -141,6 +142,7 @@ import { | 141 | 142 | enableCache, | 142 | 143 | enableSuspenseLayoutEffectSemantics, | 143 | 144 | enablePersistentOffscreenHostContainer, | | 145 | + enableTransitionTracing, | 144 | 146 | } from 'shared/ReactFeatureFlags'; | 145 | 147 | import { | 146 | 148 | renderDidSuspend, | @@ -1570,8 +1572,15 @@ function completeWork( | 1570 | 1572 | } | 1571 | 1573 | popCacheProvider(workInProgress, cache); | 1572 | 1574 | bubbleProperties(workInProgress); | 1573 | | - return null; | 1574 | 1575 | } | | 1576 | + return null; | | 1577 | + } | | 1578 | + case TracingMarkerComponent: { | | 1579 | + if (enableTransitionTracing) { | | 1580 | + // Bubble subtree flags before so we can set the flag property | | 1581 | + bubbleProperties(workInProgress); | | 1582 | + } | | 1583 | + return null; | 1575 | 1584 | } | 1576 | 1585 | } | 1577 | 1586 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberCompleteWork.old.js +10-1Lines changed: 10 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -62,6 +62,7 @@ import { | 62 | 62 | OffscreenComponent, | 63 | 63 | LegacyHiddenComponent, | 64 | 64 | CacheComponent, | | 65 | + TracingMarkerComponent, | 65 | 66 | } from './ReactWorkTags'; | 66 | 67 | import {NoMode, ConcurrentMode, ProfileMode} from './ReactTypeOfMode'; | 67 | 68 | import { | @@ -141,6 +142,7 @@ import { | 141 | 142 | enableCache, | 142 | 143 | enableSuspenseLayoutEffectSemantics, | 143 | 144 | enablePersistentOffscreenHostContainer, | | 145 | + enableTransitionTracing, | 144 | 146 | } from 'shared/ReactFeatureFlags'; | 145 | 147 | import { | 146 | 148 | renderDidSuspend, | @@ -1570,8 +1572,15 @@ function completeWork( | 1570 | 1572 | } | 1571 | 1573 | popCacheProvider(workInProgress, cache); | 1572 | 1574 | bubbleProperties(workInProgress); | 1573 | | - return null; | 1574 | 1575 | } | | 1576 | + return null; | | 1577 | + } | | 1578 | + case TracingMarkerComponent: { | | 1579 | + if (enableTransitionTracing) { | | 1580 | + // Bubble subtree flags before so we can set the flag property | | 1581 | + bubbleProperties(workInProgress); | | 1582 | + } | | 1583 | + return null; | 1575 | 1584 | } | 1576 | 1585 | } | 1577 | 1586 |
| |
|