connectrpc / connect-es

The TypeScript implementation of Connect: Protobuf RPC that works.

Home Page:https://connectrpc.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Question?] cache key failed to generate on Next.js app router

mnpqraven opened this issue · comments

commented

Is your feature request related to a problem? Please describe.
I'm relatively new to Connect and have been following the tutorial to implement rpc in my Next.js app.
Considering the following

export function rpc<T extends ServiceType>(service: T): PromiseClient<T> {
  const client = createPromiseClient(
    service,
    createGrpcWebTransport({
      baseUrl: "https://randomurl.com",
    })
  );
  return client;
}

I'm getting cache errors from next saying that caching for this call failed (hsr.dev is my nextjs app and nas-ws is my rust backend server with the rpc endpoints)
image

Describe the solution you'd like
I was wondering if this is a misconfiguration on my part or caching is not yet supported for Next.js, or if caching rpc is not possible in general

I am not familiar with nextjs caching strategy but my guess is that it doesn't support post requests and grpc web works on post

I can confirm that cache only applies to GET requests from this doc. The connect protocol supports GET requests, if you can switch to connect protocol then GET requests (and therefore caching) can be enabled on a per rpc basis.

Let us know if you run into any problems, closing this for now feel free reach out if I missed something.