@samitouri / QOS-React / commits / 520ffc77a3

Use globalThis if possible for native fetch in browser build (#22777)

Jiachi Liu committed Nov 16, 2021 at 22:24 UTC 520ffc77a399cc1fd785929b42a84f3d1c8bd106
2 files changed +5 -1
packages/react-fetch/src/ReactFetchBrowser.js
+4 -1
@@ -32,8 +32,11 @@ type RejectedRecord = {|
32
33 type Record = PendingRecord | ResolvedRecord | RejectedRecord;
34
35 +declare var globalThis: any;
36 +
37 // TODO: this is a browser-only version. Add a separate Node entry point.
36 -const nativeFetch = window.fetch;
38 +const nativeFetch = (typeof globalThis !== 'undefined' ? globalThis : window)
39 + .fetch;
40
41 function getRecordMap(): Map<string, Record> {
42 return unstable_getCacheForType(createRecordMap);
scripts/rollup/validate/eslintrc.cjs.js
+1
@@ -15,6 +15,7 @@ module.exports = {
15 WeakSet: true,
16 Uint16Array: true,
17 Reflect: true,
18 + globalThis: true,
19 // Vendor specific
20 MSApp: true,
21 __REACT_DEVTOOLS_GLOBAL_HOOK__: true,