#QueryFn is by default on pause and not executed

7 messages · Page 1 of 1 (latest)

crimson violet
#

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)
  });
};

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>;
};
#

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
}
#

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)?

#

So it seems that this is being used to detect online status https://developer.mozilla.org/en-US/docs/Web/API/Navigator/onLine

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...

#

not sure if this is an issue on chrome and mac, since it works for him with using safari

desert pelican
crimson violet
#

Okay so there is no workaround only setting the networkMode to always helps?