tRPC + React Query: Should stale queries trigger automatic background refetches?
0 reputation · 19 Nov 2025, 22:27 UTC
Integration Goal
Goal: Determine if tRPC’s React Query adapter should automatically issue a background refetch when a query becomes stale, without relying on window focus, re‑render, or manual refetchInterval.
Constraints and Trade‑offs
Constraints: The current implementation marks a query stale after staleTime expires and only refetches on React Query triggers; introducing automatic background refetches could reduce UI inconsistency but may increase server traffic and affect performance, especially in high‑frequency update scenarios. Additionally, behavior differs between tRPC v9 and v10+, so any change must consider version compatibility.
Open Questions
Questions: Should the adapter enable background refetches by default for stale queries? If enabled, what heuristic (e.g., staleTime threshold, subscription presence) should trigger the refetch? How can developers opt‑out or tune the frequency to balance freshness and load?