diff --git a/packages/astro/src/runtime/server/render/page.ts b/packages/astro/src/runtime/server/render/page.ts index e6852fa2a0ce..8c92fd91f219 100644 --- a/packages/astro/src/runtime/server/render/page.ts +++ b/packages/astro/src/runtime/server/render/page.ts @@ -5,7 +5,7 @@ import type { AstroComponentFactory } from './index.js'; import { isAstroComponentFactory } from './astro/index.js'; import { renderToAsyncIterable, renderToReadableStream, renderToString } from './astro/render.js'; import { encoder } from './common.js'; -import { isNode, isDeno } from './util.js'; +import { supportsResponseBodyAsyncIterator } from './util.js'; export async function renderPage( result: SSRResult, @@ -48,9 +48,7 @@ export async function renderPage( let body: BodyInit | Response; if (streaming) { - // isNode is true in Deno node-compat mode but response construction from - // async iterables is not supported, so we fallback to ReadableStream if isDeno is true. - if (isNode && !isDeno) { + if (supportsResponseBodyAsyncIterator) { const nodeBody = await renderToAsyncIterable( result, componentFactory, diff --git a/packages/astro/src/runtime/server/render/util.ts b/packages/astro/src/runtime/server/render/util.ts index 03d4599924a9..373ffada637b 100644 --- a/packages/astro/src/runtime/server/render/util.ts +++ b/packages/astro/src/runtime/server/render/util.ts @@ -205,10 +205,17 @@ export function renderToBufferDestination(bufferRenderFunction: RenderFunction): }; } -export const isNode = - typeof process !== 'undefined' && Object.prototype.toString.call(process) === '[object process]'; -// @ts-expect-error: Deno is not part of the types. -export const isDeno = typeof Deno !== 'undefined'; +export const supportsResponseBodyAsyncIterator = (() => { + let supported = false; + new Response({ + // @ts-expect-error: Response types don't expect the property. + get [Symbol.asyncIterator]() { + supported = true; + return undefined; + }, + }); + return supported; +})(); // We can get rid of this when Promise.withResolvers() is ready export type PromiseWithResolvers = {