mirror of
https://github.com/zebrajr/react.git
synced 2025-12-06 12:20:20 +01:00
[Flight] don't emit chunks for rejected thenables after abort (#31169)
When aborting we emit chunks for each pending task. However there was a bug where a thenable could also reject before we could flush and we end up with an extra chunk throwing off the pendingChunks bookeeping. When a task is retried we skip it if is is not in PENDING status because we understand it was completed some other way. We need to replciate this for the reject pathway on serialized thenables since aborting if effectively completing all pending tasks and not something we need to continue to do once the thenable rejects later.
This commit is contained in:
parent
566b0b0f14
commit
38af456a49
|
|
@ -3084,4 +3084,54 @@ describe('ReactFlightDOM', () => {
|
|||
</div>,
|
||||
);
|
||||
});
|
||||
|
||||
it('rejecting a thenable after an abort before flush should not lead to a frozen readable', async () => {
|
||||
const ClientComponent = clientExports(function (props: {
|
||||
promise: Promise<void>,
|
||||
}) {
|
||||
return 'hello world';
|
||||
});
|
||||
|
||||
let reject;
|
||||
const promise = new Promise((_, re) => {
|
||||
reject = re;
|
||||
});
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<div>
|
||||
<Suspense fallback="loading...">
|
||||
<ClientComponent promise={promise} />
|
||||
</Suspense>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const errors = [];
|
||||
const {writable, readable} = getTestStream();
|
||||
const {pipe, abort} = await serverAct(() =>
|
||||
ReactServerDOMServer.renderToPipeableStream(<App />, webpackMap, {
|
||||
onError(x) {
|
||||
errors.push(x);
|
||||
},
|
||||
}),
|
||||
);
|
||||
await serverAct(() => {
|
||||
abort('STOP');
|
||||
reject('STOP');
|
||||
});
|
||||
pipe(writable);
|
||||
|
||||
const reader = readable.getReader();
|
||||
while (true) {
|
||||
const {done} = await reader.read();
|
||||
if (done) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
expect(errors).toEqual(['STOP']);
|
||||
|
||||
// We expect it to get to the end here rather than hang on the reader.
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -696,6 +696,10 @@ function serializeThenable(
|
|||
pingTask(request, newTask);
|
||||
},
|
||||
reason => {
|
||||
if (newTask.status === PENDING) {
|
||||
// We expect that the only status it might be otherwise is ABORTED.
|
||||
// When we abort we emit chunks in each pending task slot and don't need
|
||||
// to do so again here.
|
||||
if (
|
||||
enablePostpone &&
|
||||
typeof reason === 'object' &&
|
||||
|
|
@ -712,6 +716,7 @@ function serializeThenable(
|
|||
newTask.status = ERRORED;
|
||||
request.abortableTasks.delete(newTask);
|
||||
enqueueFlush(request);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user