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
Feature Flags in Terraform
Feature flagging any code can be useful to developers but many don’t know how to or even that you can do it in Terraform. Some benefits of Feature Flagging your code You can enable different […]
Infrastructure as Code – The Wrong Way
You are probably familiar with the term “infrastructure as code”. It’s a great concept, and it’s gaining steam in the industry. Unfortunately, just as we had a lot to learn about how to write clean […]
Snowflake CI/CD using Jenkins and Schemachange
CI/CD and Management of Data Warehouses can be a serious challenge. In this blog you will learn how to setup CI/CD for Snowflake using Schemachange, Github, and Jenkins. For access to the code check out […]
How to get your pull requests approved more quickly
TL;DR The fewer reviews necessary, the quicker your PR gets approved. Code reviews serve an essential function on any software codebase. Done right, they help ensure correctness, reliability, and maintainability of code. On many teams, […]