Caching behavior across different pages #8141
Unanswered
hosseint79
asked this question in
Q&A
Replies: 1 comment 2 replies
-
sounds related: but hard to say without seeing a reproduction |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Describe the bug
I am using Next.js with React Query and have encountered an issue with query caching behavior across different pages.
Your minimal, reproducible example
haven't
Steps to reproduce
I have two pages: page1 and page2.
Both pages use useQuery with the same query key.
The useQuery configuration for both pages has staleTime set to 0 and cacheTime (or gcTime) set to 0.
When I navigate from page1 to page2, the following unexpected behaviors occur:
The data queried on page1 does not seem to be garbage collected, even though cacheTime is 0.
On page2, instead of creating a new instance of the query, it appears to reuse the previous data.
Expected behavior
When navigating away from page1, the query data should be immediately removed from the cache due to cacheTime set to 0.
When navigating to page2, useQuery should initiate a fresh fetch since the data should have been garbage collected.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
os: mac
browser: chrome
Tanstack Query adapter
None
TanStack Query version
5.40.0
TypeScript version
No response
Additional context
No response
Beta Was this translation helpful? Give feedback.
All reactions