Optimistic update reverting back to cache
I have a custom hook I'm using to POST todos and also edit them.
One issue that I'm currently facing is that when I make an edit. The request
goes through successfully, but when the data is invalidated
onSettled function
it will make a fetch request to the disk cache instead of server and that returns previous data.
So what that looks like is you make an edit to a todo and 2 seconds after, it is reverted back to the previous value.
After 1 minute, you get to finally see the updated todo.
For now the current fix we have is to set this 👇🏽code in the axios header to prevent it from fetching from
disk cache and get updated data from the server.
My question is: how can I prevent this revert issue. Is there another way around this instead of the cache-control header6 Replies
flat-fuchsia•3y ago
What's the question here 😅?
sunny-greenOP•3y ago
@TkDodo 🔮 The question is how can I prevent this revert issue. Is there another way around this instead of the cache-control header
flat-fuchsia•3y ago
I'm unsure what this has to do with react-query. If the request is visible in the network tab, our job is done. RQ doesn't do data fetching...
So you'd probably have the same issue without it
sunny-greenOP•3y ago
@TkDodo 🔮 When data is invalidated, it is fetched through a useQuery hook I set up
flat-fuchsia•3y ago
So? If the request made and the backend (or browser cache) returns old data, what should RQ do about it?
sunny-greenOP•3y ago
@TkDodo 🔮 I'm not trying to imply that there is something wrong with RQ.🙂
Wanted to know if someone else/or you have come across this similar issue and how they were able to solve it.
The specific issue being that on certain mutations, the request will go through but after invalidating (onSettled)
the is data fetched from disk cache and it's the previous data even though an optimistic update was made.
If I'm asking the question in the wrong place, please let me know. I'm quite new to the server.