-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useQuery
does not resume fetching when re-enabling with a function for enabled
and refetchInterval
#8358
Comments
thanks for reporting this. Here’s the same reproduction in a stackblitz with the devtools, which is easier to debug for me: https://stackblitz.com/edit/tanstack-query-rkfxvx?file=src%2Findex.tsx&preset=node I’ll try to fix this, but also note that we’re working on a better setting to turn these things off holistically for react-native screens. Have a look at this PR: |
okay got it. You’re writing to a shared mutable state ( query/packages/query-core/src/queryObserver.ts Lines 220 to 228 in 5d69ad7
In your example, they are both reading the shard mutable state, so they both With the function, you want to close over a value so that calling I’ve fixed the sandbox: https://stackblitz.com/edit/tanstack-query-rkfxvx?file=src%2Findex.tsx&preset=node |
I really appreciate your quick response.
Interesting. If I'm right, we should detect if current screen is focused, and if not, set |
Exactly 👍
To fully opt-out of re-rendering, you can currently use The newly proposed |
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
Expected behavior
When enabled toggles back to true and refetchInterval is defined:
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
Tanstack Query adapter
react-query
TanStack Query version
v5.61.5
TypeScript version
v5.3.3
Additional context
No response
The text was updated successfully, but these errors were encountered: