mirror of
https://github.com/withastro/astro.git
synced 2025-01-06 22:10:10 -05:00
workaround(node ssr): cancellation support for renderToAsyncIterable (#10319)
* workaround(node ssr): cancellation support for renderToAsyncIterable * add changeset * Update .changeset/nice-pets-tie.md
This commit is contained in:
parent
9076dc821c
commit
19ecccedaa
2 changed files with 14 additions and 1 deletions
5
.changeset/nice-pets-tie.md
Normal file
5
.changeset/nice-pets-tie.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"astro": patch
|
||||
---
|
||||
|
||||
Fixes an issue where streaming SSR responses sometimes failed with "`iterator.result` is not a function" on node-based adapters.
|
|
@ -201,10 +201,14 @@ export async function renderToAsyncIterable(
|
|||
// The `next` is an object `{ promise, resolve, reject }` that we use to wait
|
||||
// for chunks to be pushed into the buffer.
|
||||
let next = promiseWithResolvers<void>();
|
||||
// keep track of whether the client connection is still interested in the response.
|
||||
let cancelled = false;
|
||||
const buffer: Uint8Array[] = []; // []Uint8Array
|
||||
|
||||
const iterator = {
|
||||
const iterator: AsyncIterator<Uint8Array> = {
|
||||
async next() {
|
||||
if (cancelled) return { done: true, value: undefined };
|
||||
|
||||
await next.promise;
|
||||
|
||||
// If an error occurs during rendering, throw the error as we cannot proceed.
|
||||
|
@ -238,6 +242,10 @@ export async function renderToAsyncIterable(
|
|||
|
||||
return returnValue;
|
||||
},
|
||||
async return() {
|
||||
cancelled = true;
|
||||
return { done: true, value: undefined };
|
||||
}
|
||||
};
|
||||
|
||||
const destination: RenderDestination = {
|
||||
|
|
Loading…
Reference in a new issue