tRPC

T

tRPC

Join the community to ask questions about tRPC and get answers from other members.

Join

tRPC & Next.js confused about error

Hey, I'm really new with next.js, react and trpc, I was trying to add tRPC into my small SSR next.js project to send data from the client to the server, following the tRPC Next.js examples is pretty tricky knowing close to nothing about it and I am getting a weird error. It doesn't tell me where it is, what file, I've tried mostly commenting out code from my page.tsx file and I still get the useState error? I'm not sure how to set up layout.tsx too... That's probably what I'm doing wrong but I don't know where to find out what is wrong layout.tsx ```tsx import type { Metadata } from "next";...
Solution:
For context, trpc does not officially support Nextjs App router. Instead of wrapping your component in trpc's HoC, you can create a client component provider and wrap your app with it. Look here https://github.com/trpc/trpc/issues/3297#issuecomment-1423905894...
No description

Next's app router is slow when using server components, how to optimize?

it takes about 3-4s to redirect to another page that fetches data using server caller, how to solve this?

CORS Preflight did not succeed

I cannot seem to access my api endpoint but when I manually do it in the browser, it works. I attached images of the network tab and the code
Solution:
Fixed it by manually specifying each method instead of using ANY ..for context, I am using sst/ion for IaC...
No description

"Find all references" in VSCode not working

Node.js: 18.17.1 @trpc/server@10.45.2 @trpc/client@10.45.2 TypeScript: Version 4.7.4 ...

Bug? useSuspenseQuery -> isFetching doesn't change

Hi everyone! I'm trying to do users data table in nextjs via tRPC useSuspenseQuery. When I change input in useSuspenseQuery then new data fetch but test2.isFetching doesn't update at all. When I do test function that invalidate query then test2.isFetching is updating to true while data is fetching. ...

Questions around trpc with next.js app router

I have a few questions in wrapping my head around how to get it to work. Is withTRPC<AppRouter> still required? The docs show it: https://trpc.io/docs/v9/nextjs#5-configure-_apptsx but it looks like the example is around the pages router and not app router. I am using createTRPCNext<AppRouter> am I meant to use both createTRPCNext as well as withTRPC ? ...

Correct tRPC implementation (NextJS AppDir)

Hello ! I'm a little bit lost on the tRPC examples, especially on "examples-next-app-dir" When should I use this : https://github.com/trpc/examples-next-app-dir/blob/main/src/trpc/server-http.ts ...

how to import superjson in express?

"The current file is a CommonJS module..." I set module to Node16 and moduleResolution to NodeNext but still not working, any clue?...
No description

Is it possible to have more than one TRPC client (React Query)?

For example, if i have a multiple TRPC endpoints I want to communicate with

How to try a Post request?

TIL I can't use Postman to try Post requests due to how tRPC handles requests. What can I use? Is there a simple way? Is there a client similar to Postman with a tRCP extension? Thank you so much...

tRPC with Next Intl

I'm getting errors when use Next Intl with Trpc App Router When I call the route, the middleware from next intl change the route to set the locale first [en-es] and the 404 in the route. https://next-intl-docs.vercel.app/docs/routing/middleware...

Invalid response or stream interrupted

I get this error only on vercel. Everything works fine on my localhost. (Even build mode). Any suggestions of what should I do to fix it?...

Checking the connection status from the client side

I am doing nodejs to nodejs subscription, and I can't figure out how to check the connection status from the client side in both sse or ws approach so I can handle on disconnect.

Suddenly started getting a `TRPCClientError: Unexpected token '<', "<!DOCTYPE...` error

And my whole app can't run, I've been at it for the whole day. Using React Vite with the React Query integration

Is having multiple tRPC instances in a single monorepo package an anti pattern?

Hi there! We are currently refactoring a large monorepo and we are torn on deciding the best approach in terms of trpc. We used to have two monorepos we are now merging and it seems to make sense to now have a single package for trpc. ...

Can I use WebSocket with tRPC for the card game

I am going to create a card game using tRPC for getting the data from server to client. But, I was already using xmpp for user presence, multi-chat etc. But, now I want to try it out with the tRPC. Is it a better idea? Then, I might need to create a timed game / un-timed games, live streaming etc., based on the game. So, how will webSocket will help this with tRPC. What would be the good idea? Can you guide?...

How do I implement API key authorization along with JWT authorization in tRPC?

Hello, I want to make some routes protected and to be accessed by either JWT auth or by API keys auth. So I check both auth methods in the same context. To make things clear i will just share the code of my context: ```ts...

How to check websocket is alive from client?

Hi, I am new to trpc, might I know how can I check the websocket connection is alive from client side? (I am doing node to node call) I tried to subscribe from the client and then close the server, but there is no error or something I can tell the user the connection is dead....

Call and await multiple mutations within one clientside procedure

hey all, does anyone know of a nice way to call & await multiple tRPC requests inside a procedure or within one mutation? reason being is i'm building a blockchain app, and we have to implement flows like this: ``` 1. trigger a mutation on our server, recieve back data for a blockchain transaction...
Solution:
looks like i can do this after all with the mutateAsync return type!

Attempted import error: 'hashQueryKey'

./node_modules/@trpc/react-query/dist/createHooksInternal-063195fc.mjs
Attempted import error: 'hashQueryKey' is not exported from '@tanstack/react-query' (imported as 'hashQueryKey').
./node_modules/@trpc/react-query/dist/createHooksInternal-063195fc.mjs
Attempted import error: 'hashQueryKey' is not exported from '@tanstack/react-query' (imported as 'hashQueryKey').
```json...