Repository navigation
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
@BeBoRE is attempting to deploy a commit to the trpc Team on Vercel. A member of the Team first needs to authorize it. |
| }, | ||
| onData: (data) => { | ||
| if (!isStopped) { | ||
| setSubscriptionState((prev) => ({ |
There was a problem hiding this comment.
I'm not sure we wanna update data for every event - it can become incredibly expensive for high throughput events, likely better to force developers to handle data themselves
There was a problem hiding this comment.
If we update data of every event, we need to have a smart handler that won't update data unless it's used - not looked at the magic that RQ does for that
There was a problem hiding this comment.
I probably agree, I'll reconsider, removing it for now
There was a problem hiding this comment.
Re-added this :) now only rerenders if that property is watched
|
I have a few points to think on:
|
|
I changed the result type of the hook, to reflect how I think the hook should work. It's loosely based on TanStack Query, I added comments explaining what the properties should reflect. I personally dislike the error state since it's very ambigious in this context, failed is less ambigious since it tells you that the subscription has completely failed, which is what I believe error would indicate. I have added a restart callback. My idea is that this can be called at any time, even while the subscription is not stopped. A 'retry' callback would imply that it can only be called on failure, or would this be more desired? |
|
I extended the wsLink with the new connection state events, very crudely needs a lot more testing. It seems that when using WebSockets the browser doesn't recognize connection issues for a long time. The starting connecting state and pending state work quite well however. |
|
I believe the only thing missing now are tests, unless there needs to be more changes to the specifications. |
|
This pull request has been locked because we are very unlikely to see comments on closed issues. If you think, this PR is still necessary, create a new one with the same branch. Thank you. |
Closes #5871
Closes #5786
🎯 Changes
What changes are made in this PR? Is it a feature or a bug fix?
Lets useSubscription return a result containing the state of the connection, most recently received data (useful for myself), and utilities to better recover from errors.
✅ Checklist
📋 Tasks