summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 = {