docs(react): clarify staleTime 'static' vs Infinity with 'always' triggers#10354
docs(react): clarify staleTime 'static' vs Infinity with 'always' triggers#10354TkDodo merged 2 commits intoTanStack:mainfrom
Conversation
|
View your CI Pipeline Execution ↗ for commit b2e57fc
☁️ Nx Cloud last updated this comment at |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdded a documentation advisory clarifying the behavioral difference between Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| - set `staleTime` to `Infinity` to never trigger a refetch until the Query is [invalidated manually](./query-invalidation.md). | ||
| - set `staleTime` to `'static'` to **never** trigger a refetch, even if the Query is [invalidated manually](./query-invalidation.md). | ||
|
|
||
| > `'static'` and `Infinity` look similar but behave differently when `refetchOnMount`, `refetchOnWindowFocus`, or `refetchOnReconnect` are set to `"always"`. With `staleTime: Infinity`, those `"always"` triggers still fire. With `staleTime: 'static'`, they don't. The query stays frozen until you explicitly call `queryClient.resetQueries()`. Use `'static'` for data that cannot change while the app is running: feature flags fetched at boot, user permissions loaded at login, static reference tables. Use `Infinity` when you still want manual invalidation to work. |
There was a problem hiding this comment.
this sentence is great:
Use
'static'for data that cannot change while the app is running: feature flags fetched at boot, user permissions loaded at login, static reference tables. UseInfinitywhen you still want manual invalidation to work.
but the rest is a bit off. The ’always’ mention is also correct, but the biggest difference is that calling queryClient.invalidateQueries will still invalidate Infinity, but not ’static’.
So Infinity can be invalidated, static cannot.
The query stays frozen until you explicitly call
queryClient.resetQueries()
Also not quite correct. The query will never refetch data once data is in the cache. So if data leaves the cache for whatever reason, it will of course need to fetch again. Reasons could be garbage collection (gcTime), calling removeQueries, queryClient.clear() or resetQueries, but it’s really not necessary to list them all, as the guides should teach concepts.
… 'static' vs Infinity
Zelys-DFKH
left a comment
There was a problem hiding this comment.
Good catch. Rewrote the blockquote to lead with invalidateQueries() behavior and dropped the resetQueries() reference.
Summary
staleTime: 'static'is mentioned inimportant-defaults.mdand theuseQueryreference but the distinction fromInfinityis never explainedInfinitystill allowsrefetchOnMount/WindowFocus/Reconnect: "always"to fire;'static'blocks those too'static'bullet explaining the behavioral difference, when to reach for each, and thatresetQueries()is the escape hatchChecklist
Summary by CodeRabbit