fetch icon indicating copy to clipboard operation
fetch copied to clipboard

Technical planning and discussion

Open acostalima opened this issue 4 years ago • 14 comments

@cpojer I'm reaching out to follow up on a previous discussion about coming up with a custom Fetch API implementation for React Native at https://github.com/react-native-community/fetch with support for streaming (https://github.com/facebook/react-native/issues/27741). We, MOXY and Protocol Labs, are planning to start this effort shortly and we'd like to know your thoughts on the matter.

In short, what we currently have in mind is as follows:

  • Rewrite whatwg-fetch in modern JS.
  • Remove XHR out of the equation and implement fetch directly on top of RN's JavaScript Network API exactly for the same reasons outlined at https://github.com/react-native-community/discussions-and-proposals/issues/99.
  • Assume ReadableStream is available in RN's environment which can be polyfilled with web-streams-polyfill. If ReadableStream is expected to only be used in the context of Fetch, we can probably bundle them together.
  • Have tests in place running in an actual RN app on GitHub's CI.

Even if Facebook has no plans to add support for streaming to Fetch for the time being, app developers can easily swap out whatwg-fetch for @react-native-community/fetch manually. Even better would be React Native to do this automatically via some sort of extension or plugin API.

Are there any guidelines which React Native Community packages should conform to? e.g. linter and linting config, CI process config, etc.

CC @satazor @hugomrdias

acostalima avatar Oct 27 '20 19:10 acostalima

/cc @autonome

hugomrdias avatar Oct 27 '20 19:10 hugomrdias

I think this plan sounds good. If your rewrite does not increase bundle size, we can even consider swapping out whatwg-fetch with the new version.

cpojer avatar Oct 28 '20 01:10 cpojer

I'd be very interested in a stable fetch polyfill that handles streams. By the way, I'm currently considering using https://github.com/joltup/rn-fetch-blob#drop-in-fetch-replacement, I'll debrief you of how it works.

tex0l avatar Oct 30 '20 09:10 tex0l

@cpojer Could you please give me permissions to maintain the repo? Thanks!

acostalima avatar Oct 30 '20 11:10 acostalima

@tex0l Thanks! I wasn't aware rn-fetch-blob had a drop-in fetch replacement. That project looks interesting although its complexity is much superior than what we're trying to achieve here considering its has a strong native component. In our case, we're still going to be limited to text streaming as RN's networking layer cannot stream binary.

acostalima avatar Oct 30 '20 11:10 acostalima

@cpojer Could you please give me permissions to maintain the repo? Thanks!

Done!

cpojer avatar Nov 01 '20 09:11 cpojer

@cpojer I'm not being able to publish the package under react-native-community's organization. Can you give me such permission?

acostalima avatar Jan 14 '21 19:01 acostalima

Ping @cpojer.

acostalima avatar Jan 20 '21 16:01 acostalima

@alloy Can you help? 🙏

acostalima avatar Jan 25 '21 11:01 acostalima

Paging @Titozzz re moving packages out of the RNC namespace. What's the goal wrt new packages, can they still publish under the org name or should they publish to their own namespace?

alloy avatar Jan 25 '21 12:01 alloy

Everyone is moving out of the RNC Scope so yeah it should be published under its own name

Titozzz avatar Jan 25 '21 12:01 Titozzz

@Titozzz got it, thanks! I assume react-native-fetch or similar is the way to go?

acostalima avatar Jan 25 '21 12:01 acostalima

Published as react-native-fetch-api 🎉

acostalima avatar Jan 25 '21 13:01 acostalima

@acostalima Did you manage to the the time to fix the Android issue? As I understand it your solution does not work on android devices currently. Thank you for the hard work you put into making it.

I feel like the React team should be supporting this. It is rather important and it seems like a lot of libraries have had to work around this often by having to drop to native code which is extremely painful because it means that rather than allowing users to use already published and maintained libraries they need to make special one off ones for React Native.

Regardless of what is popular for features this seems like a rather important problem to the platform at a fundamental level. It should be worked on so we don't need to duplicate libraries that do a bit more than simple HTTP requests.

RobertWHurst avatar Apr 12 '23 05:04 RobertWHurst