Repository navigation
API being called on page mount every time despite having stale and cache values of 5 minutes #9734
Replies: 2 comments
|
When TanStack Query fires an unexpected network request on mount despite having Here is a breakdown of the root causes and how to resolve them: 1. The
|
|
If the key and cached data are already confirmed on the screen, a cache subscription can help narrow down what happens next. I checked this with Query Core 5.104.4. Mounting an observer with warm data and Install this temporarily in the provider, before the screen mounts, using the same client the screen gets from const unsubscribe = queryClient.getQueryCache().subscribe((event) => {
const { query } = event
if (query.queryKey[0] !== 'agent' || query.queryKey[1] !== 'profile') return
if (event.type === 'updated') {
console.log(event.action.type, query.queryHash, {
hasData: query.state.data !== undefined,
invalidated: query.state.isInvalidated,
})
} else if (event.type === 'added' || event.type === 'observerAdded') {
console.log(event.type, query.queryHash)
}
})
// Call unsubscribe() when the diagnostic is no longer needed.If you see |
Uh oh!
There was an error while loading. Please reload this page.
Hi @ALL, I have been working on a react native expo project and I have cached an api with gcTime of 10 minutes and staleTime of 5 minutes. I am adding the relevant components
//useAgentProfile.tsx
The keys do not change on page mount, stale is false, and data exists in cache. I've verified it using following consoles
Cache for query key: ["agent", "profile", 'a number here']
Cached data: true
Is data stale?: false
Data updated at: 10/6/2025, 6:53:46 PM
what are the common troubleshooting steps or some common beginners mistakes that I might be making.
All reactions