Skip to content

Commit

Permalink
Use globalThis if possible for native fetch in browser build (#22777)
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi authored Nov 16, 2021
1 parent afbc2d0 commit 520ffc7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/react-fetch/src/ReactFetchBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ type RejectedRecord = {|

type Record = PendingRecord | ResolvedRecord | RejectedRecord;

declare var globalThis: any;

// TODO: this is a browser-only version. Add a separate Node entry point.
const nativeFetch = window.fetch;
const nativeFetch = (typeof globalThis !== 'undefined' ? globalThis : window)
.fetch;

function getRecordMap(): Map<string, Record> {
return unstable_getCacheForType(createRecordMap);
Expand Down
1 change: 1 addition & 0 deletions scripts/rollup/validate/eslintrc.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = {
WeakSet: true,
Uint16Array: true,
Reflect: true,
globalThis: true,
// Vendor specific
MSApp: true,
__REACT_DEVTOOLS_GLOBAL_HOOK__: true,
Expand Down

0 comments on commit 520ffc7

Please sign in to comment.