Skip to main content

SSR Streaming

TanStack Start supports streaming Server-Side Rendering (SSR), enabling progressive rendering of your application while data loads. This improves perceived performance by showing content to users faster.

What is SSR Streaming?

SSR Streaming sends HTML to the browser progressively as it’s generated, rather than waiting for the entire page to render. Benefits include:
  • Faster Time to First Byte (TTFB): Users see content sooner
  • Progressive Enhancement: Critical content loads first, deferred content follows
  • Better User Experience: Loading states are more natural and responsive
  • Optimal Resource Utilization: Server and client work in parallel

How It Works

TanStack Start streams the initial HTML shell, then progressively hydrates deferred data as it becomes available. The framework automatically handles the complexity of streaming serialization.

Basic Streaming Setup

1

Configure Stream Handler

In your server entry file, use the streaming handler:
The defaultStreamHandler automatically enables streaming for your entire application.
2

Stream Data from Server Functions

Return ReadableStream from server functions to stream data:
3

Consume Streams in Components

Use the streamed data in your React components:

Async Generator Functions

Use async generators for cleaner streaming code:

Deferred Data Loading

Defer non-critical data to improve initial page load:

Streaming with Suspense

Combine streaming with React Suspense for declarative loading states:

Multiplexed Streams

Stream multiple data sources simultaneously:

Error Handling in Streams

Handle errors gracefully during streaming:

Performance Optimization

Chunk Size Control

Control how much data is sent in each chunk:

Backpressure Handling

Handle slow consumers gracefully:

Best Practices

  • Stream critical content first: Prioritize above-the-fold content
  • Use typed streams: Define schemas for streamed data chunks
  • Handle errors: Always implement error handling in streams
  • Monitor performance: Track streaming metrics in production
  • Test with slow connections: Verify behavior on poor networks
  • Implement timeouts: Set reasonable timeouts for stream operations
  • Use Suspense boundaries: Isolate streaming components
  • Cancel streams: Clean up streams when components unmount

Learn More