fix(query-core): ensure query refetches on mount/retry when status is error (#9728) (#9927)
* fix(query-core): ensure query refetches on mount/retry when status is error (#9728) * fix: mark queries as invalidated on background errors instead of checking error status - Remove error status check in shouldFetchOn - Set isInvalidated: true in reducer when background error occurs (only if data exists) - Add tests for staleTime: 'static' and non-static queries with background errors This approach centralizes stale logic in isStale/isStaleByTime and prevents regression where staleTime: 'static' queries would incorrectly refetch on window focus after a background error. * refactor: simplify isInvalidated logic in error case Set isInvalidated: true unconditionally since queries with no data are always considered stale per isStaleByTime logic. * Apply suggestion from @TkDodo * Apply suggestions from code review * fix: eslint * fix: disable retry in background error tests to prevent timeout The tests were timing out because when refetch() throws an error, the default retry mechanism (3 retries with exponential backoff) was being triggered. With fake timers, the retry delays weren't being advanced, causing the tests to hang. Adding retry: false to both tests disables retries and allows them to complete immediately after the error, which is appropriate for these tests that specifically check background error behavior. --------- Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc>
X
xiangnuan committed
fccef797d57d4a9566517bba87c8377f363920f2
Parent: e907f89
Committed by GitHub <noreply@github.com>
on 12/29/2025, 3:36:15 PM