Only persist successful queries (#11484)
This commit is contained in:
+13
-11
@@ -1,11 +1,15 @@
|
|||||||
import {useEffect, useRef, useState} from 'react'
|
import {useEffect, useRef, useState} from 'react'
|
||||||
import {AppState, type AppStateStatus} from 'react-native'
|
import {AppState, type AppStateStatus} from 'react-native'
|
||||||
import {createAsyncStoragePersister} from '@tanstack/query-async-storage-persister'
|
import {createAsyncStoragePersister} from '@tanstack/query-async-storage-persister'
|
||||||
import {focusManager, onlineManager, QueryClient} from '@tanstack/react-query'
|
import {
|
||||||
|
type DehydrateOptions,
|
||||||
|
focusManager,
|
||||||
|
onlineManager,
|
||||||
|
QueryClient,
|
||||||
|
} from '@tanstack/react-query'
|
||||||
import {
|
import {
|
||||||
type PersistQueryClientOptions,
|
type PersistQueryClientOptions,
|
||||||
PersistQueryClientProvider,
|
PersistQueryClientProvider,
|
||||||
type PersistQueryClientProviderProps,
|
|
||||||
} from '@tanstack/react-query-persist-client'
|
} from '@tanstack/react-query-persist-client'
|
||||||
|
|
||||||
import {createPersistedQueryStorage} from '#/lib/persisted-query-storage'
|
import {createPersistedQueryStorage} from '#/lib/persisted-query-storage'
|
||||||
@@ -16,8 +20,7 @@ import {IS_NATIVE, IS_WEB} from '#/env'
|
|||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
|
__TANSTACK_QUERY_CLIENT__: QueryClient
|
||||||
__TANSTACK_QUERY_CLIENT__: import('@tanstack/query-core').QueryClient
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,13 +136,12 @@ const createQueryClient = () =>
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const dehydrateOptions: PersistQueryClientProviderProps['persistOptions']['dehydrateOptions'] =
|
const dehydrateOptions: DehydrateOptions = {
|
||||||
{
|
shouldDehydrateMutation: (_: any) => false,
|
||||||
shouldDehydrateMutation: (_: any) => false,
|
shouldDehydrateQuery: query => {
|
||||||
shouldDehydrateQuery: query => {
|
return isQueryPersisted(query.queryKey) && query.state.status === 'success'
|
||||||
return isQueryPersisted(query.queryKey)
|
},
|
||||||
},
|
}
|
||||||
}
|
|
||||||
|
|
||||||
export function QueryProvider({
|
export function QueryProvider({
|
||||||
children,
|
children,
|
||||||
|
|||||||
Reference in New Issue
Block a user