React Server Components

The React Team recently announced new work they are doing on React Server Components, a new way of rendering React components. The goal is to create smaller bundle sizes, speed up render time, and prevent network “waterfall”. RSCs differ from Server Side Rendering as we’ll see.

What are React Server Components?

The introduction of RSC splits React components into three categories.

  • Server Components
  • Client Components
  • Shared Components

Server Components specifically are denoted by a .server.js extension and follow these criteria per the React Team’s RFC. The most notable among these are that Server Components can access server-side data sources, such as databases, files systems, or (micro)services resulting in faster reads and rendering.

How is this different from SSR (Server Side Rendering)?

The rendering of Server Components differs from SSR in that they are not rendered as HTML, but as special format that’s streamed into the client. This format is similar to JSON but currently has no standard protocol. A response would look something like this

M1: { 
  "id": "./src/SearchField.client.js", 
  "chunks": ["client5"], 
  "name": "" 
}

This allows the Server Components to be re-fetched to re-render data, unlike SSR which only speeds up the initial rendering.

This also reduces client-server network waterfall by handling data loading in the server, fetching the minimal amount of data needed from within the component.

Other types of components

RSC introduces two other categories, Client Components and Shared Components.

Client Components are the traditional components used in the client with React, denoted by a .client.js extension. They can be rendered by Server Components, though they cannot render Server Components and do not access data sources such as databases or file systems.

Shared Components are components that can be used on the client and server. They must all the constraints for both client and server components, as outlined here. They are denoted by a standard .js extension.

Conclusion

React Server Components are an exciting development and may change how developers write React in the future. React Server Components will be rolled out in the future on an experimental basis, integrating first with SSR frameworks like Next.js.

You can find out more by reading the RFC and cloning the demo project. You can also watch the demo video with Dan Abramov and Lauren Tan here

About the Author

Caleb Cowen profile.

Caleb Cowen

Sr Consultant
Leave a Reply

Your email address will not be published. Required fields are marked *

Related Blog Posts
An Exploration in Rust: Musings From a Java/C++ Developer
Why Rust? It’s fast (runtime performance) It’s small (binary size) It’s safe (no memory leaks) It’s modern (build system, language features, etc) When Is It Worth It? Embedded systems (where it is implied that interpreted […]
Getting Started with CSS Container Queries
For as long as I’ve been working full-time on the front-end, I’ve heard about the promise of container queries and their potential to solve the majority of our responsive web design needs. And, for as […]
Simple improvements to making decisions in teams
Software development teams need to make a lot of decisions. Functional requirements, non-functional requirements, user experience, API contracts, tech stack, architecture, database schemas, cloud providers, deployment strategy, test strategy, security, and the list goes on. […]
JavaScript Bundle Optimization – Polyfills
If you are lucky enough to only support a small subset of browsers (for example, you are targeting a controlled set of users), feel free to move along. However, if your website is open to […]