青木
青木2y ago

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

How do I actively disconnect my subscription?
8 Replies
Ahmed Eid
Ahmed Eid2y 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 Eid2y ago
there seem to be an unsubscribe method on the subscription returned value.
青木
青木OP2y 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 Eid2y ago
I'm not sure, but in my experience I found it closing the connection whenever the component unmounts.
Alex / KATT 🐱
you can use broadcastReconnectNotification() to tell all clients to disconnect and reconnect gracefully
Alex / KATT 🐱
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 🐱
you can use ws to loop through connected clients and force shut them
青木
青木OP2y ago
I am implementing the SSE based subscription feature and I am currently finding issues with not receiving events from client closures in NextJS.