data-loading

Configure TanStack Router loaders with SWR caching, deferred data, and context injection.

Updated May 26, 2026
One-click install
npx skills add https://github.com/Albo-Club/albo-os --skill data-loading-albo-club
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: data-loading
Source: https://github.com/Albo-Club/albo-os/tree/main/.agents/skills/tanstack-router-core/data-loading
Command: npx skills add https://github.com/Albo-Club/albo-os --skill data-loading-albo-club

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @tanstack/react-router, @tanstack/react-start.

What problem does it solve? Fetching route data in TanStack Router requires coordinating loaders, cache keys, pending states, and error boundaries, and common mistakes like server-only code in client-first loaders or misconfigured staleTime cause crashes and stale UI. ## Core Features & Use Cases - Loader and Cache Configuration: Set up route loaders with loaderDeps cache keys, staleTime/gcTime SWR caching, and pendingComponent states. - Context and Deferred Data: Inject dependencies via createRootRouteWithContext and stream non-critical data with the Await component. - Error Handling and Invalidation: Recover from loader failures with errorComponent and router.invalidate after mutations. - Use Case: Build a paginated posts list where changing the page search param re-runs the loader, comments load deferred behind a fallback, and adding a post invalidates the cache. ## Quick Start Set up a TanStack Router route loader with search-param cache keys, a pending component, and invalidation after mutations.

Frequently Asked Questions about data-loading

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

FAQPage Schema
How do I load data in a TanStack Router route?

Define a loader function on the route that returns your data, then consume it in the component with Route.useLoaderData or getRouteApi for code-split files. The loader runs in parallel with component preloading during route matching.

How do loaderDeps and search params work in TanStack Router?

loaderDeps maps validated search params into the loader cache key, so the loader re-runs only when those deps change. Return only the relevant params, not the whole search object, to avoid unnecessary reloads from unrelated param changes.

Do TanStack Router loaders run on the server or client?

Loaders are client-first and run in the browser by default. With TanStack Start SSR they also run on the server, so server-only code like database queries must go inside a server function called from the loader.

Why does my TanStack Router loader refetch on every navigation?

The default staleTime is 0, so data is always considered stale and reloads in the background on every route re-match. Set a staleTime in milliseconds on the route or defaultStaleTime on the router to keep data fresh longer.

How do I retry a failed loader in TanStack Router?

Call router.invalidate() from your errorComponent instead of reset(). Invalidation re-runs the loader and resets the error boundary, while reset only clears the boundary UI and leaves the stale loader error in place.