Remove vendored fetch polyfill, update to whatwg-fetch@3.0 by janicduplessis · Pull Request #24418 · facebook/react-native (original) (raw)

Hello, I'm one of the authors and maintainers of whatwg-fetch 👋

I'm happy to learn that adding self to React Native will make this problem go away JakeChampion/fetch#657

I have also found this puzzling comment:

// RN currently lazy loads whatwg-fetch using a custom fetch module, which,
// when called for the first time, requires and re-exports 'whatwg-fetch'.
// However, when a dependency of the project tries to require whatwg-fetch
// either directly or indirectly, whatwg-fetch is required before
// RN can lazy load whatwg-fetch. As whatwg-fetch checks
// for a fetch polyfill before loading, it will in turn try to load
// RN's fetch module, which immediately tries to import whatwg-fetch AGAIN.
// This causes a circular require which results in RN's fetch module
// exporting fetch as 'undefined'.
// The fix below postpones trying to load fetch until the first call to symbolicateStackTrace.
// At that time, we will have either global.fetch (whatwg-fetch) or RN's fetch.
if (!fetch) {
fetch = global.fetch |

Can anyone explain is this still relevant? Is there something we can tweak in whatwg-fetch to make this workaround obsolete?

Finally, what is the reason React Native bundles a window.fetch polyfill in the first place? Are any of the browser targets for React Native apps such old browsers that have no native support for window.fetch?

Thank you!