From cd8f8c60b921a3b49ba1545f8557d8386db5f021 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Mon, 16 Feb 2026 10:51:49 -0600 Subject: [PATCH] Eh let's let RQ handle refetch and retries --- src/state/appConfig.tsx | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/state/appConfig.tsx b/src/state/appConfig.tsx index 3eb127b410..67b0e553ed 100644 --- a/src/state/appConfig.tsx +++ b/src/state/appConfig.tsx @@ -1,7 +1,6 @@ import {createContext, useContext} from 'react' import {QueryClient, useQuery} from '@tanstack/react-query' -import {networkRetry} from '#/lib/async/retry' import {APP_CONFIG_URL} from '#/env' const qc = new QueryClient() @@ -27,36 +26,36 @@ export const DEFAULT_APP_CONFIG_RESPONSE: AppConfigResponse = { }, } -let fetchAppConfigPromise: Promise +let fetchAppConfigPromise: Promise | undefined async function fetchAppConfig(): Promise { try { if (!fetchAppConfigPromise) { - fetchAppConfigPromise = networkRetry( - 3, - async () => { - const r = await fetch(`${APP_CONFIG_URL}/config`) - if (!r.ok) throw new Error(await r.text()) - const data = await r.json() - return data - }, - 1e3, - ) + fetchAppConfigPromise = (async () => { + const r = await fetch(`${APP_CONFIG_URL}/config`) + if (!r.ok) throw new Error(await r.text()) + const data = await r.json() + return data + })() } return await fetchAppConfigPromise - } catch { - return null + } catch (e) { + fetchAppConfigPromise = undefined + throw e } } const Context = createContext(DEFAULT_APP_CONFIG_RESPONSE) export function Provider({children}: React.PropsWithChildren<{}>) { - const {data} = useQuery( + const {data} = useQuery( { staleTime: Infinity, - gcTime: Infinity, queryKey: appConfigQueryKey, + refetchInterval: query => { + // refetch regularly if fetch failed, otherwise never refetch + return query.state.status === 'error' ? 60e3 : Infinity + }, async queryFn() { return fetchAppConfig() }, @@ -71,10 +70,12 @@ export function Provider({children}: React.PropsWithChildren<{}>) { } export async function prefetchAppConfig() { - const data = await fetchAppConfig() - if (data) { - qc.setQueryData(appConfigQueryKey, data) - } + try { + const data = await fetchAppConfig() + if (data) { + qc.setQueryData(appConfigQueryKey, data) + } + } catch {} } export function useAppConfig() {