Skip to content

Commit 520ffc7

Browse files
authored
Use globalThis if possible for native fetch in browser build (#22777)
1 parent afbc2d0 commit 520ffc7

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

packages/react-fetch/src/ReactFetchBrowser.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ type RejectedRecord = {|
3232

3333
type Record = PendingRecord | ResolvedRecord | RejectedRecord;
3434

35+
declare var globalThis: any;
36+
3537
// 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;
3740

3841
function getRecordMap(): Map<string, Record> {
3942
return unstable_getCacheForType(createRecordMap);

scripts/rollup/validate/eslintrc.cjs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module.exports = {
1515
WeakSet: true,
1616
Uint16Array: true,
1717
Reflect: true,
18+
globalThis: true,
1819
// Vendor specific
1920
MSApp: true,
2021
__REACT_DEVTOOLS_GLOBAL_HOOK__: true,

0 commit comments

Comments
 (0)