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

This commit is contained in:
Jiachi Liu 2021-11-16 22:24:54 +01:00 committed by GitHub
parent afbc2d08f4
commit 520ffc77a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View File

@ -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);

View File

@ -15,6 +15,7 @@ module.exports = {
WeakSet: true,
Uint16Array: true,
Reflect: true,
globalThis: true,
// Vendor specific
MSApp: true,
__REACT_DEVTOOLS_GLOBAL_HOOK__: true,