Skip to content

Commit c81312e

Browse files
authored
[Fiber] Refactor Commit Phase into Separate Functions for Before Mutation/Mutation/Layout (facebook#31930)
This is doing some general clean up to be able to split the commit root three phases into three separate async steps.
1 parent d8b903f commit c81312e

File tree

6 files changed

+174
-154
lines changed

6 files changed

+174
-154
lines changed

packages/react-reconciler/src/ReactFiberLane.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,11 @@ function getHighestPriorityLanes(lanes: Lanes | Lane): Lanes {
221221
}
222222
}
223223

224-
export function getNextLanes(root: FiberRoot, wipLanes: Lanes): Lanes {
224+
export function getNextLanes(
225+
root: FiberRoot,
226+
wipLanes: Lanes,
227+
rootHasPendingCommit: boolean,
228+
): Lanes {
225229
// Early bailout if there's no pending work left.
226230
const pendingLanes = root.pendingLanes;
227231
if (pendingLanes === NoLanes) {
@@ -246,16 +250,6 @@ export function getNextLanes(root: FiberRoot, wipLanes: Lanes): Lanes {
246250
// a brief amount of time (i.e. below the "Just Noticeable Difference"
247251
// threshold).
248252
//
249-
// TODO: finishedLanes is also set when a Suspensey resource, like CSS or
250-
// images, suspends during the commit phase. (We could detect that here by
251-
// checking for root.cancelPendingCommit.) These are also expected to resolve
252-
// quickly, because of preloading, but theoretically they could block forever
253-
// like in a normal "suspend indefinitely" scenario. In the future, we should
254-
// consider only blocking for up to some time limit before discarding the
255-
// commit in favor of prerendering. If we do discard a pending commit, then
256-
// the commit phase callback should act as a ping to try the original
257-
// render again.
258-
const rootHasPendingCommit = root.finishedLanes !== NoLanes;
259253

260254
// Do not work on any idle work until all the non-idle work has finished,
261255
// even if the work is suspended.

packages/react-reconciler/src/ReactFiberRoot.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ function FiberRootNode(
6161
this.pendingChildren = null;
6262
this.current = null;
6363
this.pingCache = null;
64-
this.finishedWork = null;
6564
this.timeoutHandle = noTimeout;
6665
this.cancelPendingCommit = null;
6766
this.context = null;
@@ -76,7 +75,6 @@ function FiberRootNode(
7675
this.pingedLanes = NoLanes;
7776
this.warmLanes = NoLanes;
7877
this.expiredLanes = NoLanes;
79-
this.finishedLanes = NoLanes;
8078
this.errorRecoveryDisabledLanes = NoLanes;
8179
this.shellSuspendCounter = 0;
8280

packages/react-reconciler/src/ReactFiberRootScheduler.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ import {
6969
scheduleMicrotask,
7070
shouldAttemptEagerTransition,
7171
trackSchedulerEvent,
72+
noTimeout,
7273
} from './ReactFiberConfig';
7374

7475
import ReactSharedInternals from 'shared/ReactSharedInternals';
@@ -207,11 +208,15 @@ function flushSyncWorkAcrossRoots_impl(
207208
const workInProgressRoot = getWorkInProgressRoot();
208209
const workInProgressRootRenderLanes =
209210
getWorkInProgressRootRenderLanes();
211+
const rootHasPendingCommit =
212+
root.cancelPendingCommit !== null ||
213+
root.timeoutHandle !== noTimeout;
210214
const nextLanes = getNextLanes(
211215
root,
212216
root === workInProgressRoot
213217
? workInProgressRootRenderLanes
214218
: NoLanes,
219+
rootHasPendingCommit,
215220
);
216221
if (
217222
includesSyncLane(nextLanes) &&
@@ -335,6 +340,8 @@ function scheduleTaskForRootDuringMicrotask(
335340
const pendingPassiveEffectsLanes = getPendingPassiveEffectsLanes();
336341
const workInProgressRoot = getWorkInProgressRoot();
337342
const workInProgressRootRenderLanes = getWorkInProgressRootRenderLanes();
343+
const rootHasPendingCommit =
344+
root.cancelPendingCommit !== null || root.timeoutHandle !== noTimeout;
338345
const nextLanes =
339346
enableYieldingBeforePassive && root === rootWithPendingPassiveEffects
340347
? // This will schedule the callback at the priority of the lane but we used to
@@ -345,6 +352,7 @@ function scheduleTaskForRootDuringMicrotask(
345352
: getNextLanes(
346353
root,
347354
root === workInProgressRoot ? workInProgressRootRenderLanes : NoLanes,
355+
rootHasPendingCommit,
348356
);
349357

350358
const existingCallbackNode = root.callbackNode;
@@ -488,9 +496,12 @@ function performWorkOnRootViaSchedulerTask(
488496
// it's available).
489497
const workInProgressRoot = getWorkInProgressRoot();
490498
const workInProgressRootRenderLanes = getWorkInProgressRootRenderLanes();
499+
const rootHasPendingCommit =
500+
root.cancelPendingCommit !== null || root.timeoutHandle !== noTimeout;
491501
const lanes = getNextLanes(
492502
root,
493503
root === workInProgressRoot ? workInProgressRootRenderLanes : NoLanes,
504+
rootHasPendingCommit,
494505
);
495506
if (lanes === NoLanes) {
496507
// No more work on this root.

0 commit comments

Comments
 (0)