Yeah, SSR support is not that great, it's also missing a build-in way to hydrate the client to avoid going back to the loading state when components load.
You can also do something like this to change some options in the query options on the server, for example, to avoid delaying the render for retries:
export const sharedQueryDefaults = {
staleTime: 1000 * 30,
gcTime: 1000 * 60 * 60 * 24,
} as const
export const createBrowserQueryClient = () =>
new QueryClient({
defaultOptions: {
queries: { ...sharedQueryDefaults },
},
})
export const getBaseAppConfig = (queryClient: QueryClient): ApplicationConfig => ({
providers: [
provideClientHydration(withEventReplay()),
provideTanStackQuery(queryClient, withDevtools(), withHydration()),
],
})
export const getClientAppConfig = () => getBaseAppConfig(createBrowserQueryClient())
const createServerQueryClient = () =>
new QueryClient({
defaultOptions: {
queries: {
...sharedQueryDefaults,
retry: false,
},
},
})
export const getServerConfig = (_context: BootstrapContext) =>
mergeApplicationConfig(getBaseAppConfig(createServerQueryClient()), {
providers: [
provideServerRendering(withRoutes(serverRoutes)),
],
})