tRPC

T

tRPC

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

Join

Router type = any in monorepo...

Using typescript 5.8.2, trpc 11.0.0-rc.688 I have my server and frontend in separate packages, and when importing the AppRouter (import type { AppRouter } from 'api') , the type of AppRouter is any :/. I've followed all the steps from the FAQ, but to no avail....
Solution:
SOLVED!! The problem was the use of path aliases in the api. I changed an import ... from "@/..." to import ... from "../..." and it started working....

Creating Service Layer in Next App Router

I have a NextJS application that was built with the t3 stack a few years ago on the pages router. I am finally getting around to migrating to the app router and am running into some confusion. TLDR: I would like to build a service layer (basically just a set of functions) to call trpc endpoints that can be reused/called from both my server and client components. I followed the "Set up with React Server Components" on the trpc v11 docs, and it looks like there are essentially 2 "instances" of trpc that are created, 1 for client components and 1 for server components (trpc/client.tsx and trpc/server.tsx, respectively). Since each of these has a unique way of interacting with the trpc endpoint, and the server.tsx file is "server-only" and cant be used in my client components, I'm not sure how I can go about making a service layer that is reused between client and server components. My existing service layer handled the trpc call as well as other conversions to FE models, so I would really like to avoid duplicating this work from client and server components if possible. Does anyone know how I can achieve this?...

Stream closed, but it returns the actual data

So I have this procedure that simply returns a list of objects from db: ```js getAllHabits: protectedProcedure.query(({ ctx }) => { if (!ctx.session.user.id) return []; // return []...

Cannot set headers after they are sent to the client

I have used login system from this repo https://github.com/itsrakeshhq/finance-tracker/tree/main/backend/src/modules/auth but reworked it to tRPC v11 (11.0.0-rc.824). I changed nothing regarding logic, only stuff regarding new version of tRPC and also i am using tRPC standalone not express. Now I have issue when i try to set cookies in authRouter.login ``` const authRouter = router({ login: publicProcedure...

I'm trying to get type for queries/mutations returned from trpc use hooks, but they are different

Hello, can anyone tell me please how I can get rid of ts errors when trying to accomplish what I mentioned in title? I tried asserting as types from context from screen 1, but it throws errors too...
Solution:
This is how I did it: ```tsx import { AppRouter } from "../router" import { TRPCClientErrorLike } from "@trpc/client" import { UseTRPCQueryResult } from "@trpc/react-query/shared"...
No description

tRPC useQuery waits for all queries—How to render ASAP?

I have a dashboard with multiple components, each making its own useQuery call. The problem: It waits for all queries to load before rendering anything, instead of displaying data as soon as it's ready. 🔹 Setup: - trpc.createClient with httpBatchLink...
Solution:
Ok I found the solution, I switched to « httpLink » instead of « httpBatchLink » in my trpc client

File based structuring, trpc layout

Hi! I totally love trpc, only thing is that I want/need it to be file based. Think of svelte, each path has its own file. Was wondering if there is already something out there that does about the same, or if its even possible. So the layout: Each folder is its own router and each file is its procedure...

How to wrap response type with useAsyncData from Nuxt?

I'm using the vanilla client with Nuxt currently but it's a little tedious calling useAsyncData(() => client.someProcedure.query()) on every call so that I don't double fetch during SSR. Is there a way to make a wrapper client that will wrap query and mutation responses with the useAsyncData() call? I would love if the client was typed and I could call it the same way I can call the vanilla client.

How to define per route staleTime on queryClient?

It looks like I am unable to override the default stale time provided to react query client, no matter how I define the the route. Is TRPC overriting these dafult somewhere down the chain? ```typescript export const createQueryClient = () => { const queryClient = new QueryClient({...

Can i use a single trpc proxy client in NextJS 12?

Hey guys quick question if anyone is around. Are there any issues with defining a trpc proxy client once in nextjs pages router and then reusing it in client components by manually passing it to a useQuery? Unfortunately our backend team has created multiple trpc routers and we still haven't upgraded from react-router v3, so the trpc-react-query integration isn't a high priority for us, but will there be any caching or request sharing issues when using a single trpc proxy client? ```ts // define this once in src/trpc.ts export const trpc = createTRPCProxyClient<AppRouter>({...

[Typescript] Client query/mutate has any type

So, apparently AppRouter type has all info about existent queries/mutations, but shows <any> for input and Promise<any> for output of query/mutation. How to fix it ?...
Solution:
My problem lies in my project's monorepo architecture and reexporting schemas within monorepo and then infering types with zod
No description

Trpc V11 Nuxt 4

Hello, I was wondering if theres a possibility to have a trpc v11 example repo maybe on the examples page since the trpc-nuxt module is not really maintained. Also I think a module is not really nessesary with v11? Thanks in advance!...

server side prefetch + optional client side refetch

Hello, I'm looking for advice on a pattern for server-side prefetching with optional client-side refreshing in Next.js. Current setup:...

[Help] Fastify session http only cookie differs

Solution:
The problem is probably with fastify/fastify session plugin. fastify.register(session, { secret: "supersecret1234567890supersecret1234567890", // Use a strong secret here for production. ...

126 routers | TS7056: inferred type node exceeds - Multiple Providers?

Hello hope you are all well. quick info: env: node 20, pnpm, trpc^11.0.0-rc.466, monorepo. Everything in my monorepo is built/typescript declarations (otherwise autocomplete is a snail). I have 126 routers (didn't realise it was so much)...

How to get cursor in new Tanstack Query integration?

How can I access the cursor (or pageParam) in the new infiniteQueryOptions function? The current procedure input takes a cursor but I'm getting and error saying cursor is not passed to infiniteQueryOptions, and I can't pass it manually as it is calculated using getNextPageParam.

monorepo can't resolve trpc context

I'm usig a mono repo with next15 and trpc v11 + pnpm. I can't seem to share the trpc across the monorepo for some reason. What is weird is that the dev server runs it well but the build can't seem to find the useContext from the trpc. Says it collides with something. Type error: Property 'Provider' does not exist on type '"The property 'useContext' in your router collides with a built-in method, rename this router or procedure on your backend." | "The property 'useUtils' in your router collides with a built-in method, rename this router or procedure on your backend." | "The property 'Provider' in your router collides with a built-in ...'. Does anyone have a decent idea or a suggested setup for express backend, nextjs front, and trpc 11? I want a mono so that I can share a lot betyween them + share hooks with future projects. I want express so that I can scale them in AWS. and next pushed through AWS amplify. That's the current idea ayways. This is my experimental project where the dev works but the build fails. This is killing me for over a week now.
https://github.com/dsmurl/an-express-next...

Catch the error on trycatch and show the message

Hello, I am throwing a TRPCError inside my procedure ```js throw new TRPCError({ code: "BAD_REQUEST",...

operation input is formdata but trpc makes it an application/json POST call

operation: ``` { "type": "mutation", "path": "vectleProfiles.updateProfileLogo",...

v11 with tanstack mutation not invalidate query

When the mutation is successful and the router switches to the dashboard, sometimes the data refreshes, but other times it does not. However, if I press Alt + Tab, the data refreshes.
No description