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:
parent
b3028caecf
commit
046d69d517
3 changed files with 13 additions and 2 deletions
7
.changeset/cool-bulldogs-change.md
Normal file
7
.changeset/cool-bulldogs-change.md
Normal 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.
|
|
@ -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,
|
||||||
|
|
|
@ -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> = {
|
||||||
|
|
Loading…
Add table
Reference in a new issue