Comments (5)
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
import "@stardazed/streams-polyfill";
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
from protobuf-ts.
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 body
property of the fetch response is null
. It should be a ReadableStream<Uint8Array>
, see MDN.
We need the ReadableStream
for server streaming methods. We cannot just read the entire data using arrayBuffer()
(see MDN), because then the client would only know about a response message when the entire response has been read.
The question is, why is body === null
?
Apparently, react native uses the fetch API polyfill whatwg-fetch
. See setUpXHR.js and fetch.js.
Unfortunately, this polyfill does not implement the body
property, see JakeChampion/fetch#746
from protobuf-ts.
(sorry, my fat fingers hit enter by accident)
I see the following options:
- determine whether the fetch polyfill added by react native is actually necessary, try to turn it off
- implement a GrpcWebXhrTransport that uses a similar hack like
grpc-web-react-native-transport
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
from protobuf-ts.
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!
from protobuf-ts.
That's great news, thanks for the info. I have added a note in the manual with a link to this issue.
from protobuf-ts.
Related Issues (20)
- TypeScript linting/compiler issues with generated client HOT 2
- Add RpcOptions to Client-Stub constructor? HOT 6
- unused parameters in the empty.ts are causing TypeScript check errors HOT 6
- Global `Object` is not referenced when there is a message named Object. HOT 2
- Proto2 required fields are not serialized when they are the default value HOT 3
- Is this compiling error could be turned off by Typescript or Option in protobuf-ts HOT 2
- 2.9.2 not working with 'exactOptionalPropertyTypes: true' HOT 1
- Release 2.9.3 breaks serialization for me HOT 6
- Generated message classes cannot be subclassed because of missing 'export' HOT 1
- Error decoding from binary: "cant skip wire type 4" HOT 1
- How to debug INVALID_ARGUMENT? HOT 1
- Missing headers on RPCError HOT 8
- rpcError cannot support Chinese
- [Request] Flag to handle google wrapper types HOT 1
- Vite cannot found module HOT 2
- Invalid typescript in descriptor.ts HOT 2
- Can't retry request after awaiting response HOT 2
- Typesafe API to retrieve enums from strings HOT 4
- `output_javascript` no longer emits `.d.ts` files HOT 6
- Request: Support for moduleResolution "nodenext" and "node16" HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from protobuf-ts.