Skip to content

feat: wire up TanStack Query (SSR-aware) with a live example#49

Merged
tonytino merged 1 commit into
mainfrom
fix/41-wire-tanstack-query
Jun 11, 2026
Merged

feat: wire up TanStack Query (SSR-aware) with a live example#49
tonytino merged 1 commit into
mainfrom
fix/41-wire-tanstack-query

Conversation

@tonytino

Copy link
Copy Markdown
Owner

Closes #41.

TanStack Query was advertised across every stack list but never wired up — a runtime dependency imported nowhere. This integrates it the SSR-aware way.

Changes

  • app/router.tsx — create a QueryClient and wrap the router with routerWithQueryClient, so data prefetched in a loader is dehydrated on the server and hydrated on the client automatically. Provided via router context + a QueryClientProvider Wrap.
  • app/routes/__root.tsxcreateRootRouteWithContext<RouterContext>() so loaders get a typed context.queryClient.
  • app/routes/index.tsx — live example: a server-function-backed query prefetched in the loader (ensureQueryData) and read with useSuspenseQuery, side by side with the existing getWelcome server-function demo. (queryFn is a server function → no self-fetch.)
  • Added @tanstack/react-router-with-query, pinned exact 1.114.35 in pnpm.overrides alongside the rest of the TanStack set.
  • docs/agents/api.md — documents query-vs-server-function and the SSR prefetch pattern.

Verification

tsc ✓ · vitest 31 ✓ · biome check . ✓ · vinxi build ✓ — and serving the production build shows the SSR-prefetched query data (First item/Second item) in the rendered HTML (dehydration works end-to-end), homepage 200, stylesheet resolves, no server errors. Lockfile stays a coherent 1.114.x set.

Unblocks #42 (unused-dependency CI check) — react-query is now actually used.

🤖 Generated with Claude Code

)

TanStack Query was advertised across the stack docs but never actually wired
up — a runtime dep imported nowhere. Integrate it properly:

- app/router.tsx: create a QueryClient and use `routerWithQueryClient` so query
  data prefetched in loaders is dehydrated on the server and hydrated on the
  client automatically; provide it via context + a QueryClientProvider Wrap.
- app/routes/__root.tsx: switch to createRootRouteWithContext<RouterContext>()
  so loaders get a typed `context.queryClient`.
- app/routes/index.tsx: live example — a server-function-backed query prefetched
  in the loader (ensureQueryData) and read with useSuspenseQuery, alongside the
  existing getWelcome server-function demo.
- Add @tanstack/react-router-with-query (pinned exact 1.114.35 in pnpm.overrides,
  matching the rest of the TanStack set).
- docs/agents/api.md: document query-vs-server-function and the SSR prefetch
  pattern.

Verified: tsc, vitest (31), biome, vinxi build all pass; and serving the
production build shows the SSR-prefetched query data ("First item"/"Second
item") in the rendered HTML (dehydration works), homepage 200, stylesheet
resolves, no server errors.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tonytino tonytino merged commit 1fc70c9 into main Jun 11, 2026
3 checks passed
@tonytino tonytino deleted the fix/41-wire-tanstack-query branch June 11, 2026 01:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Task]: Wire up TanStack Query, or remove it from deps and docs

1 participant