|
1 | 1 | import { StacApiProvider } from 'stac-react'; |
| 2 | +import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; |
2 | 3 | import Header from './layout/Header'; |
3 | 4 | import Main from './pages/Main'; |
4 | 5 |
|
| 6 | +// Create a QueryClient with custom cache configuration |
| 7 | +// IMPORTANT: Must be created outside the component to maintain cache across renders |
| 8 | +const queryClient = new QueryClient({ |
| 9 | + defaultOptions: { |
| 10 | + queries: { |
| 11 | + // STAC data doesn't change frequently, so we can cache it for 5 minutes |
| 12 | + staleTime: 5 * 60 * 1000, // 5 minutes |
| 13 | + // Keep unused data in cache for 10 minutes |
| 14 | + gcTime: 10 * 60 * 1000, // 10 minutes |
| 15 | + retry: 1, |
| 16 | + // Disable automatic refetching since STAC data is static |
| 17 | + refetchOnWindowFocus: false, |
| 18 | + refetchOnMount: false, |
| 19 | + refetchOnReconnect: false, |
| 20 | + }, |
| 21 | + }, |
| 22 | +}); |
| 23 | + |
5 | 24 | function App() { |
6 | 25 | const apiUrl = process.env.REACT_APP_STAC_API; |
7 | 26 | const isDevelopment = process.env.NODE_ENV === 'development'; |
8 | 27 |
|
| 28 | + // Debug: Verify QueryClient configuration |
| 29 | + if (isDevelopment && typeof window !== 'undefined') { |
| 30 | + console.log('[App] QueryClient defaults:', queryClient.getDefaultOptions()); |
| 31 | + } |
| 32 | + |
9 | 33 | return ( |
10 | | - <StacApiProvider apiUrl={apiUrl} enableDevTools={isDevelopment}> |
11 | | - <div className="App grid grid-rows-[min-content_1fr]"> |
12 | | - <Header /> |
13 | | - <main className="flex items-stretch"> |
14 | | - <Main /> |
15 | | - </main> |
16 | | - </div> |
17 | | - </StacApiProvider> |
| 34 | + <QueryClientProvider client={queryClient}> |
| 35 | + <StacApiProvider apiUrl={apiUrl} enableDevTools={isDevelopment} queryClient={queryClient}> |
| 36 | + <div className="App grid grid-rows-[min-content_1fr]"> |
| 37 | + <Header /> |
| 38 | + <main className="flex items-stretch"> |
| 39 | + <Main /> |
| 40 | + </main> |
| 41 | + </div> |
| 42 | + </StacApiProvider> |
| 43 | + </QueryClientProvider> |
18 | 44 | ); |
19 | 45 | } |
20 | 46 |
|
|
0 commit comments