Review TanStack Query
Review the TanStack Query setup in front-app (and its consumption of worker-api over HTTP) for alignment with current official best practices - query organization, cache correctness, and developer experience on a React 19 SPA. Your reply must be a plan of suggested changes: concise, actionable, structured - not only prose.
Invocation
Text after the slash command is additional scope/focus (e.g. "mutations", "cache invalidation") - narrow the review accordingly.
Ground truth (mandatory)
Your pre-trained knowledge of TanStack Query may be outdated. Do not draft suggestions from memory alone.
- Resolve "TanStack Query" via the Context7 MCP (
resolve-library-id→query-docs) at v5:queryOptionspattern,useSuspenseQuery/useInfiniteQueryguidance,placeholderData/initialDatasemantics, invalidation strategies,QueryClientdefaults. - Cross-check with local skill
.agents/skills/tanstack-query/SKILL.md. - For anything Context7 lacks, use Firecrawl search/scrape restricted to the official domain (
tanstack.com/query) - guides, reference, changelog for the installed minor. - Version currency: catalog entries (
@tanstack/react-query,-devtools) in pnpm-workspace.yaml vs latest stable; flag deprecated v4-era APIs still present (isFetchingmisuse aside - look for removed options). - Cite the retrieved source next to every finding; label anything unverifiable as Unverified.
Scope artifacts
- apps/front-app/src/services/ (fetchers +
queryOptionsdefinitions), apps/front-app/src/hooks/ QueryClientinstantiation/defaults and provider placement; router integration (loader ↔ queryClient)- Devtools wiring (
@tanstack/react-query-devtools, production gating) - Correlation-id header propagation from SPA to gateway (packages/correlation-id)
Analysis axes
- Query organization: stable, hierarchical query keys;
queryOptionsfactories co-located with services; no inline keys scattered across components. - Cache semantics: deliberate
staleTime/gcTimeper data type (not all-default); nocacheTimev4 leftovers; structural sharing intact; optimistic updates with rollback handled via current mutation APIs. - Invalidation & mutations: targeted
invalidateQueriespredicates; mutation → refetch flows correct; error handling surfaced to UI consistently. - Loading UX: Suspense-based reads where idiomatic (
useSuspenseQuery) vs classic hooks; no request waterfalls from sequential dependent queries that could be parallel or prefetched in route loaders. - Transport: typed fetch wrapper against DTOs from
@repo/dtos-common; correlation id attached; base URL from env only. - Devtools: mounted only outside production; version aligned with runtime.
DX & AI-agentic workflow
Verify agent-friendliness: adding a query follows one documented pattern (service + queryOptions + hook); fast verification loop via front-app tests (see front-vitest skill for RTL/query harness conventions).
Steps
- Collect ground truth before reading code.
- Read services/hooks end-to-end; trace one query from loader through component.
- Walk each analysis axis; note findings or explicit one-line "no issues".
- Compose the plan grouped Critical / Improvements / Optional with what, where, why, and source citations.
Output format
- Critical - broken cache assumptions, unhandled mutation errors, stale/deprecated API breakage risk.
- Improvements - key/staleTime/loader alignment with current guidance.
- Optional - nice-to-haves; prefix pure polish with Nit:.
Read-only review: produce the plan only; implement nothing unless explicitly asked afterwards.