Skip to content

Commit

Permalink
Use fetch as a polyfill
Browse files Browse the repository at this point in the history
Summary:
The old whatwg-fetch module doesn't actually export anything, so we would always hit the `else` condition.

The new whatwg-fetch (3.0.0, introduced in facebook#24418) now exports an ES module. As a result, `whatwg` and `whatwg.fetch` are both truthy but the `module.exports` will end up empty. This breaks the RN fetch module.

This will switch the behavior back to the expected polyfill behavior (calling `require('whatwg-fetch')` and allowing it to polyfill fetch in global scope). The RN fetch module will re-export these globals.

Reviewed By: cpojer

Differential Revision: D15639851

fbshipit-source-id: ebd8bce85f7797d8539f53982e515ac47f6425e7
  • Loading branch information
Arthur Lee authored and M-i-k-e-l committed Mar 10, 2020
1 parent 8fbab55 commit d079f96
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions Libraries/Network/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@

'use strict';

const whatwg = require('whatwg-fetch');
// side-effectful require() to put fetch,
// Headers, Request, Response in global scope
require('whatwg-fetch');

if (whatwg && whatwg.fetch) {
module.exports = whatwg;
} else {
module.exports = {fetch, Headers, Request, Response};
}
module.exports = {fetch, Headers, Request, Response};

0 comments on commit d079f96

Please sign in to comment.