mirror of
https://github.com/supabase/supabase.git
synced 2026-06-22 02:02:51 +08:00
* chore: increase react-query stale time * keep staleTime: 0 for table rows * use staleTime: 0 for all user sql queries * use staleTime: 0 for all pg-meta queries * Some fixes * fix updating tables * fix bug while editing column names * Fix deleting column in database/tables column list not revalidating UI * Fix updating column in database/tables column list throwing ane rror --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
import { QueryClient, onlineManager } from '@tanstack/react-query'
|
|
import { IS_PLATFORM } from 'lib/constants'
|
|
import { useState } from 'react'
|
|
|
|
// When running locally we don't need the internet
|
|
// so we can pretend we're online all the time
|
|
if (!IS_PLATFORM) {
|
|
onlineManager.setOnline(true)
|
|
}
|
|
|
|
let queryClient: QueryClient | undefined
|
|
|
|
export function getQueryClient() {
|
|
const _queryClient =
|
|
queryClient ??
|
|
new QueryClient({
|
|
defaultOptions: {
|
|
queries: {
|
|
staleTime: 60 * 1000, // 1 minute
|
|
retry: (failureCount, error) => {
|
|
// Don't retry on 404s
|
|
if (
|
|
typeof error === 'object' &&
|
|
error !== null &&
|
|
'code' in error &&
|
|
(error as any).code === 404
|
|
) {
|
|
return false
|
|
}
|
|
|
|
if (failureCount < 3) {
|
|
return true
|
|
}
|
|
|
|
return false
|
|
},
|
|
},
|
|
},
|
|
})
|
|
|
|
// For SSG and SSR always create a new queryClient
|
|
if (typeof window === 'undefined') return _queryClient
|
|
// Create the queryClient once in the client
|
|
if (!queryClient) queryClient = _queryClient
|
|
|
|
return queryClient
|
|
}
|
|
|
|
export function useRootQueryClient() {
|
|
const [_queryClient] = useState(() => getQueryClient())
|
|
|
|
return _queryClient
|
|
}
|