Skip to content

Commit d079f96

Browse files
Arthur LeeM-i-k-e-l
Arthur Lee
authored andcommitted
Use fetch as a polyfill
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
1 parent 8fbab55 commit d079f96

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

Libraries/Network/fetch.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111

1212
'use strict';
1313

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

16-
if (whatwg && whatwg.fetch) {
17-
module.exports = whatwg;
18-
} else {
19-
module.exports = {fetch, Headers, Request, Response};
20-
}
18+
module.exports = {fetch, Headers, Request, Response};

0 commit comments

Comments
 (0)