PluginBench
Skill
Review
Audit score 70

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-practices
Claude Code
Cursor
Windsurf
Cline

How to use tanstack-integration-best-practices

  1. 1.Review the rule categories by priority (CRITICAL, HIGH, MEDIUM) to understand foundational requirements
  2. 2.Apply Setup rules first: configure QueryClient context, provider wrapping, and staleTime coordination
  3. 3.Implement Data Flow rules: use loaders with ensureQueryData and useSuspenseQuery in components
  4. 4.Configure SSR Integration: use setupRouterSsrQueryIntegration for automatic dehydration/hydration
  5. 5.Apply Caching rules: establish single-source-of-truth caching and unified invalidation patterns
  6. 6.Consult individual rule files in the rules/ directory for detailed code examples and context

Use cases

Good for
  • 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
Who it's for
  • 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

What is the recommended way to set up QueryClient in a TanStack Start project?

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.

How should I handle data fetching in route loaders?

Use the flow-loader-query-pattern with ensureQueryData to prefetch data in loaders, ensuring queries are resolved before component render.

What is the best approach for SSR with TanStack Query?

Use setupRouterSsrQueryIntegration for automatic dehydration/hydration (ssr-dehydrate-hydrate), create a QueryClient per request (ssr-per-request-client), and handle streaming queries appropriately.

How do I coordinate mutations with query caching?

Use flow-mutations-invalidation to coordinate mutations with query invalidation, and apply cache-invalidation-patterns for unified invalidation across the application.

Should I manage caching in multiple places?

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

PriorityCategoryRulesImpact
CRITICALSetup3 rulesFoundational configuration
CRITICALSSR Integration1 ruleRouter + Query SSR setup
HIGHData Flow4 rulesCorrect data fetching patterns
MEDIUMCaching3 rulesPerformance optimization
MEDIUMSSR2 rulesAdditional SSR patterns

Quick Reference

Setup (Prefix: setup-)

  • setup-query-client-context — Pass QueryClient through router context
  • setup-provider-wrapping — Correctly wrap with QueryClientProvider
  • setup-stale-time-coordination — Coordinate staleTime between router and query

Data Flow (Prefix: flow-)

  • flow-loader-query-pattern — Use loaders with ensureQueryData
  • flow-suspense-query-component — Use useSuspenseQuery in components
  • flow-mutations-invalidation — Coordinate mutations with query invalidation
  • flow-server-functions-queries — Use server functions for query functions

Caching (Prefix: cache-)

  • cache-single-source — Let TanStack Query manage caching
  • cache-preload-coordination — Coordinate preloading between router and query
  • cache-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 request
  • ssr-streaming-queries — Handle streaming with queries

How to Use

Each rule file in the rules/ directory contains:

  1. Explanation — Why this pattern matters
  2. Bad Example — Anti-pattern to avoid
  3. Good Example — Recommended implementation
  4. Context — When to apply or skip this rule

Full Reference

See individual rule files in rules/ directory for detailed guidance and code examples.