tRPC

T

tRPC

Move Fast & Break Nothing. End-to-end typesafe APIs made easy.

Join

Keep subscription `.data` after stopping (Tanstack Query)

It looks like mySubscription.data is undefined after the subscription stops from the server side (returning from generator function). Can I keep this data without introducing my own useState and leverage Tanstack Query instead? I'm using the old React Query integration because there's no documentation for the new integration for subscriptions (i.e. useSubscription(trpc.mySub.useOptions()) )....

How to compress procedure response

I have one trpc procedure which has 40 mb response. I would like to compress this. How can I compress one procedure call in trpc. Or even better have compression for all trpc procedures above some threshold. Is it possible or I have to create separate api endpoint out of trpc context. I’m using nextjs with custom express server....

Next js Pages Router, TRPC

Has anyone succesfully set up next js pages router and trpc?

A cleaner web experience for this forum

Hey! I saw this forum uses AnswerOverflow to sync Discord threads to the web. I’m building Paladin, a smoother, cleaner alternative that makes Discord forums easier to browse on the web. It’s free to use and can run alongside AnswerOverflow, so you don’t have to switch anything to try it out. If it’s helpful, I can spin up a version of Paladin on your forum so you can see how it looks for your community. Is there anything about your current setup you’d like improved? I’d love to see if Paladin can help. 😀 Example Paladin preview attached...
No description

useInfiniteQuery: `hasNextPage` does not seem to consider fewer-results-received-than-`limit`-given

What's the recommended practice for hasNextPage to correctly be false when the records received were more than 0 but fewer than the limit prop (that's next to the cursor prop at the endpoint)? To clarify the problem to solve: right now my limit is 11 and queries with 0 results correctly result in a hasNextPage of false, but queries with 1 or 2 results seem to have it true. How do y'all typically tackle this subtlety?...

BUG: useSuspenseQuery does not forward TRPC options to context

When using useSuspenseQuery, the TRPC options are not forwarded to the context: export const createTRPCContext = cache( async (opts?: FetchCreateContextFnOptions) => { // opts is undefined when called from a useSuspenseQuery...

Recommended setup for tRPC + Tanstack Query Subscriptions

Hey there, I am already aware that there is a package for this: import { useSubscription } from "@trpc/tanstack-react-query";...

creating middleware with context type as param

i'm looking into build a "post operation" function into separate piece of code. i know it may be done differently but i'm looking into it for code structure purpose. the goal of the middleware is to accept a function which takes the current context as input, as well as the result from the handler, and execute code. ```ts import type { MiddlewareResult } from '@trpc/server' import { initTRPC } from '@trpc/server'...

How to handle 500s from prefetching

I'm using nextjs app router. I'm having an issue where I prefetch using something like the following in a server component: Server ``` void trpc.projects.getProject.prefetch({...
No description

Usage of trpc with nextjs ssg

Hi, I'm trying to use TRPC with next app router SSG. Specifcially I want to have blog page that is statically generated, but I also need to handle cookies and headers on different API routes. How should I go about this when creating contexts and routers?...

best strategy for handling global trpc errors on the client

I’m using trpc in my nextjs app. In one of my procedures, I check if a server is banned. If it is, I throw a TRPCError with code FORBIDDEN and a custom message: ```ts const guildIsBanned = await ctx.db.guildBotBans.findFirst({ where: { guildId: input.guildId }, });...

Debug httpBatchStreamLink in DevTools

I'm not super familiar with chunked, but it seems to me like Chrome (in my case) won't store the result of the request to be shown in the Network tab in devtools. This is making debugging very painful. Can I do anything about this while still being able to stream the response?...
No description

TS error regarding inferred type of 'appRouter'

Hey there, I've been running into this issue with my turborepo. I have an api (hono) backend and a nextjs frontend and both rely on tRPC in order to function/make calls. I believe this is an issue with trpc/server and zod? But honestly everything I find online isn't quite right. I have a pretty standard setup that I think I have used before with no issues. I use Zod in multiple places in my repo but I make sure that they are all the same version. I'm not 100% sure of which code to show so please do ask for anything you need to see in the comments....

Shorten /app/api/trpc/[trpc]/route.ts

The docs suggest /app/api/trpc/[trpc]/route.ts to register the tRPC handler in a Next.js project. Can I shorten this to e.g. /app/api/route.ts? If yes, what's the endpoint that I need to pass to fetchRequestHandler and what's the url I need to pass to httpBatchLink?...

Stream error polluting sentry - only on Safari

Hi we are using TRPC subscriptions for streaming the LLM response. We've started seeing on error on sentry related to AbortError abort pipeTo from signal. This errors only happens on safari <16.4, so it matches the chat gpt explanation. ...
No description

Setting up tRPC without breaking Frontend's typechecking

Hello everyone, I would like to better understand how I can setup my project correctly. Right now I'm using Fastify with tRPC. My frontend is a React Native app. Both live in a monorepo using yarn workspaces. I'm exporting my tRPC types like this:...

Invalidate all queries in new TanStack React Query Setup

Hey, I set up the new tRPC flow for Next.js using TanStack React Query from docs: https://trpc.io/docs/client/tanstack-react-query/setup How can I add to it, previously implemented and documented (https://trpc.io/docs/client/react/useUtils#invalidate-full-cache-on-every-mutation ) queries invalidation on every mutation in app? We don't use the createTRPCReact anymore and I can't seem to find any other method from the docs where I can pass these overrides :x Thanks!...

hono, next.js ssr & better-auth cookies

hey guys, I am currently trying to use Better Auth with tRPC server side with a hono backend. In my backend, I am checking for the session like this: const session = await auth.api.getSession({ headers: c.req.raw.headers }); in my trpc batchLink, I just tried to put headers like this:...

Deduplicating identical queries in tRPC httpBatchLink (standalone server + Next.js server-side)

Hey folks, I'm running into an issue with tRPC v11 where my standalone tRPC server is called from Next.js 15 server-side using a tRPCProxyClient with httpBatchLink. Batching works great for multiple different procedures, but if the same procedure with identical inputs is called multiple times in the same request (e.g., from nested components), it gets batched but not deduplicated—meaning the server still processes and responds to duplicates, which is inefficient. Right now, I've got a simple (kinda dumb) workaround: wrapping individual procedure calls in React's cache like this: ```ts const api = /* my tRPCProxyClient with httpBatchLink */;...
Next