Skip to content

Commit

Permalink
Polyfill FormData with edge-runtime primitives (#48826)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
shuding committed Apr 25, 2023
1 parent 8602bf3 commit ac8de9f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
5 changes: 3 additions & 2 deletions packages/next/src/server/node-polyfill-form.ts
Expand Up @@ -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
}
9 changes: 4 additions & 5 deletions packages/next/src/server/node-polyfill-web-streams.ts
@@ -1,12 +1,11 @@
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
}

0 comments on commit ac8de9f

Please sign in to comment.