T
TanStack3y ago
stormy-gold

QueryFn is by default on pause and not executed

Hello, for me it works, however for my work colleague on mac using the same node version and chrome version we get different results. We are not using any cache provider, but somehow the query is not executed for him and marked as paused. For me it is executed without issue (on Ubuntu). What could be reasons for that? The hook looks like this:
export const fakeAPI = () =>
new Promise((resolve) =>
setTimeout(() => {
resolve(someTestData);
}, 100)
);


const useDocuments = (): UseQueryResult<IDocument[], void> => {
return useQuery({
queryKey: ['documents'],
queryFn: () => {
console.log('useDocuments');
return fakeAPI(); // this is simply
},
onSuccess: (data) => data,
onError: (error) => console.error(error)
});
};
export const fakeAPI = () =>
new Promise((resolve) =>
setTimeout(() => {
resolve(someTestData);
}, 100)
);


const useDocuments = (): UseQueryResult<IDocument[], void> => {
return useQuery({
queryKey: ['documents'],
queryFn: () => {
console.log('useDocuments');
return fakeAPI(); // this is simply
},
onSuccess: (data) => data,
onError: (error) => console.error(error)
});
};
Here is how we use the provider:
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { useState } from 'react';

const client = () => new QueryClient();

const TanStackQueryProvider: FC<PropsWithChildren> = ({ children }) => {
const [queryClient] = useState(client);

return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>;
};
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { useState } from 'react';

const client = () => new QueryClient();

const TanStackQueryProvider: FC<PropsWithChildren> = ({ children }) => {
const [queryClient] = useState(client);

return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>;
};
6 Replies
stormy-gold
stormy-goldOP3y ago
the useDocuments hook returns the following object:
{
“status”: “loading”,
“fetchStatus”: “paused”,
“isLoading”: true,
“isSuccess”: false,
“isError”: false,
“isInitialLoading”: false,
“dataUpdatedAt”: 0,
“error”: null,
“errorUpdatedAt”: 0,
“failureCount”: 0,
“failureReason”: null,
“errorUpdateCount”: 0,
“isFetched”: false,
“isFetchedAfterMount”: false,
“isFetching”: false,
“isRefetching”: false,
“isLoadingError”: false,
“isPaused”: true,
“isPlaceholderData”: false,
“isPreviousData”: false,
“isRefetchError”: false,
“isStale”: true
}
{
“status”: “loading”,
“fetchStatus”: “paused”,
“isLoading”: true,
“isSuccess”: false,
“isError”: false,
“isInitialLoading”: false,
“dataUpdatedAt”: 0,
“error”: null,
“errorUpdatedAt”: 0,
“failureCount”: 0,
“failureReason”: null,
“errorUpdateCount”: 0,
“isFetched”: false,
“isFetchedAfterMount”: false,
“isFetching”: false,
“isRefetching”: false,
“isLoadingError”: false,
“isPaused”: true,
“isPlaceholderData”: false,
“isPreviousData”: false,
“isRefetchError”: false,
“isStale”: true
}
Okay I found out why, it seems when we set networkMode to always then it works, is here maybe currently a bug with checking the connection on macs (with chrome)?
stormy-gold
stormy-goldOP3y ago
So it seems that this is being used to detect online status https://developer.mozilla.org/en-US/docs/Web/API/Navigator/onLine
Navigator: onLine property - Web APIs | MDN
Returns the online status of the browser. The property returns a boolean value, with true meaning online and false meaning offline. The property sends updates whenever the browser's ability to connect to the network changes. The update occurs when the user follows links or when a script requests a remote page. For example, the property s...
stormy-gold
stormy-goldOP3y ago
not sure if this is an issue on chrome and mac, since it works for him with using safari
extended-salmon
extended-salmon3y ago
it's a chrome bug that forced me to do this for v5: https://github.com/TanStack/query/pull/5714 I hate it, but what can you do 🤷‍♂️
GitHub
fix(onlineManager): always initialize with online: true by TkDodo...
instead of relying on navigator.onLine, because that indicator is broken AF in chrome https://bugs.chromium.org/p/chromium/issues/list?q=navigator.online
stormy-gold
stormy-goldOP3y ago
Okay so there is no workaround only setting the networkMode to always helps?
extended-salmon
extended-salmon3y ago
upgrade to v5?

Did you find this page helpful?