"use client"; import { QueryClient, QueryClientProvider, } from "@tanstack/react-query"; import { type ReactNode, useState } from "react"; import AuthDataBoundary from "@/components/Componentes/auth-data-boundary"; import FlutterLocaleSync from "@/components/Componentes/flutter-locale-sync"; import HardwareBackBridge from "@/components/Componentes/hardware-back-bridge"; import SilentReloader from "@/components/Componentes/silent-reloader"; import { ViewPaddingsProvider } from "@/components/Componentes/view-paddings-provider"; import { marriageQueryKeys } from "@/hooks/marriage/query-keys"; import type { MarriageProfileResponse } from "@/hooks/marriage/types"; // AppFocusReloader was extracted to SilentReloader in silent-reloader.tsx type ProvidersProps = { children: ReactNode; initialProfile?: MarriageProfileResponse; }; export default function Providers({ children, initialProfile }: ProvidersProps) { const [queryClient] = useState( () => { const qc = new QueryClient({ defaultOptions: { queries: { // Keep the last successful response available while a fresh // request runs. `isLoading` is therefore only true on the first // visit to a query; later visits render cached data immediately. refetchOnWindowFocus: false, refetchOnMount: false, refetchOnReconnect: false, retry: 1, staleTime: 30 * 1000, // Retain page data long enough for back-navigation to be instant. gcTime: 10 * 60 * 1000, // React Query replaces only the changed branches of a response, // preventing needless UI updates when a silent refresh is equal. structuralSharing: true, }, }, }); if (initialProfile) { console.log("⚡ [Providers] Initializing QueryClient cache with SSR initialProfile:", { id: initialProfile.id, status: initialProfile.status, gender: initialProfile.gender, has_match_summary: Boolean(initialProfile.match_summary), match_summary_id: initialProfile.match_summary?.id, public_info_count: initialProfile.match_summary?.public_info?.length, }); qc.setQueryData(marriageQueryKeys.profile(), initialProfile); } else { console.log("ℹ️ [Providers] No initialProfile passed from SSR"); } return qc; }, ); return ( {children} ); }