Skip to content
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

Pure grpc transport not available for React native #1372

Closed
JPFrancoia opened this issue Dec 27, 2024 · 4 comments
Closed

Pure grpc transport not available for React native #1372

JPFrancoia opened this issue Dec 27, 2024 · 4 comments

Comments

@JPFrancoia
Copy link

Describe the bug

I'm building a React Native app (with Expo). This app is meant to be deployed on Android and iOS, and it'll be a client to a backend written with connect Go. I'm attempting to use a pure gRPC transport for this app, taking example from the Node section of the docs:

import { createGrpcTransport } from "@connectrpc/connect-node";
import { createClient } from "@connectrpc/connect";

class GrpcClient {
  readonly #transport: Transport;

  constructor(host: string, port: number) {
    this.#transport = createGrpcTransport({
      baseUrl: `${host}:${port}`,
      interceptors: [],
    });
  }
}

When building my app for Android, I'm getting the following error:

Android Bundling failed 4222ms node_modules/expo-router/entry.js (1275 modules)
The package at "node_modules/@connectrpc/connect-node/dist/esm/compression.js" attempted to import the Node standard library module "zlib".
It failed because the native React runtime does not include the Node standard library.
Learn more: https://docs.expo.dev/workflow/using-libraries/#using-third-party-libraries

If I do this instead, it works (I can make a client with the transport and I can query my backend):

import { createGrpcWebTransport } from "@connectrpc/connect-web";
...
    this.#transport = createGrpcWebTransport({

I have a couple of questions from these observations:

  • Is there a way (or a plan maybe?) to enable a pure gRPC transport for native platforms?
  • How bad an overhead would I get using grpc-web instead of pure grpc? If I understand well what I'm doing (not a given haha), the conversion to gRPC should still happen on the device, so the call to the backend should still be pure gRPC.
@JPFrancoia JPFrancoia added the bug Something isn't working label Dec 27, 2024
@srikrsna-buf
Copy link
Member

  • Is there a way (or a plan maybe?) to enable a pure gRPC transport for native platforms?

The only way I can think of doing this is via a bridge to the native platform and using a platform native HTTP/2 implementation on each supported platform. This far exceeds the scope of this project, and is not planned. If you want to do this implementing a custom httpClient for each platform will do the trick.

  • How bad an overhead would I get using grpc-web instead of pure grpc? If I understand well what I'm doing (not a given haha), the conversion to gRPC should still happen on the device, so the call to the backend should still be pure gRPC.

It is hard to estimate, but my guess is not a lot, because the fetch implementation will end up using HTTP/2 under the hood so I don't see a clear benefit to using gRPC in this situation, except for better compression of trailers.

@srikrsna-buf srikrsna-buf removed the bug Something isn't working label Dec 30, 2024
@JPFrancoia
Copy link
Author

Ok, that makes sense. FYI, I'm reimplementing a project that uses Dart/Flutter, and in this project I was able to use a GrpcOrGrpcWebClientChannel : https://github.com/grpc/grpc-dart/blob/master/lib/grpc_or_grpcweb.dart. That gave me a pure gRPC transport for native platforms, and a gRPC-web transport for web.

@srikrsna-buf
Copy link
Member

I was able to use a GrpcOrGrpcWebClientChannel : https://github.com/grpc/grpc-dart/blob/master/lib/grpc_or_grpcweb.dart. That gave me a pure gRPC transport for native platforms, and a gRPC-web transport for web.

grpc-dart uses dart native implementation of HTTP/2. It doesn't use the platform APIs. React native on the other hand has to use platform native APIs via a bridge, it can only use a subset of web standards otherwise.

@JPFrancoia
Copy link
Author

Thanks for the explanation, much appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants