tanstack-frontend
TanStack Frontend Patterns
Overview
Implement TanStack Router routes with project-standard TRPC integration, loader strategy, typed inference, and form handling. Follow this document for decision rules, then use references/ for full examples.
Core Patterns
1) Define routes with loader-driven data strategy
- Define each route with
createFileRoute(...)and a loader that preloads critical data. - Read params/search from route APIs (
Route.useParams(),Route.useSearch()) in components. - Keep examples in
references/router-loader-examples.md.
2) Choose loader prefetch strategy intentionally
- Use
await prefetchQuery(...)for data required in first paint. - Use
await Promise.all([...])for multiple critical queries. - Use
void prefetchQuery(...)only for secondary data. - Use
fetchQuery(...)when loader logic needs returned data. - Apply the
voidrule together with the Suspense rule below.
See full decision trees and performance tradeoffs in references/prefetch-patterns.md.
3) Enforce Suspense boundaries for void-prefetched data
- Wrap every component that consumes
void prefetchQuery(...)data viauseSuspenseQuery(...)in<Suspense>. - Treat missing boundaries as correctness bugs (hydration risk), not optional optimization.
- Cross-check any
voiddecision against this requirement before finalizing the route.
See examples and the loader-pattern decision table in references/prefetch-patterns.md.
4) Apply TRPC v11 TanStack Query pattern
Use one rule block consistently:
- Use TanStack Query hooks (
useQuery,useSuspenseQuery,useMutation) with TRPC factory methods. - Use
.queryOptions(...)for queries/prefetch and.mutationOptions(...)for mutations. - Use
.queryKey(...)for cache invalidation. - Do not call
.useQuery()or.useMutation()on TRPC procedures.
See concise do/don't examples in references/trpc-v11-query-pattern.md.
5) Prefer RouterInputs/RouterOutputs for inference
- Prefer
RouterInputs/RouterOutputsfor input/response typing across route components and helpers. - Allow explicit local types when they represent UI-only view models, external library contracts, or deliberate narrowing/aggregation that does not mirror server payloads.
- Avoid duplicating raw TRPC response shapes as hand-written app types.
See practical inference patterns in references/type-inference.md.
6) Use the project form wrapper (not raw TanStack Form)
- Treat "TanStack Form" in this template as
useAppForm+@/shared/forms/*field components. - Compose forms with shared form components and pass
form/fieldexplicitly. - Avoid raw TanStack Form hooks in feature code unless updating the shared form infrastructure itself.
See complete form patterns in references/form-patterns.md.
7) Follow frontend conventions
- Prefer
type Props = ...naming for component props. - Use absolute imports (
@/...). - Import shared cross-package types from
@project/common. - Invalidate TRPC cache through
queryKey(...)helpers.
Resources
references/
router-loader-examples.md- Complete route definition examplesprefetch-patterns.md- Performance optimization and prefetch strategiestrpc-v11-query-pattern.md- Compact TRPC v11 query/mutation/invalidation rulesform-patterns.md- Form handling with validation examplestype-inference.md- TRPC type inference patterns and examples
More from blogic-cz/blogic-marketplace
marketing-expert
This skill should be used when writing or rewriting marketing copy for software products, including positioning, messaging, homepage rewrite work, landing pages, product descriptions, conversion-focused updates, and sales-enablement content. Produces clear, truthful, high-performing SaaS copy.
97requirements
This skill should be used when clarifying a feature, writing a requirements spec, running a structured discovery session, or when users mention requirements-start, requirements-status, requirements-current, requirements-list, requirements-remind, or requirements-end.
78frontend-design
This skill should be used when a task requires designing or implementing frontend UI (components, pages, layouts, styling) and no more specialized frontend skill is a better fit. It guides production-grade, brand-consistent visual implementation with distinctive but controlled aesthetics.
77testing-patterns
This skill should be used when implementing or reviewing testing workflows in template-ts projects, especially for testing, Vitest, Playwright, integration test, and mocking scenarios.
76git-workflow
Automates the full PR lifecycle — create or update a pull request, then aggressively monitor CI checks and review feedback in a continuous loop, fixing failures and addressing comments until the PR is fully green. Also covers push, branch creation, and branch sync workflows.
76debugging-with-opensrc
Load this skill when debugging behavior in external libraries by reading local OpenSrc mirrors (Effect, TanStack, TRPC, Drizzle, Better Auth, Sentry, Pino), or when docs conflict with runtime behavior and source-level verification is required.
75