Skip to content
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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

DogPawHat
Copy link

@DogPawHat DogPawHat commented Mar 1, 2025

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 here

My 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 delete useLeftConvos 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 behind useLeftConvos 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 to useLeftConvos, will make an alternative pr.) Actually I won't make a pr, might comment on it back in the discord.

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.

Copy link
Author

@DogPawHat DogPawHat left a 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
Copy link
Author

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.

Comment on lines 80 to 83
onSettled: () => {
queryClient.invalidateQueries({queryKey: CONVO_LIST_KEY})
},
Copy link
Author

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.

@DogPawHat DogPawHat force-pushed the remove-left-todos branch from c5558a0 to 25e35cf Compare March 3, 2025 21:03
@@ -42,7 +36,8 @@ export function useLeaveConvo(

return data
},
onMutate: () => {
onMutate: async () => {
await queryClient.cancelQueries({queryKey: CONVO_LIST_KEY})
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@estrattonbailey estrattonbailey requested a review from mozzius March 4, 2025 02:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant