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

Add additional fallbacks when self is undefined #521

Closed
wants to merge 1 commit into from

Conversation

tqc
Copy link

@tqc tqc commented May 17, 2017

This extends the solution in #253 for React Native compatibility.

The existing this fallback is inadequate because in strict mode this is undefined outside of class methods rather than defaulting to the global object.

@mislav
Copy link
Contributor

mislav commented Jun 12, 2017

I have no experience with React Native, but their documentation suggests that fetch is available natively. If this is true, why is the polyfill needed?

@tqc
Copy link
Author

tqc commented Jun 12, 2017

@mislav The polyfill itself may not be needed, but libraries that support multiple platforms (including react itself) can't know that, and without self the polyfill crashes at the point where you check if it is needed.

@tqc
Copy link
Author

tqc commented Jun 12, 2017

@mislav incidentally, I don't think that documentation implies fetch is available natively - just that react wraps this polyfill so the app developer doesnt have to think about it.

@psullivan6
Copy link

Related to this conversation:
Using this polyfill with rollup logs the following warning during the build:

node_modules/whatwg-fetch/fetch.js (461:40) The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten

which means the final line of the script is compiled into:
})(typeof self !== 'undefined' ? self : undefined); where undefined replaced this.


This is using the ES6 import 'whatwg-fetch'; statement.

@AntonioRedondo
Copy link

AntonioRedondo commented Jul 19, 2017

Any idea when is this gonna be merged? We're trying to use isomorphic-fetch server-side bundled with Rollup. And the issue that this pull request is trying to solve is a blocker.

@qraynaud qraynaud mentioned this pull request Jul 20, 2017
@mislav
Copy link
Contributor

mislav commented May 25, 2018

We now generate a UMD build with Rollup: #616. Let us know if this build works with React Native.

The main fetch.js file is an ES5 file (like before) but with added ES6 exports. This makes it compatible with Rollup, and is referred to by module keyword from package.json. This should make the library work better with packagers.

@mislav mislav closed this May 25, 2018
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants