Skip to content

Commit a04cd32

Browse files
committed
Simplify list of pending work
Some of this was added with "soft expiration" in mind, but now with our revised model for how soft expiration will work, this isn't necessary. It would be nice to remove more of this, but I think the list itself is inherent because we need a way to track the start times, for <Timeout ms={ms} />.
1 parent 12a0024 commit a04cd32

File tree

2 files changed

+10
-63
lines changed

2 files changed

+10
-63
lines changed

packages/react-reconciler/src/ReactFiberPendingWork.js

Lines changed: 9 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export type PendingWork = {
2727
expirationTime: ExpirationTime,
2828
isSuspended: boolean,
2929
shouldTryResuming: boolean,
30-
isRenderPhaseWork: boolean,
3130
next: PendingWork | null,
3231
};
3332

@@ -50,7 +49,8 @@ export function addPendingWork(
5049
let insertBefore = root.firstPendingWork;
5150
while (insertBefore !== null) {
5251
if (insertBefore.expirationTime >= expirationTime) {
53-
// Retry anything with an equal or lower expiration time
52+
// Retry anything with an equal or lower expiration time, since it may
53+
// be unblocked by the new work.
5454
insertBefore.shouldTryResuming = true;
5555
}
5656
if (insertBefore.expirationTime === expirationTime) {
@@ -74,45 +74,11 @@ export function addPendingWork(
7474
expirationTime,
7575
isSuspended: false,
7676
shouldTryResuming: false,
77-
isRenderPhaseWork: false,
7877
next: null,
7978
};
8079
insertPendingWorkAtPosition(root, work, insertAfter, insertBefore);
8180
}
8281
}
83-
export function addRenderPhasePendingWork(
84-
root: FiberRoot,
85-
startTime: ExpirationTime,
86-
expirationTime: ExpirationTime,
87-
): void {
88-
// Render-phase updates are treated differently because, while they
89-
// could potentially unblock earlier pending work, we assume that they won't.
90-
// They are also coalesced differently (see findNextExpirationTimeToWorkOn).
91-
let insertAfter = null;
92-
let insertBefore = root.firstPendingWork;
93-
while (insertBefore !== null) {
94-
if (insertBefore.expirationTime === expirationTime) {
95-
// Found a matching bucket
96-
return;
97-
}
98-
if (insertBefore.expirationTime > expirationTime) {
99-
// Found the insertion position
100-
break;
101-
}
102-
insertAfter = insertBefore;
103-
insertBefore = insertBefore.next;
104-
}
105-
// No matching level found. Create a new one.
106-
const work: PendingWork = {
107-
startTime,
108-
expirationTime,
109-
isSuspended: false,
110-
shouldTryResuming: false,
111-
isRenderPhaseWork: true,
112-
next: null,
113-
};
114-
insertPendingWorkAtPosition(root, work, insertAfter, insertBefore);
115-
}
11682

11783
export function flushPendingWork(
11884
root: FiberRoot,
@@ -135,14 +101,14 @@ export function flushPendingWork(
135101
if (firstUnflushedWork === null) {
136102
if (remainingExpirationTime !== NoWork) {
137103
// There was an update during the render phase that wasn't flushed.
138-
addRenderPhasePendingWork(root, currentTime, remainingExpirationTime);
104+
addPendingWork(root, currentTime, remainingExpirationTime);
139105
}
140106
} else if (
141107
remainingExpirationTime !== NoWork &&
142108
firstUnflushedWork.expirationTime > remainingExpirationTime
143109
) {
144110
// There was an update during the render phase that wasn't flushed.
145-
addRenderPhasePendingWork(root, currentTime, remainingExpirationTime);
111+
addPendingWork(root, currentTime, remainingExpirationTime);
146112
}
147113
}
148114

@@ -168,7 +134,8 @@ export function resumePendingWork(
168134
root: FiberRoot,
169135
expirationTime: ExpirationTime,
170136
): void {
171-
// Called when a promise resolves
137+
// Called when a promise resolves. This "pings" React to retry the previously
138+
// suspended render.
172139
let work = root.firstPendingWork;
173140
while (work !== null) {
174141
if (work.expirationTime === expirationTime) {
@@ -184,19 +151,12 @@ export function resumePendingWork(
184151
export function findNextExpirationTimeToWorkOn(
185152
root: FiberRoot,
186153
): ExpirationTime {
187-
// If there's a non-suspended interactive expiration time, return the first
188-
// one. If everything is suspended, return the last retry time that's either
189-
// a) a render phase update
190-
// b) later or equal to the last suspended time
154+
// Return the earliest time that either isn't suspended or has been pinged.
191155
let lastSuspendedTime = NoWork;
192-
let lastRenderPhaseTime = NoWork;
193156
let lastRetryTime = NoWork;
194157
let work = root.firstPendingWork;
195158
while (work !== null) {
196-
if (
197-
!work.isSuspended &&
198-
(!work.isRenderPhaseWork || lastSuspendedTime === NoWork)
199-
) {
159+
if (!work.isSuspended) {
200160
return work.expirationTime;
201161
}
202162
if (
@@ -209,13 +169,6 @@ export function findNextExpirationTimeToWorkOn(
209169
if (lastRetryTime === NoWork || lastRetryTime < work.expirationTime) {
210170
lastRetryTime = work.expirationTime;
211171
}
212-
if (
213-
work.isRenderPhaseWork &&
214-
(lastRenderPhaseTime === NoWork ||
215-
lastRenderPhaseTime < work.expirationTime)
216-
) {
217-
lastRenderPhaseTime = work.expirationTime;
218-
}
219172
}
220173
work = work.next;
221174
}
@@ -228,7 +181,7 @@ export function findNextExpirationTimeToWorkOn(
228181
if (lastRetryTime >= lastSuspendedTime) {
229182
return lastRetryTime;
230183
}
231-
return lastRenderPhaseTime;
184+
return NoWork;
232185
}
233186

234187
export function findStartTime(root: FiberRoot, expirationTime: ExpirationTime) {

packages/react-reconciler/src/ReactFiberScheduler.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ import ReactFiberInstrumentation from './ReactFiberInstrumentation';
5959
import ReactDebugCurrentFiber from './ReactDebugCurrentFiber';
6060
import {
6161
addPendingWork,
62-
addRenderPhasePendingWork,
6362
flushPendingWork,
6463
findStartTime,
6564
findNextExpirationTimeToWorkOn,
@@ -1353,12 +1352,7 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
13531352
interruptedBy = fiber;
13541353
resetStack();
13551354
}
1356-
if (!isWorking || isCommitting) {
1357-
addPendingWork(root, startTime, expirationTime);
1358-
} else {
1359-
// We're in the render phase.
1360-
addRenderPhasePendingWork(root, startTime, expirationTime);
1361-
}
1355+
addPendingWork(root, startTime, expirationTime);
13621356
if (
13631357
// If we're in the render phase, we don't need to schedule this root
13641358
// for an update, because we'll do it before we exit...

0 commit comments

Comments
 (0)