Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use globalThis if possible to access fetch in react-fetch browser build #22777

Merged
merged 1 commit into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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