Hi folks, I have a situation where I am rendering messages to the chat. Messages are the array of objects with all relevant data.
I use an optimistic update (with mutation) when the user sends the message. onMutate: I am updating the "MESSAGES" cache and its msgStatus to 'pending', onSuccess changes its status to 'success'.
When a message fails to send (mutation) I am setting its status to msgStatus: 'error' in the onError function and I render a "retry" small button beside the message.
I have "refetchOnWindowFocus: true" for updating the messages and it overrides the cache and deletes the last saved message with the "msgStatus: error". I tried to set the select function and I try to get the "MESSAGES" snapshot and merge it with the data but it is not working. It still deletes the error message somehow.
I want to preserve that error message in the messages list in the cache until the user succeeds to send it but I want to refresh the data with refetchOnWindowFocus while keeping the error message with retry button at the end of the list in the chat.
Is there a way to make this work? Any suggestion would help. I suppose that the "onSuccess" function runs after the cache is updated and the "select" function runs before? I am using the same cache for storing the messages and onMutate updates that cache.