Potential Bug: RefetchIntervall callback fn is called even when the useQuery enabled = false
function useCheckSpotify(isCheckingSpotifyAccountConnection: boolean) {
return useQuery({
queryKey: ['isSpotifyAccountConnected'],
queryFn: async () => {
const response = await Axios({
method: 'GET',
url:
api/user/checkSpotify,
});
console.log('at useCheckSpotify: response.data.data', response.data.data);
if (response.data.data.exists === false) {
// no connection yet
window.open(response.data.data.url);
}
if (response.data.data.exists === true) {
// the connection exists already
console.log('at useCheckSpotify: Connection exists');
//@ts-ignore
generalStore.sendEventToSourceCategoryStateMachine('CONNECTING_COMPLETED');
}
return response.data.data;
},
enabled: isCheckingSpotifyAccountConnection,
refetchOnWindowFocus: false,
refetchInterval: data => {
if (data) {
console.log('at useCheckSpotify: Connection exists');
generalStore.sendEventToSourceCategoryStateMachine('CONNECTING_COMPLETED');
return false;
}
console.log('at useCheckSpotify: re-fetching while connection does not exist');
return 600; //refetch interval in milliseconds
},
...defaultQueryConfig,
});
}
please have a look at this hook.
I can say with certainty, that the isCheckingSpotifyAccountConnection value is false.
At the moment in time when I'm getting an error from this function.
The part of the code that is in the refetchInterval callback is being run anyway.
I am using v5.22.2
----
As an experiment I have changed the version to v5.0.0-beta.20 (because react-query-devtools had that version)
This seemed to have solved it.
Then I switched to the latest version: 5.24.1. the problem reapeared.
From my standpoint this looks like an issue on the side of Tanstack Query. At the very least you should know about it.
I'm sorry I don't have the time to create a Github issue with all the required fields.
5 Replies
sunny-greenOP•2y ago
@Shashtag do you have anything to add?
robust-apricot•2y ago
can you show a codesandbox reproduction please ?
sunny-greenOP•2y ago
not this week
sunny-greenOP•2y ago
@TkDodo 🔮
not sure how I can make an isolated version of this problem.
this is not something you'd expect happening:
Even when you passt just "false" on the useQuery
so enabled is definitely false
-> it still fetches
(and there is nowhere else in the codebase where this endpoint is being called
contrary to what I wrote earlier, this also occurs on the older version:

robust-apricot•2y ago
not sure how I can help you without an isolated problem 🤷♂️