TanStack Start logo

TanStack Start

The full-stack React framework built on TanStack Router, offering end-to-end type safety and RPC-style server functions.

npm install tanstack-start
12.4K3/weekv1.0.0210 BISC448 issues
Last updated: 2024-12-12
Star history chart for tanstack/router

TL;DR

A modern full-stack framework that elevates the router to be the central nervous system of your application.

Built on Vite and TanStack Router, it provides 100% type-safe data fetching, server functions, and navigation out of the box.

Why TanStack Start?

TanStack Start represents a paradigm shift where "The Router is the Framework." While Next.js and Remix manage routing as a file-system convenience, TanStack Start treats the router as the core state manager for the entire application. It leverages the immense power of TanStack Router to handle search params, caching, and loaders, while adding a server layer powered by Vinxi (the same engine behind SolidStart).

  • End-to-End Type Safety: This is not a buzzword here. From your database call in a Server Function to the prop in your component, types flow automatically without code generation or manual bridging.
  • Server Functions (RPC): Instead of creating REST endpoints or GraphQL resolvers, you define functions that run on the server and call them directly from your client components. The framework handles the serialization and network transport.
  • Smart Caching & Invalidation: Since it's built on TanStack Router, it inherits sophisticated "stale-while-revalidate" caching logic, automatic garbage collection, and precise invalidation keys.
  • Full-Stack Search Params: Validated, typed search parameters (URL query strings) are first-class citizens, usable in loaders and components with zero effort.
  • Streamlined Build: Powered by Vite, offering instant dev server startups and optimized production builds.

Code Snippet

TanStack Start combines route definitions with server-side loaders. Notice how the loader runs on the server, but the data is typed automatically in the component.

import { createFileRoute } from '@tanstack/react-router'
import { createServerFn } from '@tanstack/start'
import { db } from '@/utils/db'

// 1. Define a Server Function (RPC)
// This code NEVER leaks to the client bundle
const getPost = createServerFn('GET', async (postId: string) => {
  const post = await db.post.findUnique({ where: { id: postId } })
  return post
})

export const Route = createFileRoute('/posts/$postId')({
  // 2. The Loader calls the Server Function
  // It runs before the route loads, ensuring data is ready
  loader: async ({ params }) => {
    return await getPost(params.postId)
  },
  // 3. The Component receives fully typed data
  component: PostComponent,
})

function PostComponent() {
  const post = Route.useLoaderData()
  return (
    <div>
      <h1>{post.title}</h1>
      <p>{post.content}</p>
    </div>
  )
}

Pros and Cons

No library is perfect; understanding the trade-offs is key to selecting the right tool.

Pros

  • DX & TypeScript: The type inference is unmatched. Changing a server return type instantly causes a type error in the UI component using it, providing incredible refactoring confidence.
  • State Management: It effectively eliminates the need for global state managers (like Redux/Zustand) for server state, as the Router handles caching and distribution.
  • Search Param Handling: It has the best search parameter API in the ecosystem, treating URL state as structured, typed data rather than just strings.

Cons

  • Maturity: As a newer entrant compared to Next.js, edge cases, deployment recipes for niche hosts, and third-party integrations are less documented.
  • Learning Curve: The "Router-First" mental model, especially regarding how loaders and search params work, is steeper than the simple "fetch in useEffect" or getServerSideProps models.
  • Ecosystem Size: While you can use React packages, specific "TanStack Start" plugins are scarce compared to the vast Next.js plugin ecosystem.

Comparison with Other Frameworks

The table below outlines the positioning differences between TanStack Start and other popular meta-frameworks:

LibraryDesign PhilosophyBest ForPain Points
TanStack StartType-Safety First
Router-centric architecture with RPC server functions.
Complex Apps
Dashboards and SaaS apps requiring strict type safety and complex URL state.
New Ecosystem
Fewer tutorials, StackOverflow answers, and hosting presets than competitors.
Next.jsEcosystem First
The default standard. Supports RSC, SSR, SSG, and everything in between.
General Purpose
Everything from marketing sites to massive e-commerce platforms.
Complexity
The app router caching model and RSC constraints can be confusing and hard to debug.
RemixWeb Standards
Focus on HTTP standards, progressive enhancement, and forms.
Data Heavy Apps
Applications that rely heavily on mutations and standard browser behavior.
Type Loose
Type safety often requires manual casting or helper libraries compared to Start's native inference.

Verdict: When to Adopt

Adopt TanStack Start if you are starting a new SaaS product or dashboard where TypeScript is non-negotiable and you want the best possible Developer Experience (DX) regarding data flow. It is the spiritual successor to the "Single Page App" but with the SEO and performance benefits of SSR. If you need a massive existing ecosystem or React Server Components (RSC) right now, stick with Next.js.