-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Remove use left convos #7874
base: main
Are you sure you want to change the base?
Remove use left convos #7874
Conversation
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.
Calling out two other minor changes I've made. If the context you have suggests there bad for some reason I don't know about, you can revert them.
onMutate, | ||
onError, | ||
}: { | ||
onMutate?: () => void | ||
onSuccess?: (data: ChatBskyConvoLeaveConvo.OutputSchema) => void |
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.
Didn't see this option being used at all. Easy enough to add back in if you need it.
onSettled: () => { | ||
queryClient.invalidateQueries({queryKey: CONVO_LIST_KEY}) | ||
}, |
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.
onSettled
is called regardless of success.
c5558a0
to
25e35cf
Compare
@@ -42,7 +36,8 @@ export function useLeaveConvo( | |||
|
|||
return data | |||
}, | |||
onMutate: () => { | |||
onMutate: async () => { | |||
await queryClient.cancelQueries({queryKey: CONVO_LIST_KEY}) |
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.
Follow on from comments in the Tanstack discord made by @mozzius about
useMutationState
. I've attempted to give a more "straightforward" answer over there, but I'm doing this pr to tackle the problem hereMy understanding of the issue
I may be horrifically wrong here, but this is what my current reading of the code entails.
If a user leaves and re-joins the convo, the leave convo mutation is still filtering out the convo they just re-joined, and
useLeftConvos
will still have the successful mutation in the cache, filtering out the convo they just rejoined (this is probably the part I'm most unsure of lol). Hence the need to remove the mutation from the mutation cache, which is somewhat non-trivial.A modest proposal
However, it looks like
useLeaveConvo
is already using the cache optimistic update pattern described here: https://tanstack.com/query/latest/docs/framework/react/guides/optimistic-updates#via-the-cache . Tanstack docs only say to use either the UI or the cache approach, and hence I think we can just deleteuseLeftConvos
entirely and we'll be fine anyway.And that's what the PR does.
We also are disabling
useListConvosQuery
if there are any pending leave convos mutations in flight so that the optimistic updates will not be overwritten (and the convo flashes up again briefly). This was apparently most of the motivation behinduseLeftConvos
in the first place; it makes sense to move that mutation monitoring into the query hook instead.(I've might have another solution as well if you really need to hold on toActually I won't make a pr, might comment on it back in the discord.useLeftConvos
, will make an alternative pr.)Testing
Leave conversations and rejoin them with the same people. Only tested the happy path so far; chat with the local backend doesn't seem great to set up.