Skip to main content

React Server Components

React Router provides experimental support for React Server Components (RSC), enabling you to render components on the server and stream them to the client.
RSC support in React Router is experimental and APIs may change. Not recommended for production use.

Overview

React Server Components allow you to:
  • Render components on the server
  • Stream components to the client
  • Access server-only resources (databases, file system)
  • Reduce client bundle size
  • Improve initial page load

Setup

RSC Framework Mode

Use the unstable_reactRouterRSC plugin:

RSC Data Mode

Manual setup with runtime APIs:

Server Components

Components that render on the server:

Client Components

Mark components for client rendering:

Mixing Server and Client

Compose server and client components:

Server Actions

Call server functions from client:
Use in client components:

Streaming

Stream components as they render:

Route Configuration

Define routes with RSC:

Loaders with RSC

Loaders still work alongside RSC:

Client Loaders

Augment server data on client:

Browser Entry

Set up RSC in the browser:

Server Entry

Handle RSC requests on the server:

Route Discovery

Routes are discovered lazily or eagerly:
Eager: Discovers routes as links appear in DOM
Lazy: Discovers routes when clicked

Data Strategy

RSC uses a special data strategy for single-fetch:

Error Boundaries

Handle errors in RSC:

Hydration Fallback

Show loading state during hydration:

Server-Only Code

Ensure code only runs on server:

Client-Only Code

Ensure code only runs on client:

HMR with RSC

Hot Module Replacement works with RSC:

Best Practices

  1. Use server components by default: Opt into client components
  2. Keep client components small: Minimize client bundle
  3. Use “use server” for actions: Clear server function boundary
  4. Don’t import server code in client: Use separate files
  5. Stream when possible: Use Suspense boundaries

Limitations

  • Experimental API, subject to change
  • Requires React 19+
  • Not all React features supported in server components
  • Cannot use hooks in server components
  • Client components cannot be async

Example App Structure

Migration from Traditional SSR

  1. Mark interactive components with “use client”
  2. Move server logic to server components
  3. Convert form actions to server actions
  4. Update routing to RSC config
  5. Test both client and server rendering