Description
Describe the bug
When using useQuery with a dynamic enabled property (passing a function) and refetchInterval, the query correctly stops when enabled returns false. However, when enabled returns true again (for example, when re-focusing a screen or toggling the state), the query does not resume executing the queryFn as expected. Logs confirm that the enabled function is called and returns true, but no further calls to the queryFn are made, and the refetchInterval appears to be ignored after re-enabling.
This behavior is problematic for scenarios such as React Native apps where queries should be disabled on inactive screens and resume when the user navigates back.
Your minimal, reproducible example
https://snack.expo.dev/@smhdasadi/reactqueryenabledrefetchintervalbug
Steps to reproduce
- Open project in this Expo Snack link.
- Observe the query repeatedly calling queryFn at the defined refetchInterval (2 seconds).
- Press the button to toggle enabled to false. The query stops, and no further queryFn executions are logged.
- Press the button again to toggle enabled back to true. Logs show that enabled is being called and returns true, but the query does not resume execution.
- Observe that no further executions of queryFn are triggered.
Expected behavior
When enabled toggles back to true and refetchInterval is defined:
- The query should resume execution.
- The queryFn should be called at the defined refetchInterval.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
- OS: Android, iOS
- Platform: React Native
Tanstack Query adapter
react-query
TanStack Query version
v5.61.5
TypeScript version
v5.3.3
Additional context
No response