Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use ReadableStream for response object if deno #10495

Merged
merged 11 commits into from
Apr 1, 2024
6 changes: 4 additions & 2 deletions packages/astro/src/runtime/server/render/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } from './util.js';
import { isNode, isDeno } from './util.js';

export async function renderPage(
result: SSRResult,
Expand Down Expand Up @@ -48,7 +48,9 @@ export async function renderPage(

let body: BodyInit | Response;
if (streaming) {
if (isNode) {
// 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) {
const nodeBody = await renderToAsyncIterable(
result,
componentFactory,
Expand Down
2 changes: 2 additions & 0 deletions packages/astro/src/runtime/server/render/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ 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';
satyarohith marked this conversation as resolved.
Show resolved Hide resolved

// We can get rid of this when Promise.withResolvers() is ready
export type PromiseWithResolvers<T> = {
Expand Down