diff --git a/packages/next/server/body-streams.ts b/packages/next/server/body-streams.ts index 7218529a660a4e..f5bd6dfe172bc7 100644 --- a/packages/next/server/body-streams.ts +++ b/packages/next/server/body-streams.ts @@ -3,11 +3,14 @@ import { PassThrough, Readable } from 'stream' export function requestToBodyStream( context: { ReadableStream: typeof ReadableStream }, + KUint8Array: typeof Uint8Array, stream: Readable ) { return new context.ReadableStream({ start(controller) { - stream.on('data', (chunk) => controller.enqueue(chunk)) + stream.on('data', (chunk) => + controller.enqueue(new KUint8Array([...new Uint8Array(chunk)])) + ) stream.on('end', () => controller.close()) stream.on('error', (err) => controller.error(err)) }, diff --git a/packages/next/server/web/sandbox/fetch-inline-assets.ts b/packages/next/server/web/sandbox/fetch-inline-assets.ts index 8c3c0ba751b11f..b017c6e8ee752b 100644 --- a/packages/next/server/web/sandbox/fetch-inline-assets.ts +++ b/packages/next/server/web/sandbox/fetch-inline-assets.ts @@ -34,7 +34,7 @@ export async function fetchInlineAsset(options: { if (fileIsReadable) { const readStream = createReadStream(filePath) return new options.context.Response( - requestToBodyStream(options.context, readStream) + requestToBodyStream(options.context, Uint8Array, readStream) ) } } diff --git a/packages/next/server/web/sandbox/sandbox.ts b/packages/next/server/web/sandbox/sandbox.ts index d232294d5fceab..1d689fd0b8749a 100644 --- a/packages/next/server/web/sandbox/sandbox.ts +++ b/packages/next/server/web/sandbox/sandbox.ts @@ -92,11 +92,14 @@ export const run = withTaggedErrors(async (params) => { ? params.request.body?.cloneBodyStream() : undefined + const KUint8Array = runtime.evaluate('Uint8Array') + try { const result = await edgeFunction({ request: { ...params.request, - body: cloned && requestToBodyStream(runtime.context, cloned), + body: + cloned && requestToBodyStream(runtime.context, KUint8Array, cloned), }, }) for (const headerName of FORBIDDEN_HEADERS) {