-
Notifications
You must be signed in to change notification settings - Fork 130
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
ReactNative GrpcWebFetchTransport produces RpcError: premature end of response #67
Comments
Hey @kgoguevgoget, the RpcError seems to originate here: protobuf-ts/packages/grpcweb-transport/src/grpc-web-format.ts Lines 75 to 76 in 2cfe191
So the We need the The question is, why is Apparently, react native uses the fetch API polyfill Unfortunately, this polyfill does not implement the |
(sorry, my fat fingers hit enter by accident) I see the following options:
Could you have a look at option 1? I guess this could look like this: if (__DEV__) {
(globalThis as any).fetch = (globalThis as any).originalFetch;
} See https://medium.com/@kureevalexey/hi-birkir-gudjonsson-fb6299cd7e33 and https://github.com/facebook/react-native/blob/6e6443afd04a847ef23fb6254a84e48c70b45896/Libraries/Utilities/PolyfillFunctions.js |
Ah Ok I will try to see if option 1 is a viable solution here. As for option 2, I am afraid that my knowledge in typescript is not as adept as Go so I wouldn't be able to help out with that one but lets see if at least option 1 gets us further Thanks for the quick response! |
Hi there, just wanted to give an update and a bit of a guide on how I managed to get it to work: As per your notes: React Native uses whatwg-fetch which DOES NOT support ReadableStream and the Body property. There is however the following: https://www.npmjs.com/package/react-native-polyfill-globals From the react-native-pollyfill globals package we can actually patch the whatwg-fetch to support the body and FileReader.readAsArrayBuffer. npm i @stardazed/streams-polyfill
npm install react-native-polyfill-globals
npm install -D patch-package
npx patch-package --patch-dir node_modules/react-native-polyfill-globals/patches In index.js at the top add
Once ReactNative is patched to support those mentioned above we can actually just run the GrpcWebFetchTransport as I did in the first post. So yes actually React Native works with your library but you'll need to polyfill + use the patches in the linked package |
That's great news, thanks for the info. I have added a note in the manual with a link to this issue. |
Hi I am building an android app using React Native and wish to use your library to help with making gRPC requests to my gRPC server, I have managed to successfully get it working without problems using GrpcWebFetchTransport on a pure react application.
But the same code appears to have issues when running on Android using React Native.
I imagine that it has something to do with the Transport I'm using while running on android because I can clearly see that my request is getting sent to the server and processed correctly but the issue lies in the react native side, specifically trying to read the response.
For reference I have tried the other transports you listed in the manual but
GrpcWebFetchTransport
was the only one that managed to make a request, it just happened to fail on reading the response.Note: that my gRPC server only accepts binary requests and only unary calls.
example proto
Client code
I have been able to successfully make a gRPC request using https://github.com/improbable-eng/grpc-web/tree/master/client/grpc-web-react-native-transport but this requires me to generate the proto file using a completely diffrent method and moving away from your library which I don't want to do.
Using the Improbable-end/grpc-web-react-native transport. It seems to be using XHR but im not sure if thats the reason that one works and your GrpcWebFetch doesn't.
Any ideas?
The text was updated successfully, but these errors were encountered: