tanstack-integration-best-practices
deckardger/tanstack-agent-skills
Best practices for coordinating TanStack Query, Router, and Start in full-stack applications.
What is tanstack-integration-best-practices?
Patterns and guidelines for integrating TanStack Query with TanStack Router and TanStack Start, covering SSR setup, data flow coordination, and caching strategies. Use this when building new TanStack projects or refactoring existing integrations to ensure optimal type safety and performance.
- Provides setup patterns for QueryClient context and provider wrapping
- Establishes data flow rules using loaders with ensureQueryData and useSuspenseQuery
- Coordinates caching and invalidation between router and query layers
- Configures SSR with automatic dehydration/hydration via setupRouterSsrQueryIntegration
- Defines staleTime coordination and per-request QueryClient creation for SSR
How to install tanstack-integration-best-practices
npx skills add https://github.com/deckardger/tanstack-agent-skills --skill tanstack-integration-best-practicesHow to use tanstack-integration-best-practices
- 1.Review the rule categories by priority (CRITICAL, HIGH, MEDIUM) to understand foundational requirements
- 2.Apply Setup rules first: configure QueryClient context, provider wrapping, and staleTime coordination
- 3.Implement Data Flow rules: use loaders with ensureQueryData and useSuspenseQuery in components
- 4.Configure SSR Integration: use setupRouterSsrQueryIntegration for automatic dehydration/hydration
- 5.Apply Caching rules: establish single-source-of-truth caching and unified invalidation patterns
- 6.Consult individual rule files in the rules/ directory for detailed code examples and context
Use cases
- Setting up a new TanStack Start project with Query and Router integration
- Configuring SSR with proper query hydration and streaming support
- Refactoring mutations to coordinate with query invalidation patterns
- Establishing type-safe data fetching using server functions as query functions
- Optimizing caching by letting TanStack Query be the single source of truth
- Full-stack developers building with TanStack Start
- Teams integrating TanStack Query with TanStack Router
- Developers implementing SSR in TanStack applications
- Engineers optimizing data flow and caching strategies
tanstack-integration-best-practices FAQ
Pass QueryClient through router context using setup-query-client-context, wrap with QueryClientProvider using setup-provider-wrapping, and coordinate staleTime settings between router and query via setup-stale-time-coordination.
Use the flow-loader-query-pattern with ensureQueryData to prefetch data in loaders, ensuring queries are resolved before component render.
Use setupRouterSsrQueryIntegration for automatic dehydration/hydration (ssr-dehydrate-hydrate), create a QueryClient per request (ssr-per-request-client), and handle streaming queries appropriately.
Use flow-mutations-invalidation to coordinate mutations with query invalidation, and apply cache-invalidation-patterns for unified invalidation across the application.
No. Apply cache-single-source to let TanStack Query be the single source of truth for caching, avoiding duplication and inconsistency.
Full instructions (SKILL.md)
Source of truth, from deckardger/tanstack-agent-skills.
name: tanstack-integration-best-practices description: Best practices for integrating TanStack Query with TanStack Router and TanStack Start. Patterns for full-stack data flow, SSR, and caching coordination.
TanStack Integration Best Practices
Guidelines for integrating TanStack Query, Router, and Start together effectively. These patterns ensure optimal data flow, caching coordination, and type safety across the stack.
When to Apply
- Setting up a new TanStack Start project
- Integrating TanStack Query with TanStack Router
- Configuring SSR with query hydration
- Coordinating caching between router and query
- Setting up type-safe data fetching patterns
Rule Categories by Priority
| Priority | Category | Rules | Impact |
|---|---|---|---|
| CRITICAL | Setup | 3 rules | Foundational configuration |
| CRITICAL | SSR Integration | 1 rule | Router + Query SSR setup |
| HIGH | Data Flow | 4 rules | Correct data fetching patterns |
| MEDIUM | Caching | 3 rules | Performance optimization |
| MEDIUM | SSR | 2 rules | Additional SSR patterns |
Quick Reference
Setup (Prefix: setup-)
setup-query-client-context— Pass QueryClient through router contextsetup-provider-wrapping— Correctly wrap with QueryClientProvidersetup-stale-time-coordination— Coordinate staleTime between router and query
Data Flow (Prefix: flow-)
flow-loader-query-pattern— Use loaders with ensureQueryDataflow-suspense-query-component— Use useSuspenseQuery in componentsflow-mutations-invalidation— Coordinate mutations with query invalidationflow-server-functions-queries— Use server functions for query functions
Caching (Prefix: cache-)
cache-single-source— Let TanStack Query manage cachingcache-preload-coordination— Coordinate preloading between router and querycache-invalidation-patterns— Unified invalidation patterns
SSR Integration (Prefix: ssr-)
ssr-dehydrate-hydrate— Use setupRouterSsrQueryIntegration for automatic SSR
Additional SSR (Prefix: ssr-)
ssr-per-request-client— Create QueryClient per requestssr-streaming-queries— Handle streaming with queries
How to Use
Each rule file in the rules/ directory contains:
- Explanation — Why this pattern matters
- Bad Example — Anti-pattern to avoid
- Good Example — Recommended implementation
- Context — When to apply or skip this rule
Full Reference
See individual rule files in rules/ directory for detailed guidance and code examples.
Related skills
More from deckardger/tanstack-agent-skills and the wider catalog.

tanstack-query-best-practices
TanStack Query best practices for optimized data fetching, caching, and server state management in React.

tanstack-router-best-practices
Type-safe routing patterns and best practices for TanStack Router in React applications.

tanstack-start-best-practices
TanStack Start best practices for full-stack React: server functions, middleware, SSR, auth, and deployment.
mies
Ruthless reduction and exacting craft for user-facing interfaces, applying Mies van der Rohe restraint and anti-generic design discipline.

wonda-cli
Terminal toolkit for generating media and automating social research across LinkedIn, Reddit, and X/Twitter.

astro-framework
Astro framework specialist for fast, content-driven websites with islands architecture and hybrid rendering.