Skip to content

Commit

Permalink
fix: Handle ReadableStream
Browse files Browse the repository at this point in the history
  • Loading branch information
Fryuni committed Aug 19, 2024
1 parent 6bb5087 commit 7df2fae
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/request-state/src/runtime/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import type { ReadableStream } from 'node:stream/web';
import type { ReadableStream as Stream } from 'node:stream/web';
import { defineMiddleware } from 'astro/middleware';
import { collectState } from './serverState.js';
import { parse } from 'content-type';

declare const ReadableStream: typeof Stream;

export const onRequest = defineMiddleware(async (_, next) => {
const { getState, result } = await collectState(next);

Expand All @@ -26,6 +28,11 @@ export const onRequest = defineMiddleware(async (_, next) => {
}
}

// @ts-expect-error generator not assignable to ReadableStream
return new Response(render(), result);
if (typeof ReadableStream === 'undefined') {
// @ts-expect-error generator not assignable to ReadableStream
return new Response(render(), result);
}

// @ts-expect-error ReadableStream from Node doesn't match ReadableStream from Web API
return new Response(ReadableStream.from(render()), result);
});

0 comments on commit 7df2fae

Please sign in to comment.