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

Object Partners profile.
Leave a Reply

Your email address will not be published.

Related Blog Posts
Natively Compiled Java on Google App Engine
Google App Engine is a platform-as-a-service product that is marketed as a way to get your applications into the cloud without necessarily knowing all of the infrastructure bits and pieces to do so. Google App […]
Building Better Data Visualization Experiences: Part 2 of 2
If you don't have a Ph.D. in data science, the raw data might be difficult to comprehend. This is where data visualization comes in.
Unleashing Feature Flags onto Kafka Consumers
Feature flags are a tool to strategically enable or disable functionality at runtime. They are often used to drive different user experiences but can also be useful in real-time data systems. In this post, we’ll […]
A security model for developers
Software security is more important than ever, but developing secure applications is more confusing than ever. TLS, mTLS, RBAC, SAML, OAUTH, OWASP, GDPR, SASL, RSA, JWT, cookie, attack vector, DDoS, firewall, VPN, security groups, exploit, […]