Skip to main content
TanStack Start provides powerful server-side rendering (SSR) capabilities that allow your application to render HTML on the server before sending it to the client. This improves initial page load performance, SEO, and enables progressive enhancement.

How Server Rendering Works

When a request arrives at your server, TanStack Start follows this flow:
  1. Request Handler: The createStartHandler receives the incoming request
  2. Router Initialization: A router instance is created with memory history for the requested URL
  3. Route Matching: The router matches the URL path to your route definitions
  4. Data Loading: Route loaders execute on the server to fetch data
  5. Component Rendering: React components render to HTML string or stream
  6. Hydration Data: Serialized state is embedded in the HTML for client hydration

Rendering Modes

TanStack Start supports two rendering approaches:

String Rendering

Renders the entire HTML as a string before sending the response. Best for static pages or when you need the complete HTML immediately.
Internally, this uses renderRouterToString from @tanstack/react-router/ssr/server:

Stream Rendering

Streams HTML to the client as it renders, allowing the browser to start processing content before the entire page is ready. This is the recommended approach for better perceived performance.
Internally, this uses renderRouterToStream:

SSR Configuration

Control SSR behavior per route or globally:

Per-Route SSR Control

app/routes/index.tsx

Disable SSR for Specific Routes

app/routes/dashboard.tsx

Global SSR Configuration

Set default SSR behavior for all routes:
app/start.ts

The StartServer Component

The <StartServer> component wraps your router on the server:
This component:
  • Renders the <RouterProvider> with the server router instance
  • Manages SSR-specific context and state
  • Coordinates with the serialization system

Server-Side Data Loading

Route loaders execute on the server during SSR:
app/routes/posts.$postId.tsx
The loader data is:
  1. Fetched on the server
  2. Serialized and embedded in the HTML
  3. Available immediately on the client without refetching

Hydration

After the server sends HTML, the client “hydrates” the page:
app/client.tsx
During hydration:
  1. The client router reads serialized state from the HTML
  2. React attaches event listeners to the server-rendered HTML
  3. The app becomes interactive without re-rendering

Request Context

Access request information during SSR:

Response Headers

Set response headers during SSR:

Asset Manifest

TanStack Start automatically generates an asset manifest during build that includes:
  • JavaScript module preloads
  • CSS stylesheets
  • Client entry script
The manifest is resolved per request in createStartHandler:
This ensures only the assets needed for the current route are loaded.

Error Handling

Handle errors during SSR:

Best Practices

Stream rendering (defaultStreamHandler) provides better perceived performance by sending content as it renders:
Keep loaders fast and focused. Use parallel loading when possible:
Use conditional logic for server-only code:
Use response headers to control caching:

Streaming

Learn how to stream content progressively

Server Functions

Execute server-side logic from client components

Deployment

Deploy your SSR application to production

SSR Guide

Complete guide to SSR and streaming