-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
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")
Screen.Recording.2025-11-22.at.12.10.41.AM.mov
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