diff --git a/src/router.tsx b/src/router.tsx index 9700374..9ae9e9d 100644 --- a/src/router.tsx +++ b/src/router.tsx @@ -1,4 +1,4 @@ -import { QueryClient } from '@tanstack/react-query'; +import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { createRouter } from '@tanstack/react-router'; import { setupRouterSsrQueryIntegration } from '@tanstack/react-router-ssr-query'; import { routeTree } from './routeTree.gen'; @@ -27,11 +27,19 @@ export function getRouter() { scrollRestoration: true, defaultErrorComponent: ({ error }) => , defaultNotFoundComponent: NotFound, + // Provide the QueryClient from the app's own react-query import rather than + // letting the SSR integration wrap it. react-query ships ESM and CJS builds; + // if the integration is loaded through its CJS entry while the app imports + // ESM, they hold separate React contexts and every useQuery fails during + // SSR with "No QueryClient set" (seen in the nodesandbox runtime). + Wrap: ({ children }) => ( + {children} + ), }); - // Streams queries fetched during SSR to the client cache and wraps the app - // in a QueryClientProvider. - setupRouterSsrQueryIntegration({ router, queryClient }); + // Streams queries fetched during SSR to the client cache. The provider is + // the Wrap above, so the integration must not add its own. + setupRouterSsrQueryIntegration({ router, queryClient, wrapQueryClient: false }); return router; }