Skip to content

Commit 6b4c031

Browse files
committed
Check thenable instead of thenableState
Now that hook state is preserved while the work loop is suspended, we don't need to track the thenable state in the work loop. We can track it alongside the rest of the hook state. Before deleting the thenable state variable from the work loop, I need to remove the other places where it's referenced. One of them is `isThenableStateResolved`. This grabs the last thenable from the array and checks if it has resolved. This was a pointless indirection anyway. The thenable is already stored as `workInProgressThrownValue`. So we can check that directly.
1 parent 33e3d28 commit 6b4c031

File tree

4 files changed

+18
-32
lines changed

4 files changed

+18
-32
lines changed

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

+3-7
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,9 @@ export function getThenableStateAfterSuspending(): ThenableState | null {
5454
return state;
5555
}
5656

57-
export function isThenableStateResolved(thenables: ThenableState): boolean {
58-
const lastThenable = thenables[thenables.length - 1];
59-
if (lastThenable !== undefined) {
60-
const status = lastThenable.status;
61-
return status === 'fulfilled' || status === 'rejected';
62-
}
63-
return true;
57+
export function isThenableResolved(thenable: Thenable<mixed>): boolean {
58+
const status = thenable.status;
59+
return status === 'fulfilled' || status === 'rejected';
6460
}
6561

6662
function noop(): void {}

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

+3-7
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,9 @@ export function getThenableStateAfterSuspending(): ThenableState | null {
5454
return state;
5555
}
5656

57-
export function isThenableStateResolved(thenables: ThenableState): boolean {
58-
const lastThenable = thenables[thenables.length - 1];
59-
if (lastThenable !== undefined) {
60-
const status = lastThenable.status;
61-
return status === 'fulfilled' || status === 'rejected';
62-
}
63-
return true;
57+
export function isThenableResolved(thenable: Thenable<mixed>): boolean {
58+
const status = thenable.status;
59+
return status === 'fulfilled' || status === 'rejected';
6460
}
6561

6662
function noop(): void {}

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

+6-9
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ import {
276276
SuspenseException,
277277
getSuspendedThenable,
278278
getThenableStateAfterSuspending,
279-
isThenableStateResolved,
279+
isThenableResolved,
280280
} from './ReactFiberThenable.new';
281281
import {schedulePostPaintCallback} from './ReactPostPaintCallback';
282282
import {
@@ -2204,24 +2204,20 @@ function renderRootConcurrent(root: FiberRoot, lanes: Lanes) {
22042204
break;
22052205
}
22062206
case SuspendedOnData: {
2207+
const thenable: Thenable<mixed> = (thrownValue: any);
22072208
if (workInProgressSuspendedThenableState !== null) {
22082209
const thenableState = workInProgressSuspendedThenableState;
2209-
if (isThenableStateResolved(thenableState)) {
2210+
if (isThenableResolved(thenable)) {
22102211
// The data resolved. Try rendering the component again.
22112212
workInProgressSuspendedReason = NotSuspended;
22122213
workInProgressThrownValue = null;
2213-
replaySuspendedUnitOfWork(
2214-
unitOfWork,
2215-
thrownValue,
2216-
thenableState,
2217-
);
2214+
replaySuspendedUnitOfWork(unitOfWork, thenable, thenableState);
22182215
break;
22192216
}
22202217
}
22212218

22222219
// The work loop is suspended on data. We should wait for it to
22232220
// resolve before continuing to render.
2224-
const thenable: Thenable<mixed> = (workInProgressThrownValue: any);
22252221
const onResolution = () => {
22262222
ensureRootIsScheduled(root, now());
22272223
};
@@ -2246,7 +2242,8 @@ function renderRootConcurrent(root: FiberRoot, lanes: Lanes) {
22462242
default: {
22472243
if (workInProgressSuspendedThenableState !== null) {
22482244
const thenableState = workInProgressSuspendedThenableState;
2249-
if (isThenableStateResolved(thenableState)) {
2245+
const thenable: Thenable<mixed> = (thrownValue: any);
2246+
if (isThenableResolved(thenable)) {
22502247
// The data resolved. Try rendering the component again.
22512248
workInProgressSuspendedReason = NotSuspended;
22522249
workInProgressThrownValue = null;

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

+6-9
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ import {
276276
SuspenseException,
277277
getSuspendedThenable,
278278
getThenableStateAfterSuspending,
279-
isThenableStateResolved,
279+
isThenableResolved,
280280
} from './ReactFiberThenable.old';
281281
import {schedulePostPaintCallback} from './ReactPostPaintCallback';
282282
import {
@@ -2204,24 +2204,20 @@ function renderRootConcurrent(root: FiberRoot, lanes: Lanes) {
22042204
break;
22052205
}
22062206
case SuspendedOnData: {
2207+
const thenable: Thenable<mixed> = (thrownValue: any);
22072208
if (workInProgressSuspendedThenableState !== null) {
22082209
const thenableState = workInProgressSuspendedThenableState;
2209-
if (isThenableStateResolved(thenableState)) {
2210+
if (isThenableResolved(thenable)) {
22102211
// The data resolved. Try rendering the component again.
22112212
workInProgressSuspendedReason = NotSuspended;
22122213
workInProgressThrownValue = null;
2213-
replaySuspendedUnitOfWork(
2214-
unitOfWork,
2215-
thrownValue,
2216-
thenableState,
2217-
);
2214+
replaySuspendedUnitOfWork(unitOfWork, thenable, thenableState);
22182215
break;
22192216
}
22202217
}
22212218

22222219
// The work loop is suspended on data. We should wait for it to
22232220
// resolve before continuing to render.
2224-
const thenable: Thenable<mixed> = (workInProgressThrownValue: any);
22252221
const onResolution = () => {
22262222
ensureRootIsScheduled(root, now());
22272223
};
@@ -2246,7 +2242,8 @@ function renderRootConcurrent(root: FiberRoot, lanes: Lanes) {
22462242
default: {
22472243
if (workInProgressSuspendedThenableState !== null) {
22482244
const thenableState = workInProgressSuspendedThenableState;
2249-
if (isThenableStateResolved(thenableState)) {
2245+
const thenable: Thenable<mixed> = (thrownValue: any);
2246+
if (isThenableResolved(thenable)) {
22502247
// The data resolved. Try rendering the component again.
22512248
workInProgressSuspendedReason = NotSuspended;
22522249
workInProgressThrownValue = null;

0 commit comments

Comments
 (0)