accelint-tanstack-query-best-practices

Configure TanStack Query to prevent data leakage and performance issues in Next.js App Router applications.

Updated Mar 24, 2026
One-click install
npx skills add https://github.com/Ahnd6474/Jakal-flow --skill accelint-tanstack-query-best-practices-ahnd6474
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: accelint-tanstack-query-best-practices
Source: https://github.com/Ahnd6474/Jakal-flow/tree/main/.skill-staging/skills/accelint-tanstack-query-best-practices
Command: npx skills add https://github.com/Ahnd6474/Jakal-flow --skill accelint-tanstack-query-best-practices-ahnd6474

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) and assets (resource) components.

What problem does it solve?

Developers often misconfigure TanStack Query in Next.js App Router projects, leading to server‑side cache leakage, unstable query keys, excessive observers, and unsafe optimistic updates that compromise performance and data integrity.

Core Features & Use Cases

  • QueryClient factory that isolates server requests and reuses a singleton in the browser.
  • Deterministic query‑key factories for hierarchical invalidation across server and client layers.
  • Observer economics guidance to hoist queries, avoid N‑queries‑in‑lists, and tune staleTime/gcTime.
  • Mutation patterns with safe optimistic updates, proper onMutate/onError/onSettled handling.
  • Multi‑layer caching strategy integrating Next.js use cache, TanStack Query, and HTTP cache.
  • Debugging aids such as observer‑count thresholds and performance decision matrices.

Quick Start

Ask the accelint-tanstack-query-best-practices skill to review and improve your TanStack Query setup for a Next.js App Router project.

Frequently Asked Questions about accelint-tanstack-query-best-practices

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent TanStack Query cache data leakage in Next.js App Router?

Prevent TanStack Query cache leakage in Next.js by using a QueryClient factory that isolates server requests per render while reusing a singleton in the browser, ensuring no cross-request data contamination.

What's the best way to structure TanStack Query keys for cache invalidation?

Use deterministic query-key factories to structure TanStack Query keys, enabling hierarchical cache invalidation across server and client layers for predictable data fetching and mutation updates.

How do I handle optimistic updates safely with TanStack Query mutations?

Handle safe optimistic updates in TanStack Query by implementing proper onMutate, onError, and onSettled handlers to roll back changes on failure and maintain data integrity during mutations.

Why does my Next.js app have excessive TanStack Query observers impacting performance?

Excessive TanStack Query observers impact performance when queries are not hoisted or N-queries-in-lists patterns are used, requiring observer optimization and tuning staleTime and gcTime to reduce redundant fetches.

Can I use TanStack Query caching alongside Next.js use cache and HTTP cache?

TanStack Query caching integrates with Next.js use cache and HTTP cache in a multi-layer strategy, coordinating server-side and client-side caches to optimize data fetching performance across the stack.

How do I debug TanStack Query performance issues in a Next.js application?

Debug TanStack Query performance issues using observer-count thresholds and performance decision matrices to identify excessive observers, unstable query keys, and suboptimal staleTime or gcTime configurations.