Unverified Commit ac8de9fa authored by Shu Ding's avatar Shu Ding Committed by GitHub

Polyfill FormData with edge-runtime primitives (#48826)

It makes more sense to use the `FormData` from `@edge-runtime/primitives` to ensure the version and implementation are aligned, and avoid importing extra modules (as we always import the Edge Runtime).
parent 8602bf35
......@@ -3,6 +3,7 @@
*/
if (!(global as any).FormData) {
const undici = require('next/dist/compiled/undici')
;(global as any).FormData = undici.FormData
const { FormData } =
require('next/dist/compiled/@edge-runtime/primitives/fetch') as typeof import('next/dist/compiled/@edge-runtime/primitives/fetch')
;(global as any).FormData = FormData
}
import {
ReadableStream,
TransformStream,
} from 'next/dist/compiled/@edge-runtime/primitives/streams'
// Polyfill Web Streams for the Node.js runtime.
if (!global.ReadableStream) {
const { ReadableStream } =
require('next/dist/compiled/@edge-runtime/primitives/streams') as typeof import('next/dist/compiled/@edge-runtime/primitives/streams')
global.ReadableStream = ReadableStream
}
if (!global.TransformStream) {
const { TransformStream } =
require('next/dist/compiled/@edge-runtime/primitives/streams') as typeof import('next/dist/compiled/@edge-runtime/primitives/streams')
global.TransformStream = TransformStream
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment