-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: resubscribe on reconnect #2783
Conversation
Initial POC of how reconnecting could work, likely has some bad side-effects though
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
fixed up linting and trying to sneak in a minor TS change here https://github.com/trpc/trpc/pull/2783/files#diff-d5eb300ee573b9c1ced9ca84f2cb9be7746b78404935ac11c96c3bfa7d42a205R47 I would like to have access to this type in my plugin, so can we kindly export it :) |
I think we are trying to keep these sort of types (I.e types needed for plugins and shouldn't necessarily be used in apps) exported from /shared (but maybe /integrations) would be a better name 🤔 |
@juliusmarminge While you're considering that I wonder if you all would be up for bringing these types over from my composable project into tRPC proper? They let you flatten a router into a dot notation string and then get procedure info back from the flatten version like This lets other implementations reference procedures my a single string but also keep type safety and auto-complete. Maybe the naming is slightly wrong as its called |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good to me and I'm happy no existing tests fail, but I would like some tests to proves the new behavior is correct
It'd go in here: https://github.com/trpc/trpc/blob/next/packages/server/test/interop/websockets.test.ts
(We haven't fully migrated all tests to v10 but thanks to interop we can still test the behavior)
Hey all bringing my thoughts over from discord to work through here. The focus now is not only getting resubscribe to work but to clean up the As James mentioned
So technically I think a subscription could be completed and stopped. Though it does seem fair to say if a subscription is completed, it should just be unsubscribed automatically anyway. Right now completed and stopped are mixed into a few things. Particularly when it comes to errors and disconnects. Also since disconnecting is mixed up in this we cannot count on the server to push state to the client. So both need to be aware of these concepts. So this is how I could see it playing out. Client side subscribe -> For non-intentional disconnects the client will retry connecting, once reconnected is will subscribe again -> That seems to separate start/stop and complete as complete is now only an indication that the observable has no more data. However I could also see an argument that a subscription is just a single observable anyway so in the case of unsubscribe, disconnect, or complete it is always just a Perhaps someone is using this observable like a timer, they are going to Let me know your thoughts, we can get this all cleared up. also for the record there is a websocket test alright to test disconnect and reconnect/resubscribe. It was just marked |
@jlalmes, have you had a chance to look at this yet? :) |
Where would be the best place to throw money to get this resolved? 🤑 |
@KATT no worries on that, but thanks for the offer! Happy to help this project get better. Where is this now? Does it need testing or we all good to go? Also from that long comment I had above, where did this land? What are the expected results for all the different |
I'll merge it. The tests are pretty extensive so pretty sure it doesn't break any existing behavior.
|
Co-authored-by: Alex / KATT <alexander@n1s.se>
Initial POC of how reconnecting could work, likely has some bad side-effects though
Closes #2776
🎯 Changes
First we don't queue a subscription.stop if we are not connected to the socket. If it is queued this line here https://github.com/trpc/trpc/blob/next/packages/client/src/links/wsLink.ts#L124 will keep the request to subscribe from being sent as they both share the same id
Second we prevent the error callback if we have not closed "normally". This will prevent this method from being called here https://github.com/trpc/trpc/blob/next/packages/client/src/links/wsLink.ts#L319 which keep things from being unsubscribed while the socket tried to reconnect.
What changes are made in this PR? Is it a feature or a bug fix?
✅ Checklist