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
4 changes: 2 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 { supportsResponseBodyAsyncIterator } from './util.js';

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

let body: BodyInit | Response;
if (streaming) {
if (isNode) {
if (supportsResponseBodyAsyncIterator) {
const nodeBody = await renderToAsyncIterable(
result,
componentFactory,
Expand Down
13 changes: 11 additions & 2 deletions packages/astro/src/runtime/server/render/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,17 @@ export function renderToBufferDestination(bufferRenderFunction: RenderFunction):
};
}

export const isNode =
typeof process !== 'undefined' && Object.prototype.toString.call(process) === '[object process]';
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<T> = {
Expand Down
Loading