Unable to update previous query cache #5628
-
Describe the bugHi team, Your minimal, reproducible examplesee above Steps to reproducesee above Expected behaviorIf the query is still fresh, the value of the updated item should be the same in all the How often does this bug happen?Every time Screenshots or VideosNo response Platform
Tanstack Query adaptervue-query TanStack Query versionv4.29.15 TypeScript versionv5.1.3 Additional contextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
do you have all variables like the status filter added to the QueryKey? I mean, you're not even showing any code... |
Beta Was this translation helpful? Give feedback.
-
Yes, of course, I have
Then we use that filter above to query the API
You just only care about the Step by step:
Because the stale time in the query key that we made in Step 1, does not expire, I got an unwanted result in the final step. |
Beta Was this translation helpful? Give feedback.
well what did you do in the optimistic update?
sorry, this back and forth is pointless and exhausting, and it's usually the reason why I require a runnable codesandbox reproduction to investigate issues.
Conceptually, here is what happens:
React Query has a document cache (not a normalized cache); it's an in-memory JS map where the key is the QueryKey. If you change the key, you create a separate entry in the Cache.
That means, if you have 3 filters, and you switch between the three, you have three cache entries, each having their own data. With filters, that means you'll likely have duplicate data in the various cache entries (which is fine, that's how it's designed to work).
If you now …