-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Implement response.body as a stream #746
Comments
@mislav @josh @dgraham Would you be open to a PR for this if I can get it implemented in a fork? Since React Native uses this code to implement |
I'm also curious to hear what the React Native folks think of this idea @arthuralee @janicduplessis @cpojer |
Finally, I thought I'd rope in some of the people contributing to the Thanks! |
From this comment on #198, it seems like there is no interest in adding streaming support to this polyfill. There are other fetch polyfills that do support streaming, such as fetch-readablestream or @stardazed/streams-polyfill. (I also made my own, but it's not very well maintained. 😅) If possible, you may want to consider switching to one of those. |
Note that if the underlying platform does not support streaming responses, then the only thing a polyfill can do is create a If you want actual streaming support in React Native, then React Native would need to implement it itself. |
@MattiasBuelens Thanks for the prompt and thoughtful response!
Since React Native uses this package as its implementation of fetch, wouldn't landing it here address that the next time React Native core upgrades the dep? Or is there something lower level that would need to change? |
It only does that if the underlying fetch implementation actually supports
A fetch polyfill is merely a wrapper around If React Native wanted to support streaming, they would need to add something to their The "proper" way would be for React Native to implement That said, I had a quick look at the source code for their XHR, and it would seem like they should support "pseudo-streaming" with |
Could this be added separate from fetch as an additional plugin similar to the Then people could do something like:
where the latter would patch the getter into the former. What do you think? |
This would be enough for a first step. @cpojer do you think something like the above could be added to react native? if yes whats the best approach? PR this repo? make a new package patching whatwg-fetch like you said ? directly to react-native network code? |
This polyfill was originally intended to be used in web browsers that had no support for the fetch standard. Our target is basically pre-2015 web browsers, and every feature that we add to the polyfill had to be reasonably implementable using the capabilities of those browsers, which was mostly reliant on building on top of XMLHttpRequest. React Native runs under JavaScriptCore, which I have no familiarity with, but I would like to assume that it's a more modern environment than a pre-2015 web browser. I don't think that including this polyfill in React Native was a great call, since we never targeted this environment, and if React Native chose to maintain their own implementation (or use another implementation that targets JavaScriptCore), I think implementing more modern features such as streaming would be more feasible. TL;DR; we likely won't implement streaming here because we don't want to find out what what would be involved in making this functionality work seamlessly in older browsers. |
So it sounds like in the long run we need React Native core to implement fetch, and in the short run the React Native core team ought to fork this repo so we can make PRs against the fork without fear of breaking older browsers? |
It appears that |
|
It is likely that React Native's networking stack will need changes to support newer features and even better would be native support for fetch, but we are not currently working on that. Is the question here whether we'd accept contributions? If so, yes, definitely! Especially if it unblocks progress for this repo, if people are still interested in maintaining this polyfill. |
@cpojer from the comments above it's gonna be hard to add more stuff to this repo. |
@hugomrdias @cpojer React Native GitHub issues tend to get closed to comments (totally understandable, but perhaps not ideal for a long-term topic like this). Maybe if we could set up a fork of this repo under the facebook GitHub org with a more liberal issue-closing policy, that would be better? Thanks! |
@cpojer What do you think about this idea? Thanks! |
Although this issue is closed, it's still an open question where to resume the conversation. So please keep commenting enabled for this issue. Thanks! |
In react-native body.constructor.name == 'Blob' gives I am able to fix it as
Add this condition to https://github.com/github/fetch/blob/7232090c04e1ddefb806910bbd0a756bc8aac2f0/fetch.js#L229 |
@qalqi With that change, |
Yep.. Able to receive a response with ipfs 0.41.0 in react-native with this change |
Here is an another alternative approach it seems.. facebook/react-native#25701 (comment) |
@qalqi Just to confirm, the goal of your change is to get response.body to be defined as a getter for a ReadableStream, is that right? |
Yeah.
It’s resolves body.text() blob stream and sends as response.
With this change, some ipfs 0.41.0 functions work.
|
@qalqi Thanks for getting back to me! A) When using the B) You mean when using the daemon from (A) via |
@qalqi Do you remember specifically which functions are working for you? Thanks! |
A) All get requests are working with Put requests are all failing with error Here is react-native sandbox with working get requests https://github.com/qalqi/react-native-ipfs-http-client/tree/primary/rn-nodeify |
@qalqi Thanks for getting back to me! I'll respond to you over in this new issue on the |
Response has no .body property available which is needed as a getter to expose a
ReadableStream
of the body contents.https://developer.mozilla.org/en-US/docs/Web/API/Body/body
The text was updated successfully, but these errors were encountered: