
In a surprising turn of events, the React Router team has embraced React Server Components with their recent preview release. This development marks a significant shift in the React ecosystem, especially considering the team's previous stance on server components. Let's explore what this means for developers and how server components work within React Router.
Understanding React Server Components in React Router
React Server Components represent a paradigm shift in how React applications are built, allowing components to run exclusively on the server while seamlessly integrating with client components. The React Router implementation provides a straightforward way to leverage this technology within familiar routing patterns.

The basic implementation showcases fast navigation between pages, server-side data loading, and server actions that can process form submissions. This approach combines the benefits of server-side rendering with the interactivity of client-side React applications.
Implementation Architecture
The architecture of React Server Components in React Router consists of several key components:
- An Express server that imports React Router via a virtual import
- Server-side routing handled by a root.ts file
- A root.tsx file containing layout components and middleware
- Server components exported using a specific convention
- Integration of server actions for form handling
The entire setup is built on Parcel instead of Vite, as Vite doesn't yet support server components. This architecture enables server-side routing, which differs from React Router's traditional client-side approach.
Server Components vs. Client Components
In this implementation, developers need to understand the distinction between server components and client components. Server components are rendered on the server and can directly access server resources like databases or file systems. They're exported using a specific convention rather than as default exports.
// Server component export convention
export function ServerComponent() {
// Component code that runs on the server
return <div>Server rendered content</div>;
}
Client components, on the other hand, are explicitly marked and only render in the browser. They're ideal for interactive elements that require client-side JavaScript.
// Client component
'use client';
export function PendingButton() {
// Interactive component that runs in the browser
return <button>Click me</button>;
}
Working with Server Actions
One of the most powerful features of this implementation is server actions, which allow forms to submit data directly to server-side functions. These actions are marked with the 'use server' directive to indicate they only run on the server.

// Server action example
'use server';
export async function serverAction(formData) {
const name = formData.get('name');
console.log('Server received:', name);
return { name };
}
These server actions can be integrated with forms to create interactive experiences that process data on the server without requiring a full API implementation.
Data Loading with Loaders
Similar to traditional React Router, this implementation supports loaders that run before components are rendered. In the server components context, these loaders run on the server and can fetch data that will be available to the component.
// Loader example
export async function loader({ request }) {
// Access to context from middleware
const context = request.context;
return {
message: context.text,
name: getNameFromForm() // Custom function to retrieve form data
};
}
Middleware for Context and Caching
The implementation includes middleware support in the root file, which can be used for batching, caching, and providing context to routes. This creates a powerful system for managing shared data and optimizing performance.
// Middleware example
export const middleware = unstable_createMiddleware(async (request) => {
console.log('Middleware running...');
// Provide context to all routes
const response = await unstable_provide(
request,
new Map([[context, { text: 'Hello World' }]])
);
return response;
});
Implications for Remix and the Future

While React Router embraces server components, it appears that Remix (from the same team) is taking a different direction. According to available information, Remix is unlikely to support server components and may be developing its own renderer instead of relying on React, citing complexity concerns.
This divergence creates an interesting situation where developers may need to choose between React Router with server components or Remix with its custom approach. More details about Remix's future direction are expected to be announced at upcoming events.
Getting Started with React Router Server Components
For developers interested in exploring this technology, there are already sample projects available that demonstrate the implementation. While the current version is in preview and not yet ready for production, it shows promise for creating efficient, server-rendered React applications with the familiar React Router API.
- Set up a Parcel-based project (Vite doesn't support server components yet)
- Configure an Express server to handle React Router
- Create server components using the proper export convention
- Implement server actions for form processing
- Use middleware for context and caching as needed
While this preview implementation has limitations and is not yet production-ready, it represents a significant step forward in the React ecosystem. Developers interested in server components now have a familiar routing solution to explore this technology with.
Conclusion
React Router's embrace of server components marks an important evolution in the React ecosystem. While still in preview, this implementation provides a glimpse into how traditional React applications might evolve to leverage server-side rendering capabilities without sacrificing the component model that makes React so powerful.
As the technology matures, we can expect more robust tooling, better documentation, and production-ready implementations. For now, developers interested in the cutting edge of React development have an exciting new approach to explore with React Router's server components preview.
Let's Watch!
React Router Now Supports Server Components: What Developers Need to Know
Ready to enhance your neural network?
Access our quantum knowledge cores and upgrade your programming abilities.
Initialize Training Sequence