From 2793927a5c33ed930122da9be9f0787e93210552 Mon Sep 17 00:00:00 2001 From: null Date: Fri, 3 Jul 2026 20:56:31 -0500 Subject: [PATCH] feat(query): global background-refetch error toast (P1) Added a QueryCache onError handler to the QueryClient: pages already render an inline error on initial load, so this only toasts when a *background refetch* fails while stale data is on screen (which would otherwise be silent). Restores the load-error feedback dropped during the R5 migration, centrally. Co-Authored-By: Claude Opus 4.8 --- client/App.jsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/client/App.jsx b/client/App.jsx index 13dbe8e..e78c76f 100644 --- a/client/App.jsx +++ b/client/App.jsx @@ -13,10 +13,21 @@ import ErrorBoundary from '@/components/ErrorBoundary'; import PageLoader from '@/components/PageLoader'; // TanStack Query -import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; +import { QueryClient, QueryClientProvider, QueryCache } from '@tanstack/react-query'; import { ReactQueryDevtools } from '@tanstack/react-query-devtools'; +import { toast } from 'sonner'; const queryClient = new QueryClient({ + // Global error handling: pages render an inline error on the *initial* load + // (no data yet), so only surface a toast when a *background refetch* fails + // while stale data is still shown — otherwise the failure would be silent. + queryCache: new QueryCache({ + onError: (error, query) => { + if (query.state.data !== undefined) { + toast.error(error?.message || 'Could not refresh — showing the last data.'); + } + }, + }), defaultOptions: { queries: { staleTime: 1000 * 60 * 2, // 2 minutes