T
TanStack7mo ago
extended-salmon

useQuery not using stale data why?

I have the following code in my app export const clientPersister = createSyncStoragePersister({ storage: clientStorage }); const queryClient = new QueryClient({ defaultOptions: { queries: { gcTime: 1000 * 60 * 60 * 24 * 7, // 7 days retry: false, networkMode: 'offlineFirst', }, mutations: { networkMode: 'offlineFirst', }, /* mutations: { onError: (error) => { console.log('error ', error); toast.error(error.message); }, }, */ }, }); const persistOptions: Omit<PersistQueryClientOptions, 'queryClient'> = { persister: clientPersister, maxAge: 1000 * 60 * 60 * 24 * 7, // 7 days }; export function QueryProvider({ children }: { children: React.ReactNode }) { useOnlineManager(); useAppState(onAppStateChange); return ( <PersistQueryClientProvider client={queryClient} persistOptions={persistOptions}> {children} </PersistQueryClientProvider> ); } When i initially run a query when users have internet I see my data, when I reload the app without internet i don’t see the data any more, i thought useQuery is going to use cached data even though it is no longer fresh and it hasn’t been garbage collected, please help? I also want to be able to refresh the data in case internet is restored
4 Replies
conscious-sapphire
conscious-sapphire7mo ago
it sure should, please show a reproduction. Are you sure your site can load without internet?
extended-salmon
extended-salmonOP7mo ago
I’m using this in a react native mobile app I also use ky, checking the error from useQuery i get TypeError: signal.throwIfAborted is not a function (it is undefined
rare-sapphire
rare-sapphire7mo ago
Looks like an issue with react native. One comment refers to the same conversation in ky as well as a polyfill solution. https://github.com/facebook/react-native/issues/50015
GitHub
AbortSignal/AbortController doesn't work · Issue #50015 · faceboo...
Description AbortController / AbortSignal are used in javascript to cancel a request started with fetch, or any other async task that should be cancellable (docs here) In react native, there are se...
extended-salmon
extended-salmonOP7mo ago
Thank you. I’ll review this solution, if it doesn’t work I’ll replace with ofetch instead

Did you find this page helpful?