青木
青木14mo ago

How does trpc subscription actively close/disconnect in the server?

How do I actively disconnect my subscription?
8 Replies
Ahmed Eid
Ahmed Eid14mo ago
I believe you have to just unmount the component that uses useSubscription but it's a good question if you're not using react.
Ahmed Eid
Ahmed Eid14mo ago
there seem to be an unsubscribe method on the subscription returned value.
青木
青木14mo ago
The problem arises on the back end. I don't seem to be able to actively cancel useSubscription in react either?
Ahmed Eid
Ahmed Eid14mo ago
I'm not sure, but in my experience I found it closing the connection whenever the component unmounts.
Alex / KATT 🐱
Alex / KATT 🐱14mo ago
you can use broadcastReconnectNotification() to tell all clients to disconnect and reconnect gracefully
Alex / KATT 🐱
Alex / KATT 🐱14mo ago
GitHub
examples-next-prisma-websockets-starter/prodServer.ts at ba462445a1...
🏓 tRPC Next.js WebSocket Starter. Contribute to trpc/examples-next-prisma-websockets-starter development by creating an account on GitHub.
Alex / KATT 🐱
Alex / KATT 🐱14mo ago
you can use ws to loop through connected clients and force shut them
青木
青木14mo ago
I am implementing the SSE based subscription feature and I am currently finding issues with not receiving events from client closures in NextJS.
More Posts
child router questionlet's say we have a monorepo, one server, two client apps (cat and dog). we make one appRouter, likHow to force SSL on projects using tRPC?Hello everyone, I'm working on a project that uses create-t3-app as boilerplate. My project is hosAWS Lambda / How to set Cookies inside ProceduresHow can I set and remove cookies similar to ctx.res.cookie(..) with Express when using the aws lambdMassive Type Errors on tRPC 10 Legacy Router against MergeRouterWe're trying to upgrade to tRPC 10 but I am running into a massive type clash when trying to merge rIs it possible to create 2 routers inside a single file?I am having an issue in which it is impossible to me to use a class instance within 2 routers. I triUse onError to change an application error into a TRPCError?I want to use the onError handler to change any instance of a custom application error into a TRPCErIncreasing Body 1mb limitHey, Im trying to build an application that allows sending of base64 encoded files to my next.js serNitro and tRPC in vercel-edgeHey there! I hope this is the right place to ask for help. I am trying to deploy an application witHow to retrieve and receive Bigint data to/from TRPC procedureNode: `v16.15.1` I'm trying to return an object which contains an `amount` property from one of my TypeError: Cannot read properties of null (reading 'useContext') when using useMutation with TRPC inI'm encountering an error in my Next.js application when trying to use the useMutation hook with TRP