File tree Expand file tree Collapse file tree
src/integrations/tanstack-query Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { QueryClient , QueryClientProvider } from "@tanstack/react-query" ;
22
3- // Singleton queryClient to ensure the same instance is used everywhere
4- let queryClientSingleton : QueryClient | null = null ;
3+ // Client-side singleton to ensure the same instance is used across the app
4+ let clientQueryClient : QueryClient | null = null ;
5+
6+ function makeQueryClient ( ) {
7+ return new QueryClient ( ) ;
8+ }
59
610export function getContext ( ) {
7- if ( ! queryClientSingleton ) {
8- queryClientSingleton = new QueryClient ( ) ;
11+ // Server: always create a new QueryClient per request to avoid data leaks
12+ if ( typeof window === "undefined" ) {
13+ return {
14+ queryClient : makeQueryClient ( ) ,
15+ } ;
16+ }
17+
18+ // Client: use singleton to preserve cache across navigations
19+ if ( ! clientQueryClient ) {
20+ clientQueryClient = makeQueryClient ( ) ;
921 }
1022 return {
11- queryClient : queryClientSingleton ,
23+ queryClient : clientQueryClient ,
1224 } ;
1325}
1426
You can’t perform that action at this time.
0 commit comments