Optimistic update doesn't get undone when using `data` if offline
I'm experiencing an issue where optimistic updates don't seem to get "undone" (by using patchResult.undo()) when using data from the query hook if my computer is offline (eg: when I set my connection to "offline" in Chrome devtools for testing purposes).
If I use currentData from the query hook instead, undoing of optimistic updates works as expected when my computer is "offline".
Optimistic updates get undone as expected regardless of if I use data or currentData if my Chrome devtools are not set to "offline".
The reason I set my devtools to "offline" was to quickly simulate a failed mutation when testing my application.
Guesses On What's Going On
I believe RTKQ can keep track of whether user is "offline" are not (for features like refetchOnReconnect). Maybe there is something weird going on in particular when RTK is in this "user offline detected" state.
Chrome's "offline" mode screws with the websocket that Next/React uses when in development mode (for things like hot reload). I thought that could be part of the problem but tried running a production build of the application (built with next build) and the issue was still present.
Video Screenshot (first part: shows currentData undo working when offline, second part: shows data undo not working when "offline")
https://github.com/user-attachments/assets/d41668c6-a13a-4e30-b2ab-ede3a19f7602
Minimal Reproduction
Unfortunately, the endpoint in my example with a working mutation endpoint is authenticated. My example is nearly identical to the official optimistic update example though.
https://github.com/agusterodin/rtkq-playground/tree/optimistic-update-polling-race-condition
Does it look like a patch action is getting dispatched for the undo step? Do the Redux DevTools show anything relevant?
It appears that the patch is getting dispatched for the undo step. Inside the "RTK Query" panel in devtools, the correct value is being shown (patch is correctly undone) in the store.
The data being returned by the query hook doesn't match what's in the store (the correctly "undone" value).
Getting rid of invalidateTags on the mutation seems to make the issue disappear (with the obvious drawback that cache invalidation no longer occurs).