0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-27 22:19:04 -05:00

fix: use ReadableStream for response object if deno (#10495)

This commit is contained in:
Satya Rohith 2024-04-01 13:35:30 +05:30 committed by GitHub
parent b3028caecf
commit 046d69d517
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 2 deletions

View file

@ -0,0 +1,7 @@
---
"astro": patch
---
This patch allows astro to run in node-compat mode in Deno. Deno doesn't support
construction of response from async iterables in node-compat mode so we need to
use ReadableStream.

View file

@ -5,7 +5,7 @@ import type { AstroComponentFactory } from './index.js';
import { isAstroComponentFactory } from './astro/index.js'; import { isAstroComponentFactory } from './astro/index.js';
import { renderToAsyncIterable, renderToReadableStream, renderToString } from './astro/render.js'; import { renderToAsyncIterable, renderToReadableStream, renderToString } from './astro/render.js';
import { encoder } from './common.js'; import { encoder } from './common.js';
import { isNode } from './util.js'; import { isNode, isDeno } from './util.js';
export async function renderPage( export async function renderPage(
result: SSRResult, result: SSRResult,
@ -48,7 +48,9 @@ export async function renderPage(
let body: BodyInit | Response; let body: BodyInit | Response;
if (streaming) { 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( const nodeBody = await renderToAsyncIterable(
result, result,
componentFactory, componentFactory,

View file

@ -207,6 +207,8 @@ export function renderToBufferDestination(bufferRenderFunction: RenderFunction):
export const isNode = export const isNode =
typeof process !== 'undefined' && Object.prototype.toString.call(process) === '[object process]'; 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';
// We can get rid of this when Promise.withResolvers() is ready // We can get rid of this when Promise.withResolvers() is ready
export type PromiseWithResolvers<T> = { export type PromiseWithResolvers<T> = {