Skip to content

Commit 372d80d

Browse files
committed
add pendingPassiveTransitions
1 parent 8dcedba commit 372d80d

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import type {OffscreenState} from './ReactFiberOffscreenComponent';
2626
import type {HookFlags} from './ReactHookEffectTags';
2727
import type {Cache} from './ReactFiberCacheComponent.new';
2828
import type {RootState} from './ReactFiberRoot.new';
29+
import type {Transition} from './ReactFiberTracingMarkerComponent.new';
2930

3031
import {
3132
enableCreateEventHandleAPI,
@@ -2614,15 +2615,22 @@ export function commitPassiveMountEffects(
26142615
root: FiberRoot,
26152616
finishedWork: Fiber,
26162617
committedLanes: Lanes,
2618+
committedTransitions: Array<Transition> | null,
26172619
): void {
26182620
nextEffect = finishedWork;
2619-
commitPassiveMountEffects_begin(finishedWork, root, committedLanes);
2621+
commitPassiveMountEffects_begin(
2622+
finishedWork,
2623+
root,
2624+
committedLanes,
2625+
committedTransitions,
2626+
);
26202627
}
26212628

26222629
function commitPassiveMountEffects_begin(
26232630
subtreeRoot: Fiber,
26242631
root: FiberRoot,
26252632
committedLanes: Lanes,
2633+
committedTransitions: Array<Transition> | null,
26262634
) {
26272635
while (nextEffect !== null) {
26282636
const fiber = nextEffect;
@@ -2631,7 +2639,12 @@ function commitPassiveMountEffects_begin(
26312639
ensureCorrectReturnPointer(firstChild, fiber);
26322640
nextEffect = firstChild;
26332641
} else {
2634-
commitPassiveMountEffects_complete(subtreeRoot, root, committedLanes);
2642+
commitPassiveMountEffects_complete(
2643+
subtreeRoot,
2644+
root,
2645+
committedLanes,
2646+
committedTransitions,
2647+
);
26352648
}
26362649
}
26372650
}
@@ -2640,14 +2653,20 @@ function commitPassiveMountEffects_complete(
26402653
subtreeRoot: Fiber,
26412654
root: FiberRoot,
26422655
committedLanes: Lanes,
2656+
committedTransitions: Array<Transition> | null,
26432657
) {
26442658
while (nextEffect !== null) {
26452659
const fiber = nextEffect;
26462660

26472661
if ((fiber.flags & Passive) !== NoFlags) {
26482662
setCurrentDebugFiberInDEV(fiber);
26492663
try {
2650-
commitPassiveMountOnFiber(root, fiber, committedLanes);
2664+
commitPassiveMountOnFiber(
2665+
root,
2666+
fiber,
2667+
committedLanes,
2668+
committedTransitions,
2669+
);
26512670
} catch (error) {
26522671
reportUncaughtErrorInDEV(error);
26532672
captureCommitPhaseError(fiber, fiber.return, error);
@@ -2675,6 +2694,7 @@ function commitPassiveMountOnFiber(
26752694
finishedRoot: FiberRoot,
26762695
finishedWork: Fiber,
26772696
committedLanes: Lanes,
2697+
committedTransitions: Array<Transition> | null,
26782698
): void {
26792699
switch (finishedWork.tag) {
26802700
case FunctionComponent:

packages/react-reconciler/src/ReactFiberWorkLoop.new.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ let rootWithPendingPassiveEffects: FiberRoot | null = null;
391391
let pendingPassiveEffectsLanes: Lanes = NoLanes;
392392
let pendingPassiveProfilerEffects: Array<Fiber> = [];
393393
let pendingPassiveEffectsRemainingLanes: Lanes = NoLanes;
394+
let pendingPassiveTransitions: Array<Transition> | null = null;
394395

395396
// Use these to prevent an infinite loop of nested updates
396397
const NESTED_UPDATE_LIMIT = 50;
@@ -2087,6 +2088,9 @@ function commitRootImpl(
20872088
if (!rootDoesHavePassiveEffects) {
20882089
rootDoesHavePassiveEffects = true;
20892090
pendingPassiveEffectsRemainingLanes = remainingLanes;
2091+
// workInProgressTransitions might be overwritten, so we want
2092+
// to store it in pendingPassiveTransitions until they get processed
2093+
pendingPassiveTransitions = workInProgressTransitions;
20902094
scheduleCallback(NormalSchedulerPriority, () => {
20912095
flushPassiveEffects();
20922096
// This render triggered passive effects: release the root cache pool
@@ -2407,6 +2411,10 @@ function flushPassiveEffectsImpl() {
24072411
return false;
24082412
}
24092413

2414+
// Cache and clear the transitions flag
2415+
const transitions = pendingPassiveTransitions;
2416+
pendingPassiveTransitions = null;
2417+
24102418
const root = rootWithPendingPassiveEffects;
24112419
const lanes = pendingPassiveEffectsLanes;
24122420
rootWithPendingPassiveEffects = null;
@@ -2436,7 +2444,7 @@ function flushPassiveEffectsImpl() {
24362444
executionContext |= CommitContext;
24372445

24382446
commitPassiveUnmountEffects(root.current);
2439-
commitPassiveMountEffects(root, root.current, lanes);
2447+
commitPassiveMountEffects(root, root.current, lanes, transitions);
24402448

24412449
// TODO: Move to commitPassiveMountEffects
24422450
if (enableProfilerTimer && enableProfilerCommitHooks) {

0 commit comments

Comments
 (0)