Skip to content

Commit d2333a8

Browse files
authored
feat: always polyfill fetch (#1)
Node 18+ introduces the fetch API globally but it does not yet support all our use-cases.
1 parent c88170b commit d2333a8

File tree

3 files changed

+8
-13
lines changed

3 files changed

+8
-13
lines changed

packages/fetch/src/lib.node.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import * as WebFetch from "./fetch.js"
22

33
export { ReadableStream, Blob, FormData } from './package.js';
4-
// Electron-renderer should get the browser implementation instead of node
5-
// Browser configuration is not enough
4+
// Node 18+ introduces fetch API globally and it doesn't support our use-cases yet.
5+
// For now we always use the polyfill.
66

77
// Marking export as a DOM File object instead of custom class.
88
export const fetch = /** @type {typeof globalThis.fetch} */
9-
(typeof globalThis.fetch === "function" ? globalThis.fetch : WebFetch.fetch)
9+
WebFetch.fetch
1010

11-
export const Headers = globalThis.Headers || WebFetch.Headers
12-
export const Request = globalThis.Request || WebFetch.Request
13-
export const Response = global.Response || WebFetch.Response
11+
export const Headers = WebFetch.Headers
12+
export const Request = WebFetch.Request
13+
export const Response = WebFetch.Response
1414

1515
export default fetch

packages/file/src/lib.node.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ import { File as WebFile } from "./file.js"
88

99
// Marking export as a DOM File object instead of custom class.
1010
/** @type {typeof globalThis.File} */
11-
const File = typeof globalThis.File === "function" ? globalThis.File : WebFile
11+
const File = WebFile
1212

1313
export { File, Blob }

packages/form-data/src/lib.node.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,4 @@
33

44
import * as polyfill from "./form-data.js"
55

6-
// Electron-renderer should get the browser implementation instead of node
7-
// which is why we check global first.
8-
export const FormData =
9-
typeof globalThis.FormData === "function"
10-
? globalThis.FormData
11-
: polyfill.FormData
6+
export const FormData = polyfill.FormData

0 commit comments

Comments
 (0)