GithubHelp home page GithubHelp logo

Comments (12)

taion avatar taion commented on April 19, 2024

@zpao

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.

taion avatar taion commented on April 19, 2024

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.

zpao avatar zpao commented on April 19, 2024

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.

vjeux avatar vjeux commented on April 19, 2024

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.

taion avatar taion commented on April 19, 2024

@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.

zpao avatar zpao commented on April 19, 2024

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.

taion avatar taion commented on April 19, 2024

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.

zpao avatar zpao commented on April 19, 2024

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.

taion avatar taion commented on April 19, 2024

Got it - thanks for explaining that.

from fbjs.

zpao avatar zpao commented on April 19, 2024

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.

boourns avatar boourns commented on April 19, 2024

@zpao that is correct. I tried this branch with react-native and still ended up with fetch undefined.

from fbjs.

zpao avatar zpao commented on April 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.