Comments (12)
Webpack prefers the browser version (by default), so it works just fine with isomorphic-fetch
and properly pulls in the browser polyfill. I use this exact configuration for my non-Relay applications and it works as expected.
With RN, I believe both versions of the polyfill are set up to not replace the global version if one is already available. The risk would more be if they just completely failed to import - I can't easily test this right now; don't have an RN setup yet.
from fbjs.
Specifically I use isomorphic-fetch
with Webpack in a configuration exactly analogous to the Relay case - isomorphic-fetch
is a subdependency of a library that I directly depend on, and Webpack properly resolves the browser version.
from fbjs.
Awesome, thanks for the info! Seems like it should just work for the majority of cases then.
With RN, I believe both versions of the polyfill are set up to not replace the global version if one is already available.
You're right it does. Still haven't had a chance to look into the RN support. Perhaps @vjeux knows?
from fbjs.
React Native uses github's fetch implementation that takes over the global variable:
https://github.com/facebook/react-native/blob/7f76f08a11fe1354b132c2875dc2fcf6195c2979/Libraries/Fetch/fetch.js
https://github.com/facebook/react-native/blob/ce814686078058b01bbbf39017745a3ebd1ec07a/Libraries/JavaScriptAppEngine/Initialization/InitializeJavaScriptAppEngine.js#L117-L121
Happy to change it to isomorphic fetch or anything else if it still works in React Native
from fbjs.
@vjeux: isomorphic-fetch
uses keys on package.json
to plug into node-fetch
or whatwg-fetch
. If the RN packager pulls in the browser versions of libraries over the Node versions, then using isomorphic-fetch
should just pull in whatwg-fetch
. Otherwise there might be some extra work involved.
from fbjs.
Talked with @vjeux in person, sounds like the packager will use the browser
field so we should be fine. The only issue left for them is then having multiple fetch impls packaged (even if only 1 is used, there are a few extra bytes)
from fbjs.
Huh? Does the RN packager pull in unused files? Why would it pull in node-fetch
at all if it's just going off what's on the browser
field?
from fbjs.
Didn't say it would. But RN already has a copy of fetch
(linked above) so Relay's requires getting rewritten to pull in fbjs/lib/fetch
would then bring in a 2nd copy of whatwg-fetch
from fbjs.
Got it - thanks for explaining that.
from fbjs.
The comments in facebook/relay#26 make me think this won't actually work in RN due to self
not existing (https://github.com/matthew-andrews/isomorphic-fetch/blob/master/fetch-npm-browserify.js is exactly what we were doing)
from fbjs.
@zpao that is correct. I tried this branch with react-native and still ended up with fetch undefined.
from fbjs.
I think this got worked out in another PR so going to close out. We'll revisit if we need to.
from fbjs.
Related Issues (20)
- Low vulnerability
- ua-parser-js high severity vulnerability HOT 1
- Add CI check to ensure lockfiles up to date
- [security] upgrade to latest version of isomorphic-fetch HOT 10
- CVE-2017-16086 found in ua-parser.js HOT 2
- ua-parser-js to fix Regular Expression Denial Of Service (ReDoS) HOT 1
- areEqual doesn't support objects with null prototypes
- Got error "Cannot destructure property 'instrument' of 'options' as it is undefined" when using with jest:27.0.4 HOT 2
- missing v3.0.0 relase and tag HOT 1
- ua-parser-js Dependency Security vulnerability HOT 1
- 'instrument' required, then optional? Resulting in `TypeError: Cannot destructure property 'instrument' of 'options' as it is undefined.`
- fbjs > [email protected]: this package has been hijacked HOT 1
- [security-update] Update ua-parser-js dependency in fbjs HOT 1
- "ua-parser-js": "0.7.30" have a wrong HOT 3
- Security vulnerability with cross-fetch in fbjs HOT 3
- ChainAlert: new npm maintainer has published version 3.0.3 of package fbjs HOT 3
- Git.io deprecation notice
- upgrade core-js version HOT 1
- ua-parser-js ReDoS Vulnerability HOT 1
- nullthrows has either bad condition or bad error message HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fbjs.