Skip to content

Commit e72a310

Browse files
committed
old fork
1 parent f8bc79f commit e72a310

8 files changed

+318
-15
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ import {
137137
mergeLanes,
138138
getBumpedLaneForHydration,
139139
pickArbitraryLane,
140+
getTransitionsForLanes,
140141
} from './ReactFiberLane.old';
141142
import {
142143
ConcurrentMode,
@@ -1335,6 +1336,13 @@ function updateHostRoot(current, workInProgress, renderLanes) {
13351336
}
13361337
}
13371338

1339+
if (enableTransitionTracing) {
1340+
workInProgress.memoizedState.transitions = getTransitionsForLanes(
1341+
root,
1342+
renderLanes,
1343+
);
1344+
}
1345+
13381346
// Caution: React DevTools currently depends on this property
13391347
// being called "element".
13401348
const nextChildren = nextState.element;
@@ -3493,12 +3501,18 @@ function attemptEarlyBailoutIfNoScheduledUpdate(
34933501
switch (workInProgress.tag) {
34943502
case HostRoot:
34953503
pushHostRootContext(workInProgress);
3504+
const root: FiberRoot = workInProgress.stateNode;
34963505
if (enableCache) {
3497-
const root: FiberRoot = workInProgress.stateNode;
34983506
const cache: Cache = current.memoizedState.cache;
34993507
pushCacheProvider(workInProgress, cache);
35003508
pushRootCachePool(root);
35013509
}
3510+
if (enableTransitionTracing) {
3511+
workInProgress.memoizedState.transitions = getTransitionsForLanes(
3512+
root,
3513+
renderLanes,
3514+
);
3515+
}
35023516
resetHydrationState();
35033517
break;
35043518
case HostComponent:

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

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
enableSuspenseLayoutEffectSemantics,
4141
enableUpdaterTracking,
4242
enableCache,
43+
enableTransitionTracing,
4344
} from 'shared/ReactFeatureFlags';
4445
import {
4546
FunctionComponent,
@@ -132,6 +133,7 @@ import {
132133
markCommitTimeOfFallback,
133134
enqueuePendingPassiveProfilerEffect,
134135
restorePendingUpdaters,
136+
addCallbackToPendingTransitionCallbacks,
135137
} from './ReactFiberWorkLoop.old';
136138
import {
137139
NoFlags as NoHookEffect,
@@ -156,6 +158,11 @@ import {
156158
onCommitUnmount,
157159
} from './ReactFiberDevToolsHook.old';
158160
import {releaseCache, retainCache} from './ReactFiberCacheComponent.old';
161+
import {
162+
TransitionStart,
163+
TransitionComplete,
164+
} from './ReactFiberTracingMarkerComponent.old';
165+
import {clearTransitionsForLanes} from './ReactFiberLane.old';
159166

160167
let didWarnAboutUndefinedSnapshotBeforeUpdate: Set<mixed> | null = null;
161168
if (__DEV__) {
@@ -983,8 +990,10 @@ function commitLayoutEffectOnFiber(
983990
case IncompleteClassComponent:
984991
case ScopeComponent:
985992
case OffscreenComponent:
986-
case LegacyHiddenComponent:
993+
case LegacyHiddenComponent: {
987994
break;
995+
}
996+
988997
default:
989998
throw new Error(
990999
'This unit of work tag should not have side-effects. This error is ' +
@@ -2137,13 +2146,13 @@ export function commitMutationEffects(
21372146
inProgressRoot = root;
21382147
nextEffect = firstChild;
21392148

2140-
commitMutationEffects_begin(root);
2149+
commitMutationEffects_begin(root, committedLanes);
21412150

21422151
inProgressLanes = null;
21432152
inProgressRoot = null;
21442153
}
21452154

2146-
function commitMutationEffects_begin(root: FiberRoot) {
2155+
function commitMutationEffects_begin(root: FiberRoot, lanes: Lanes) {
21472156
while (nextEffect !== null) {
21482157
const fiber = nextEffect;
21492158

@@ -2166,17 +2175,17 @@ function commitMutationEffects_begin(root: FiberRoot) {
21662175
ensureCorrectReturnPointer(child, fiber);
21672176
nextEffect = child;
21682177
} else {
2169-
commitMutationEffects_complete(root);
2178+
commitMutationEffects_complete(root, lanes);
21702179
}
21712180
}
21722181
}
21732182

2174-
function commitMutationEffects_complete(root: FiberRoot) {
2183+
function commitMutationEffects_complete(root: FiberRoot, lanes: Lanes) {
21752184
while (nextEffect !== null) {
21762185
const fiber = nextEffect;
21772186
setCurrentDebugFiberInDEV(fiber);
21782187
try {
2179-
commitMutationEffectsOnFiber(fiber, root);
2188+
commitMutationEffectsOnFiber(fiber, root, lanes);
21802189
} catch (error) {
21812190
reportUncaughtErrorInDEV(error);
21822191
captureCommitPhaseError(fiber, fiber.return, error);
@@ -2194,13 +2203,45 @@ function commitMutationEffects_complete(root: FiberRoot) {
21942203
}
21952204
}
21962205

2197-
function commitMutationEffectsOnFiber(finishedWork: Fiber, root: FiberRoot) {
2206+
function commitMutationEffectsOnFiber(
2207+
finishedWork: Fiber,
2208+
root: FiberRoot,
2209+
lanes: Lanes,
2210+
) {
21982211
// TODO: The factoring of this phase could probably be improved. Consider
21992212
// switching on the type of work before checking the flags. That's what
22002213
// we do in all the other phases. I think this one is only different
22012214
// because of the shared reconciliation logic below.
22022215
const flags = finishedWork.flags;
22032216

2217+
if (enableTransitionTracing) {
2218+
switch (finishedWork.tag) {
2219+
case HostRoot: {
2220+
const state = finishedWork.memoizedState;
2221+
const transitions = state.transitions;
2222+
if (transitions != null) {
2223+
transitions.forEach(transition => {
2224+
// TODO(luna) Do we want to log TransitionStart in the startTransition callback instead?
2225+
addCallbackToPendingTransitionCallbacks({
2226+
type: TransitionStart,
2227+
transitionName: transition.name,
2228+
startTime: transition.startTime,
2229+
});
2230+
2231+
addCallbackToPendingTransitionCallbacks({
2232+
type: TransitionComplete,
2233+
transitionName: transition.name,
2234+
startTime: transition.startTime,
2235+
});
2236+
});
2237+
2238+
clearTransitionsForLanes(root, lanes);
2239+
state.transitions.clear();
2240+
}
2241+
}
2242+
}
2243+
}
2244+
22042245
if (flags & ContentReset) {
22052246
commitResetTextContent(finishedWork);
22062247
}

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import {
6262
OffscreenComponent,
6363
LegacyHiddenComponent,
6464
CacheComponent,
65+
TracingMarkerComponent,
6566
} from './ReactWorkTags';
6667
import {NoMode, ConcurrentMode, ProfileMode} from './ReactTypeOfMode';
6768
import {
@@ -141,6 +142,7 @@ import {
141142
enableCache,
142143
enableSuspenseLayoutEffectSemantics,
143144
enablePersistentOffscreenHostContainer,
145+
enableTransitionTracing,
144146
} from 'shared/ReactFeatureFlags';
145147
import {
146148
renderDidSuspend,
@@ -1571,8 +1573,15 @@ function completeWork(
15711573
}
15721574
popCacheProvider(workInProgress, cache);
15731575
bubbleProperties(workInProgress);
1574-
return null;
15751576
}
1577+
return null;
1578+
}
1579+
case TracingMarkerComponent: {
1580+
if (enableTransitionTracing) {
1581+
// Bubble subtree flags before so we can set the flag property
1582+
bubbleProperties(workInProgress);
1583+
}
1584+
return null;
15761585
}
15771586
}
15781587

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
MutableSourceGetSnapshotFn,
1313
MutableSourceSubscribeFn,
1414
ReactContext,
15+
StartTransitionOptions,
1516
} from 'shared/ReactTypes';
1617
import type {Fiber, Dispatcher, HookType} from './ReactInternalTypes';
1718
import type {Lanes, Lane} from './ReactFiberLane.old';
@@ -31,6 +32,7 @@ import {
3132
enableLazyContextPropagation,
3233
enableSuspenseLayoutEffectSemantics,
3334
enableUseMutableSource,
35+
enableTransitionTracing,
3436
} from 'shared/ReactFeatureFlags';
3537

3638
import {
@@ -111,6 +113,7 @@ import {
111113
import {pushInterleavedQueue} from './ReactFiberInterleavedUpdates.old';
112114
import {warnOnSubscriptionInsideStartTransition} from 'shared/ReactFeatureFlags';
113115
import {getTreeId} from './ReactFiberTreeContext.old';
116+
import {now} from './Scheduler';
114117

115118
const {ReactCurrentDispatcher, ReactCurrentBatchConfig} = ReactSharedInternals;
116119

@@ -1966,7 +1969,7 @@ function rerenderDeferredValue<T>(value: T): T {
19661969
return prevValue;
19671970
}
19681971

1969-
function startTransition(setPending, callback) {
1972+
function startTransition(setPending, callback, options) {
19701973
const previousPriority = getCurrentUpdatePriority();
19711974
setCurrentUpdatePriority(
19721975
higherEventPriority(previousPriority, ContinuousEventPriority),
@@ -1978,6 +1981,13 @@ function startTransition(setPending, callback) {
19781981
ReactCurrentBatchConfig.transition = {};
19791982
const currentTransition = ReactCurrentBatchConfig.transition;
19801983

1984+
if (enableTransitionTracing) {
1985+
if (options !== undefined && options.name !== undefined) {
1986+
ReactCurrentBatchConfig.transition.name = options.name;
1987+
ReactCurrentBatchConfig.transition.startTime = now();
1988+
}
1989+
}
1990+
19811991
if (__DEV__) {
19821992
ReactCurrentBatchConfig.transition._updatedFibers = new Set();
19831993
}
@@ -1989,6 +1999,7 @@ function startTransition(setPending, callback) {
19891999
setCurrentUpdatePriority(previousPriority);
19902000

19912001
ReactCurrentBatchConfig.transition = prevTransition;
2002+
19922003
if (__DEV__) {
19932004
if (
19942005
prevTransition === null &&
@@ -2009,7 +2020,10 @@ function startTransition(setPending, callback) {
20092020
}
20102021
}
20112022

2012-
function mountTransition(): [boolean, (() => void) => void] {
2023+
function mountTransition(): [
2024+
boolean,
2025+
(callback: () => void, options?: StartTransitionOptions) => void,
2026+
] {
20132027
const [isPending, setPending] = mountState(false);
20142028
// The `start` method never changes.
20152029
const start = startTransition.bind(null, setPending);
@@ -2018,14 +2032,20 @@ function mountTransition(): [boolean, (() => void) => void] {
20182032
return [isPending, start];
20192033
}
20202034

2021-
function updateTransition(): [boolean, (() => void) => void] {
2035+
function updateTransition(): [
2036+
boolean,
2037+
(callback: () => void, options?: StartTransitionOptions) => void,
2038+
] {
20222039
const [isPending] = updateState(false);
20232040
const hook = updateWorkInProgressHook();
20242041
const start = hook.memoizedState;
20252042
return [isPending, start];
20262043
}
20272044

2028-
function rerenderTransition(): [boolean, (() => void) => void] {
2045+
function rerenderTransition(): [
2046+
boolean,
2047+
(callback: () => void, options?: StartTransitionOptions) => void,
2048+
] {
20292049
const [isPending] = rerenderState(false);
20302050
const hook = updateWorkInProgressHook();
20312051
const start = hook.memoizedState;

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

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
*/
99

1010
import type {FiberRoot} from './ReactInternalTypes';
11+
import type {
12+
Transition,
13+
Transitions,
14+
} from './ReactFiberTracingMarkerComponent.old';
1115

1216
// TODO: Ideally these types would be opaque but that doesn't work well with
1317
// our reconciler fork infra, since these leak into non-reconciler packages.
@@ -20,6 +24,7 @@ import {
2024
enableSchedulingProfiler,
2125
enableUpdaterTracking,
2226
allowConcurrentByDefault,
27+
enableTransitionTracing,
2328
} from 'shared/ReactFeatureFlags';
2429
import {isDevToolsPresent} from './ReactFiberDevToolsHook.old';
2530
import {ConcurrentUpdatesByDefaultMode, NoMode} from './ReactTypeOfMode';
@@ -796,3 +801,82 @@ export function movePendingFibersToMemoized(root: FiberRoot, lanes: Lanes) {
796801
lanes &= ~lane;
797802
}
798803
}
804+
805+
export function addTransitionToLanesMap(
806+
root: FiberRoot,
807+
transition: Transition,
808+
lane: Lane,
809+
) {
810+
if (enableTransitionTracing) {
811+
const transitionLanesMap = root.transitionLanes;
812+
const index = laneToIndex(lane);
813+
const transitions = transitionLanesMap[index];
814+
if (transitions !== null) {
815+
transitions.add(transition);
816+
} else {
817+
if (__DEV__) {
818+
console.error(
819+
'React Bug: transition lanes accessed out of bounds index: %s',
820+
index.toString(),
821+
);
822+
}
823+
}
824+
}
825+
}
826+
827+
export function getTransitionsForLanes(
828+
root: FiberRoot,
829+
lanes: Lane | Lanes,
830+
): Transitions | null {
831+
if (!enableTransitionTracing) {
832+
return null;
833+
}
834+
835+
const transitionsForLanes = new Set();
836+
while (lanes > 0) {
837+
const index = laneToIndex(lanes);
838+
const lane = 1 << index;
839+
const transitions = root.transitionLanes[index];
840+
if (transitions !== null) {
841+
transitions.forEach(transition => {
842+
transitionsForLanes.add(transition);
843+
});
844+
} else {
845+
if (__DEV__) {
846+
console.error(
847+
'React Bug: transition lanes accessed out of bounds index: %s',
848+
index.toString(),
849+
);
850+
}
851+
}
852+
853+
lanes &= ~lane;
854+
}
855+
856+
return transitionsForLanes;
857+
}
858+
859+
export function clearTransitionsForLanes(root: FiberRoot, lanes: Lane | Lanes) {
860+
if (!enableTransitionTracing) {
861+
return;
862+
}
863+
864+
while (lanes > 0) {
865+
const index = laneToIndex(lanes);
866+
const lane = 1 << index;
867+
868+
const transitions = root.transitionLanes[index];
869+
if (transitions !== null) {
870+
transitions.clear();
871+
} else {
872+
if (__DEV__) {
873+
console.error(
874+
'React Bug: transition lanes accessed out of bounds index: %s',
875+
index.toString(),
876+
);
877+
}
878+
}
879+
880+
lanes &= ~lane;
881+
}
882+
}

0 commit comments

Comments
 (0)