From a5be731fdaed312797feab5f1dacd616fc385b35 Mon Sep 17 00:00:00 2001 From: Vin Date: Wed, 12 Aug 2026 15:55:22 -0400 Subject: [PATCH] fix: stop redundant refetching of immutable gene data Just a simple change to React Query's defaults (staleTime 0 + refetchOnWindowFocus) caused every view to re-fetch its data on each tab focus. BAR expression data is immutable per gene, so set staleTime Infinity and disable focus refetch app-wide; this made many redundant recalls to the (costly) API. Queries remain keyed by gene id, so switching genes still fetches and returning to a gene is served from cache. If we ever need to have a re-fetch (I doubt it) we'll change it back --- Eplant/main.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Eplant/main.tsx b/Eplant/main.tsx index 4fd12b9..363b77c 100644 --- a/Eplant/main.tsx +++ b/Eplant/main.tsx @@ -72,7 +72,18 @@ const router = createBrowserRouter( { basename: import.meta.env.BASE_URL ?? '/' } ) -export const queryClient = new QueryClient() +// BAR expression data is immutable for a given gene, so it never goes stale. +// Without this, React Query's defaults (staleTime 0 + refetchOnWindowFocus) +// re-fetch every view's data on each tab focus. Queries are keyed by gene id, +// so switching genes still fetches; returning to a gene is served from cache. +export const queryClient = new QueryClient({ + defaultOptions: { + queries: { + staleTime: Infinity, + refetchOnWindowFocus: false, + }, + }, +}) function RootApp() { return (