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.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 theunstable_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: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: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
- Use server components by default: Opt into client components
- Keep client components small: Minimize client bundle
- Use “use server” for actions: Clear server function boundary
- Don’t import server code in client: Use separate files
- 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
- Mark interactive components with “use client”
- Move server logic to server components
- Convert form actions to server actions
- Update routing to RSC config
- Test both client and server rendering