How does trpc subscription actively close/disconnect in the server?
How do I actively disconnect my subscription?
8 Replies
I believe you have to just unmount the component that uses
useSubscription
but it's a good question if you're not using react.there seem to be an unsubscribe method on the subscription returned value.
The problem arises on the back end.
I don't seem to be able to actively cancel useSubscription in react either?
I'm not sure, but in my experience I found it closing the connection whenever the component unmounts.
you can use
broadcastReconnectNotification()
to tell all clients to disconnect and reconnect gracefullyGitHub
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.
you can use
ws
to loop through connected clients and force shut themI am implementing the SSE based subscription feature and I am currently finding issues with not receiving events from client closures in NextJS.