summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Arsh <69170106+lilnasy@users.noreply.github.com> 2024-03-04 21:15:13 +0530
committerGravatar GitHub <noreply@github.com> 2024-03-04 21:15:13 +0530
commit19ecccedaab6d8fa0ff23711c88fa7d4fa34df38 (patch)
treef3d2dcdb69d895536783b461d251fb796fe97f57
parent9076dc821cf4d0023372ecd4c1d1f4c0f9213afe (diff)
downloadastro-19ecccedaab6d8fa0ff23711c88fa7d4fa34df38.tar.gz
astro-19ecccedaab6d8fa0ff23711c88fa7d4fa34df38.tar.zst
astro-19ecccedaab6d8fa0ff23711c88fa7d4fa34df38.zip
workaround(node ssr): cancellation support for renderToAsyncIterable (#10319)
* workaround(node ssr): cancellation support for renderToAsyncIterable * add changeset * Update .changeset/nice-pets-tie.md
-rw-r--r--.changeset/nice-pets-tie.md5
-rw-r--r--packages/astro/src/runtime/server/render/astro/render.ts10
2 files changed, 14 insertions, 1 deletions
diff --git a/.changeset/nice-pets-tie.md b/.changeset/nice-pets-tie.md
new file mode 100644
index 000000000..02d90002e
--- /dev/null
+++ b/.changeset/nice-pets-tie.md
@@ -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.
diff --git a/packages/astro/src/runtime/server/render/astro/render.ts b/packages/astro/src/runtime/server/render/astro/render.ts
index 4d11254b7..9ee7461f5 100644
--- a/packages/astro/src/runtime/server/render/astro/render.ts
+++ b/packages/astro/src/runtime/server/render/astro/render.ts
@@ -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 = {