refactor(services): drop the bespoke retry engine from the query wrapper

The custom onErrorRetry existed only to honor a function-form
retryDelay, which exactly one caller (the app data provider) used for
exponential backoff. Fall back to SWR's built-in error retry and
express that caller's cadence with constant options.
This commit is contained in:
Tunglies
2026-10-28 10:52:18 +08:00
parent 433230aedc
commit 2fd6be642e
2 changed files with 5 additions and 19 deletions
+3 -1
View File
@@ -26,7 +26,9 @@ const TQ_MIHOMO = {
refetchOnReconnect: false,
staleTime: 1500,
retry: 3,
retryDelay: (attempt: number) => Math.min(200 * 2 ** attempt, 3000),
// SWR's default retry waits about 2^retryCount * errorRetryInterval with
// jitter, so 100 reproduces the previous 200 * 2^attempt backoff.
retryDelay: 100,
} as const
const TQ_DEFAULTS = {
+2 -18
View File
@@ -18,7 +18,7 @@ type QueryOptions<T> = {
placeholderData?: T | (() => T | undefined)
staleTime?: number
retry?: number | false
retryDelay?: number | ((attempt: number) => number)
retryDelay?: number
refetchInterval?: number | false
refetchIntervalInBackground?: boolean
revalidateOnMount?: boolean
@@ -90,25 +90,9 @@ export function useQuery<T>(options: QueryOptions<T>): QueryResult<T> {
const swr = useSWR<T>(enabled ? queryKey : null, queryFn, {
dedupingInterval: staleTime,
errorRetryCount: retry === false ? 0 : retry,
errorRetryInterval:
typeof retryDelay === 'number'
? retryDelay
: swrConfig.errorRetryInterval,
errorRetryInterval: retryDelay ?? swrConfig.errorRetryInterval,
fallbackData,
keepPreviousData: placeholderData !== undefined,
onErrorRetry: (_error, _key, config, revalidate, { retryCount }) => {
const maxRetries = config.errorRetryCount
if (maxRetries !== undefined && retryCount > maxRetries) return
const interval =
typeof retryDelay === 'function'
? retryDelay(Math.max(retryCount - 1, 0))
: config.errorRetryInterval
setTimeout(() => {
revalidate({ retryCount, dedupe: true })
}, interval)
},
revalidateOnFocus: refetchOnWindowFocus,
revalidateOnMount,
revalidateOnReconnect: refetchOnReconnect,