tRPC

T

tRPC

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

Join

When a procedure returns an instance of a class, the superjson isApplicable doesnt detect it

When a procedure returns an instance of a class, the superjson isApplicable doesnt detect it as that class, but when you return it inside an object or array, it does. ```ts // ❌ class Test { a: string;...

Validating inputs and outputs only via typescript

Hey everyone, I am trying to create an appRouter with ts-morph but I am having trouble with passing the zod schema/object instance to it (since I need to pass the original implementation, not the instance). I was thinking about a way to work around this and was wondering if I could somehow just pass the zod typescript type in the inputs and outputs - keep in mind that my usecase only calls for the type definitions to work, not the actual implementation. ```ts...

Zod error not being formatted

I'm using Zod for validation and whenever I get a validation error I'd like to be able to get the error message properly formatted. In the docs there's a section for this where it's sepcified that we can use the errorFormatter to achieve this. However, it's not doing anything at all. Btw, if I add a console.log within the errorFormatter nothing's being shown in the console, which is kind of weird if you ask me. However superjson is working completely fine, so I dont think its a configuration problem.... Here's my code ```...

AppRouter type is imported as any

I have a monorepo and everything else from the server is imported correctly except for this specific type. Aliases do not work, importing directly from the file does not work. Any hints? I do not want to use project references.

v10 useQueries does not return a stable reference

I though this code would work downstream for memos and callbacks, but it does not. The memo and effect are re-ran every render. Have I don't something stupid, here or is this intended? How would I memoize a derives values from the results? This code:...

strange behaviour with t3 trpc starter

I had copied the provided create-post component and created a duplicate create-video component, exact same just different db table. https://github.com/rverma-dev/t3-app-bug/commit/d08f1ca79e3dcbba6033b477308a14b7ee530536. However the page gets rendered and immediately it error out Error: ❌ Attempted to access a server-side environment variable on the client. Kind of looking at it for last 4-5 hours but no luck at all. The code is exact same as of create-post but don't work....

Websocket connects even without any subscriptions

Currently, when I add a WS link, it tries to connect to the server right away. How can I prevent this behavior and allow it to connect only if there are any active subscriptions? Unlogged users don't have subscriptions, so they should not connect to WS server

calling tRPC procedures from a function (e.g. a cron on vercel)?

Hey everyone, I am using nextjs App router together with tRPC and it's working super well so far! I would like to call tRPC procedures periodically (like once per month with a cron job) and also from a function (e.g. user submits a form, once it's sucessfully submitted, I wait 5 seconds and then call a mutate procedure that updates stuff in my DB)....

How to serialize and deserialize an object of a custom class?

I have a custom class and i want to send objects of it over trpc, but the serialization is not working properly. The date fields are being converted to strings.

Header caching

Hello all, I am sending an authorizaton token ```js export const TRPCProvider: React.FC<{...

You must define a transformer on your your `initTRPC`-object first

Hey, getting an odd error, pretty much booted up a ct3a stock application, and getting these errors. When there seemingly IS the transformer on the init trpc object... I think that ct3a is using the v11 release candidate, so i dont know if there is anything breaking in there? Any help is appreciated!...
Solution:
I had messed around with tsconfig and turned off strict mode. Apparently this is a no go. When i turned it back on, the issue was solved.
No description

trpc + unstable_cache (Next)

What is the recommended way to work with trpc + unstable_cache? For now I am creating functions wrapped inside unstable_cache and call procedures inside this function. Is there any easier way?

How to set up custom response headers at procedure level

hello guys, i'd like to know how to set up custom headers per procedure. I am aware of the responseMeta, but thats general. I'd like something more fine-grained. Something like this but doesnt work: ```ts...

Subscription example not behaving like it should

Hey, I've recently wanted to make a subscription route and I've stumbled upon a problem. In the documentation it's said that you should return an observable with a callback that is triggered immediately. That however is not happening. I don't know if I don't understand this correctly of if the example is broken. I'm using bun@1.1.10 with @trpc/server@11.0.0-rc.396. ```ts...
Solution:
Okay I get it now, in my actual project I was using httpBatchLink and wsLink together insead of splitting them using splitLink that's why the subscription wasn't going off. ```ts export const api = createTRPCClient<AppRouter & WebSocketRouter>({ links: [...

nodeHTTPHandler with Nitro

I'm trying to setup trpc with nitro.unjs.io using the node-httpadapter. ```ts import { nodeHTTPRequestHandler } from "@trpc/server/adapters/node-http"; import { appRouter } from "~/lib/trpc/router";...
Solution:
Nvm, it seems to work like this. Have to return the correct response of course (which revealed another error with the path). ```ts export default defineEventHandler(async (event) => { console.log('trpc route handler');...

Cookies not being passed on to client

Hi all, I can't tell if I'm simply trying to wrangle TRPC into doing something it's not designed to do, or if I'm just doing it wrong. I'm using trpc to proxy our auth server, something like: ``` .mutation(async ({ input }) => {...

Does the fastify adapter support content-type multipart formdata on v11?

I saw that recently formdata support was merged in, and i was interested if the fastify adapter supports it and does it need @fastify/multipart?

NextJs Setup: `useContext is not a function`

Env: Bun 1.1.10 This morning I started following this guide to setup tRPC in my existing NextJs project https://trpc.io/docs/client/nextjs/setup ...
No description

TRPC response data changing to undefined when typing in a form field.

Hello, I'm currently having a very strange issue, I am using a form to input some data and send off to a trpc endpoint to retrieve some data from the server when I click the submit button. However, the respnose userData variable is being changed to undefined whenever I type into the form field. I am not sure why this is happening as I do not mutate userData anywhere, and there are no new TRPC queries running (verified checking network tab) and the TRPC endpoint is set to disabled. So it will only fetch data once I call the refetch function... Anyone have any idea?...
Next