Skip to content

Commit 92e5533

Browse files
committed
Revert "Unwrap sync resolved thenables without suspending (facebook#25615)"
This reverts commit 1a90262. If a thenable resolves synchronously, `use` should unwrap its result without suspending or interrupting the component's execution.
1 parent d807eb5 commit 92e5533

File tree

2 files changed

+3
-42
lines changed

2 files changed

+3
-42
lines changed

packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5426,33 +5426,6 @@ describe('ReactDOMFizzServer', () => {
54265426
expect(Scheduler).toFlushAndYield([]);
54275427
expect(getVisibleChildren(container)).toEqual('Hi');
54285428
});
5429-
5430-
// @gate enableUseHook
5431-
it('unwraps thenable that fulfills synchronously without suspending', async () => {
5432-
function App() {
5433-
const thenable = {
5434-
then(resolve) {
5435-
// This thenable immediately resolves, synchronously, without waiting
5436-
// a microtask.
5437-
resolve('Hi');
5438-
},
5439-
};
5440-
try {
5441-
return <Text text={use(thenable)} />;
5442-
} catch {
5443-
throw new Error(
5444-
'`use` should not suspend because the thenable resolved synchronously.',
5445-
);
5446-
}
5447-
}
5448-
// Because the thenable resolves synchronously, we should be able to finish
5449-
// rendering synchronously, with no fallback.
5450-
await act(async () => {
5451-
const {pipe} = renderToPipeableStream(<App />);
5452-
pipe(writable);
5453-
});
5454-
expect(getVisibleChildren(container)).toEqual('Hi');
5455-
});
54565429
});
54575430

54585431
describe('useEvent', () => {

packages/react-server/src/ReactFizzThenable.js

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,36 +83,24 @@ export function trackUsedThenable<T>(
8383
// it's defined, but an unknown value, assume it's been instrumented by
8484
// some custom userspace implementation. We treat it as "pending".
8585
} else {
86-
const pendingThenable: PendingThenable<T> = (thenable: any);
86+
const pendingThenable: PendingThenable<mixed> = (thenable: any);
8787
pendingThenable.status = 'pending';
8888
pendingThenable.then(
8989
fulfilledValue => {
9090
if (thenable.status === 'pending') {
91-
const fulfilledThenable: FulfilledThenable<T> = (thenable: any);
91+
const fulfilledThenable: FulfilledThenable<mixed> = (thenable: any);
9292
fulfilledThenable.status = 'fulfilled';
9393
fulfilledThenable.value = fulfilledValue;
9494
}
9595
},
9696
(error: mixed) => {
9797
if (thenable.status === 'pending') {
98-
const rejectedThenable: RejectedThenable<T> = (thenable: any);
98+
const rejectedThenable: RejectedThenable<mixed> = (thenable: any);
9999
rejectedThenable.status = 'rejected';
100100
rejectedThenable.reason = error;
101101
}
102102
},
103103
);
104-
105-
// Check one more time in case the thenable resolved synchronously
106-
switch (thenable.status) {
107-
case 'fulfilled': {
108-
const fulfilledThenable: FulfilledThenable<T> = (thenable: any);
109-
return fulfilledThenable.value;
110-
}
111-
case 'rejected': {
112-
const rejectedThenable: RejectedThenable<T> = (thenable: any);
113-
throw rejectedThenable.reason;
114-
}
115-
}
116104
}
117105

118106
// Suspend.

0 commit comments

Comments
 (0)