Skip to content

Commit 4b8e164

Browse files
authored
Fork performWork instead of using boolean flag (#15169)
I inline it into performAsyncWork instead. Code that was only relevant to the async callback had leaked into the performWork call which is an indication that this was a bad abstraction and therefore the wrong place to DRY. By inlining I also discovered that minExpirationTime is actually irrelevant in the yieldy case so we can clean that up.
1 parent 56035da commit 4b8e164

File tree

1 file changed

+44
-27
lines changed

1 file changed

+44
-27
lines changed

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

+44-27
Original file line numberDiff line numberDiff line change
@@ -2234,23 +2234,18 @@ function performAsyncWork(didTimeout) {
22342234
} while (root !== firstScheduledRoot);
22352235
}
22362236
}
2237-
let isYieldy = true;
2238-
if (disableYielding) {
2239-
isYieldy = false;
2240-
}
2241-
performWork(NoWork, isYieldy);
2242-
}
2243-
2244-
function performSyncWork() {
2245-
performWork(Sync, false);
2246-
}
22472237

2248-
function performWork(minExpirationTime: ExpirationTime, isYieldy: boolean) {
22492238
// Keep working on roots until there's no more work, or until there's a higher
22502239
// priority event.
22512240
findHighestPriorityRoot();
22522241

2253-
if (isYieldy) {
2242+
if (disableYielding) {
2243+
// Just do it all
2244+
while (nextFlushedRoot !== null && nextFlushedExpirationTime !== NoWork) {
2245+
performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, false);
2246+
findHighestPriorityRoot();
2247+
}
2248+
} else {
22542249
recomputeCurrentRendererTime();
22552250
currentSchedulerTime = currentRendererTime;
22562251

@@ -2263,7 +2258,6 @@ function performWork(minExpirationTime: ExpirationTime, isYieldy: boolean) {
22632258
while (
22642259
nextFlushedRoot !== null &&
22652260
nextFlushedExpirationTime !== NoWork &&
2266-
minExpirationTime <= nextFlushedExpirationTime &&
22672261
!(shouldYield() && currentRendererTime > nextFlushedExpirationTime)
22682262
) {
22692263
performWorkOnRoot(
@@ -2275,25 +2269,48 @@ function performWork(minExpirationTime: ExpirationTime, isYieldy: boolean) {
22752269
recomputeCurrentRendererTime();
22762270
currentSchedulerTime = currentRendererTime;
22772271
}
2278-
} else {
2279-
while (
2280-
nextFlushedRoot !== null &&
2281-
nextFlushedExpirationTime !== NoWork &&
2282-
minExpirationTime <= nextFlushedExpirationTime
2283-
) {
2284-
performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, false);
2285-
findHighestPriorityRoot();
2286-
}
22872272
}
22882273

22892274
// We're done flushing work. Either we ran out of time in this callback,
22902275
// or there's no more work left with sufficient priority.
22912276

22922277
// If we're inside a callback, set this to false since we just completed it.
2293-
if (isYieldy) {
2294-
callbackExpirationTime = NoWork;
2295-
callbackID = null;
2278+
callbackExpirationTime = NoWork;
2279+
callbackID = null;
2280+
2281+
// If there's work left over, schedule a new callback.
2282+
if (nextFlushedExpirationTime !== NoWork) {
2283+
scheduleCallbackWithExpirationTime(
2284+
((nextFlushedRoot: any): FiberRoot),
2285+
nextFlushedExpirationTime,
2286+
);
2287+
}
2288+
2289+
// Clean-up.
2290+
finishRendering();
2291+
}
2292+
2293+
function performSyncWork() {
2294+
performWork(Sync);
2295+
}
2296+
2297+
function performWork(minExpirationTime: ExpirationTime) {
2298+
// Keep working on roots until there's no more work, or until there's a higher
2299+
// priority event.
2300+
findHighestPriorityRoot();
2301+
2302+
while (
2303+
nextFlushedRoot !== null &&
2304+
nextFlushedExpirationTime !== NoWork &&
2305+
minExpirationTime <= nextFlushedExpirationTime
2306+
) {
2307+
performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, false);
2308+
findHighestPriorityRoot();
22962309
}
2310+
2311+
// We're done flushing work. Either we ran out of time in this callback,
2312+
// or there's no more work left with sufficient priority.
2313+
22972314
// If there's work left over, schedule a new callback.
22982315
if (nextFlushedExpirationTime !== NoWork) {
22992316
scheduleCallbackWithExpirationTime(
@@ -2547,7 +2564,7 @@ function interactiveUpdates<A, B, C, R>(
25472564
lowestPriorityPendingInteractiveExpirationTime !== NoWork
25482565
) {
25492566
// Synchronously flush pending interactive updates.
2550-
performWork(lowestPriorityPendingInteractiveExpirationTime, false);
2567+
performWork(lowestPriorityPendingInteractiveExpirationTime);
25512568
lowestPriorityPendingInteractiveExpirationTime = NoWork;
25522569
}
25532570
const previousIsBatchingInteractiveUpdates = isBatchingInteractiveUpdates;
@@ -2571,7 +2588,7 @@ function flushInteractiveUpdates() {
25712588
lowestPriorityPendingInteractiveExpirationTime !== NoWork
25722589
) {
25732590
// Synchronously flush pending interactive updates.
2574-
performWork(lowestPriorityPendingInteractiveExpirationTime, false);
2591+
performWork(lowestPriorityPendingInteractiveExpirationTime);
25752592
lowestPriorityPendingInteractiveExpirationTime = NoWork;
25762593
}
25772594
}

0 commit comments

Comments
 (0)