Sposta QueryClientProvider sopra AppShell per evitare crash SSR

useGiocatoreBase() ora interroga giocatori_squadra con useQuery, ma
RootComponent la chiamava prima di montare QueryClientProvider: ogni pagina
falliva in SSR con "No QueryClient set". Il provider avvolge ora tutto fin
dall'inizio; la logica di redirect/loading si sposta in un componente
AppShell interno, comportamento invariato.
This commit is contained in:
2026-09-03 10:16:40 +02:00
parent 4470139504
commit 7e93229eee
+12 -2
View File
@@ -157,6 +157,16 @@ function RootShell({ children }: { children: ReactNode }) {
function RootComponent() { function RootComponent() {
const { queryClient } = Route.useRouteContext(); const { queryClient } = Route.useRouteContext();
// `AppShell` legge la rosa da `giocatori_squadra` (useGiocatoreBase → DD-015): serve stare
// dentro il QueryClientProvider, quindi il provider avvolge tutto fin da qui.
return (
<QueryClientProvider client={queryClient}>
<AppShell />
</QueryClientProvider>
);
}
function AppShell() {
const navigate = useNavigate(); const navigate = useNavigate();
const location = useLocation(); const location = useLocation();
const giocatore = useGiocatoreBase(); const giocatore = useGiocatoreBase();
@@ -183,7 +193,7 @@ function RootComponent() {
} }
return ( return (
<QueryClientProvider client={queryClient}> <>
<div className="mx-auto min-h-screen max-w-md bg-background pb-24"> <div className="mx-auto min-h-screen max-w-md bg-background pb-24">
{/* Required: nested routes render here. Removing <Outlet /> breaks all child routes. */} {/* Required: nested routes render here. Removing <Outlet /> breaks all child routes. */}
<Outlet /> <Outlet />
@@ -191,6 +201,6 @@ function RootComponent() {
{!isBenvenuto && <BottomNav />} {!isBenvenuto && <BottomNav />}
{!isBenvenuto && <CelebrazioneBadge />} {!isBenvenuto && <CelebrazioneBadge />}
<Toaster position="top-center" duration={3500} closeButton /> <Toaster position="top-center" duration={3500} closeButton />
</QueryClientProvider> </>
); );
} }