Closed UntakerAnonPLAY closed 2 weeks ago
We'll need more information to reproduce. What do you mean by "parameters"? URL query parameters?
By parameters I mean request messages, I don't even know what info to give you to reproduce, cause I tried different versions of connect rpc and It was the same. Only strange thing I've noticed that might help you is that in 1.6.1 Interceptor on a server side of next js wasn't showing full class data of a message, but only it's data members (no functions like toBinary). Maybe because of this connect couldn't construct the network call correctly. So I switched to 2.0.0 rc2, but same behaviour.
*I'm making network calls using client in asynchronous page component
We have an example with Next.js here that doesn't show this issue: https://github.com/connectrpc/examples-es/tree/main/nextjs
The example serves and calls RPCs with the Connect protocol with Protobuf JSON. It uses Next.js 15.0.2 (since https://github.com/connectrpc/examples-es/pull/1973) and the latest release candidate, but we haven't seen any similar issues with earlier versions either.
Maybe this helps you narrow the problem down. We will not be able to reproduce the issue without significantly more information.
Probably a stupid question, but do I need a next js adapter if I'm using it as a server side client?
Cause I'm seeing an example is using it, but I thought It's only needed for server + client cases, for web client to make requests to next js. In my case I only need a client on a next js server part that calls another server.
Ok, so far I figured out this things: 1) Next js client to next js server is working using next js connect adapter 2) If I'm doing a request from a node connect client to a node connect server it is working 3) If I'm doing step 2 in a running next js server it is not (I have a behaviour described in the first message) 4) Also If I'm trying to do step 3 (make a request out of next js server to external connect server) without binary format, I'm getting this error: "cannot decode message editor_api.v1.LoadRequest from JSON: JSON Parse error: Unexpected EOF"
Btw, external connect server uses fastify plugin
Ok, for now it seems to me that connect transport from connect-node for connect client is not willing to work with next js server side. Because connect transport from gpc web is working with next js, I'm switching to it for now.
So If you want to reproduce - grab a connect transport from a connect node and create a client in next js server side, then try to pass any messages with payloads to a connect server. Check if payload is there. Maybe it's not where the problem lays but that's all I figured out soon. (None of the examples for next js are actually testing this)
Btw, I think connect web transport is working cause next js has a global fetch, but this also introduces me to this problem "Failed to generate cache key for Method Path". And next js is doing some strange things with a default node http mechanism intercepting connect request
There actually are two pages in the Next.js example that call another Connect server:
Both are calling an RPC on demo.connectrpc.com, where we run the demo service ELIZA. Both clients use the Connect transport from @connecrpc/connect-web
, but they work just as well with the Connect transport from @connectrpc/connect-node
.
cannot decode message editor_api.v1.LoadRequest from JSON: JSON Parse error: Unexpected EOF
This looks like an error message from the server, which didn't receive the full request.
Unfortunately, we will not be able to help, since the two transports use different code paths, Next.js behavior varies between different contexts (getServerSideProps, RSC), and there are several other variables. This means there is a very large number of different scenarios, and only a very specific one might yield the error you are seeing.
The only way we can help you is if you provide a reproducible example.
Ok, fuck, it's bun, I double tested everything, and when I'm using bun I get this problem. I reproduced it using next js react server action example and fastify server example. I don't know if you care about bun support or something, but if you change tsx to bun, you can reproduce it.
Ah, bun. They aim for compatibility with Node.js v20, so @connectrpc/connect-node
should work: https://bun.sh/docs/runtime/nodejs-apis
Can you open an issue against bun? There isn't anything we can do on our side. I'm sure they'd appreciate a reproducible example to pinpoint the issue.
Describe the bug
When I'm trying to call an rpc method in next js environment, server doesn't see any parameters passed(default values). Calls without parameters are working. Receiving the answer is working also. I see that parameters are actually sent via interceptors, but are just ignored by a server (I'm controlling the server also). When I call the method without next js it works.
Environment (please complete the following information):