react-native: fetch implementation does not support streams from the spec - needs implementation in React Native core

React Native has not implemented fetch on top of native APIs, and the fetch polyfill built on top of XHR does not support streams where response.body is a getter for a ReadableStream.

React Native version:

0.61.4

Steps To Reproduce

Use fetch and see that response.body is undefined rather than a getter for a ReadableStream according the the fetch spec.

Describe what you expected to happen:

I expected for response.body to be defined.

Related issues

https://github.com/facebook/react-native/issues/9629 https://github.com/facebook/react-native/issues/12912 https://github.com/github/fetch/issues/746#issuecomment-573251497 (cc @MattiasBuelens)

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 31
  • Comments: 25 (3 by maintainers)

Commits related to this issue

Most upvoted comments

I am really interested in bringing spec-compliant fetch to react native. I think there’s renewed interest in the OSS community and JS developers to standardise where possible as seen in adding fetch to node.js core and the work Cloudflare, Vercel, Shopify et al are doing in WinterCG.

A spec compliant fetch also aligns with React Native’s goals IMO.

Has there been any discussion in how to bring spec compliant fetch to React Native? The polyfill fork is a good start but I’m not sure the caveats especially around performance and bundle size make it suitable for general adoption.

When generative AI became popular, SSE became the dominant API response when developing AI apps, so it became urgent to satisfy stream, otherwise a lot of AI apps would be lost, and people had to use ionic/flutter/native to realize this feature.

It is also woth to mention, that with the current state of react natives fetch implementation the new graphql features @defer and @stream don’t work. But that is probabbly more related to this issue: https://github.com/facebook/react-native/issues/12912

My bad, I recently took down my blog since it was not getting enough traffic (I started it as an experiment) Anyways you can see the usage on one of my Stackoverflow Answers: https://stackoverflow.com/questions/56207968/stream-api-with-fetch-in-a-react-native-app/77089139#77089139

On iOS, I can successfully receive a text stream using https://github.com/react-native-community/fetch, and I suggest try this library

any update?

The Facebook GitHub org only contains project managed by Facebook. It’ll mean we have to take care of releases and everything. I’m not sure if that’s a good idea, you’ll probably be able to move faster on a separate org. What about react-native-community? @alloy can get you set up with that.

Made a blog post just about how to implement this using the Community fetch polyfill (streaming works like a charm in RN now!)

https://blog.codergautam.dev/how-to-use-streaming-fetch/

EDIT- SEE MY NEW SO ANSWER FOR STEPS TO USE IT: https://stackoverflow.com/questions/56207968/stream-api-with-fetch-in-a-react-native-app/77089139#77089139

I’m using it for OpenAI API and works perfectly

This issue still requires the community’s attention. Thanks!

Just created the fork and added you, @pcowgill react-native-community/fetch

can you please add me too, thanks

Just created the fork and added you, @pcowgill https://github.com/react-native-community/fetch