Open History to see the last commit
TanStack Query Angular SSR + persistence example#
Combines SSR/hydration, a localStorage persister, and a client-only island: ClientPersistDemoComponent is mounted with afterNextRender, so its injectQuery queryFn does not run during SSR (unlike @defer main content, which is still rendered on the server for incremental hydration).
- Server: same bootstrap config shape as the base SSR example;
withPersistQueryClientuses a factory and skips work when not in the browser. - Client:
showClientDemois set totrueinafterNextRender, then<client-persist-demo />is created β optionaldehydrateOptions.shouldDehydrateQuerycan scope persistence toclient-persistquery keys only.
To run:
- From the repo root:
pnpm installthenpnpm --filter @tanstack/query-example-angular-ssr-persist start - Production SSR server after build:
pnpm --filter @tanstack/query-example-angular-ssr-persist run buildthenpnpm --filter @tanstack/query-example-angular-ssr-persist run serve:ssr