Simplifying Server Components

Spanish audio is available in the player settings
Rate this content
Bookmark

Server Components are arguably the biggest change to React since its initial release but many of us in the community have struggled to get a handle on them. In this talk we'll try to break down the different moving parts so that you have a good understanding of what's going on under the hood, and explore the line between React and the frameworks that are built upon it.

FAQ

Mark Dalglish is a professional who has been working in the React space for a decade, focusing on areas like design systems, CSS modules, and server-side rendering capabilities within React. He is currently involved with the Remix team at Shopify.

Mark Dalglish was initially attracted to React due to its server-side rendering capabilities, which he found fundamentally different and more effective compared to other technologies he had used in web development.

React server components represent a shift in how React is thought about and used. They allow for server-side operations only, which simplifies certain aspects of building applications but also introduces new architectural considerations and challenges.

Server components in React are components that run only on the server side. They allow developers to render more efficiently by offloading certain tasks from the client to the server, thus improving performance and SEO capabilities while maintaining rich interactivity.

The main benefits of using server components in React include enhanced performance through reduced client-side load, improved initial load times, and better SEO since the server can directly render HTML content that is crawlable by search engines.

Developers might find it intimidating to work with React server components due to their different architectural implications. There is a need to rethink application structure, manage framework integrations, and understand new deployment and debugging strategies.

While specific tools for debugging React server components were not detailed, the complexity and newness of the technology imply that traditional React debugging tools may need adjustments or enhancements to handle server-side components effectively.

Mark Dalgleish
Mark Dalgleish
27 min
20 Oct, 2023

Comments

Sign in or register to post your comment.

Video Summary and Transcription

React server components simplify server-side rendering and provide a mental model of components as pure functions. Using React as a library for server components allows for building a basic RSC server and connecting it to an SSR server. RSC responses are serialized virtual DOM that offload code from the client and handle interactivity. The client manifest maps serialized placeholders to real components on the client, enabling dynamic rendering. Server components combine the best of classic web development and progressive enhancement, offering the advantage of moving logic from the client to the server.

1. Introduction to React Server Components

Short description:

My name is Mark Dalglish, and I'm here all the way from Melbourne, Australia. I've been working in the React space for a decade, with a focus on server-side rendering and progressive enhancement. Currently, I'm working on the Remix team at Shopify. React server components have piqued my interest, but they initially seemed intimidating. However, I've always had a simple mental model of how React works, with components being pure functions that describe what should be on the screen. JSX is just function calls. Early on, it was strange to return HTML elements from JavaScript functions.

So, as you heard, my name is Mark Dalglish, and I'm here all the way from Melbourne, Australia, which means it took me 21 hours of flying to get here. So, thank you so much for having me. It's a pleasure to be here in London.

Now, I've been working in the React space, can you believe it, for a decade at this point. I only realized as I was preparing for this talk. Now, some of you, as you heard, may be familiar with my work in React in terms of design system space, CSS modules, vanilla, Extract, design systems, but going back to why I got started in React in the first place, it was actually its server-side rendering capabilities that really sold me on React being fundamentally different to everything I'd used before, not just in the JavaScript space, but in web development in general. And for me, the really exciting part of it was that finally I got to bridge the gap between what we were trying to do with rich client-side interactivity in JavaScript, while also maintaining the progressive enhancement that up until that point, up until the push for JavaScript on the client, progressive enhancement had long been a value in the web space, and now React let me get the best of both worlds and solve some very real problems that I had at work at that time, trying to have rich client-side interactivity, while also having that first load page performance, as well as importantly, SEO support for Google for us at that time. So that work, that background for me in server-side rendering is what's ultimately led me to my current full-time work on the Remix team at Shopify, working really hard to make that progressive enhancement experience a reality for all of you.

So it's with, it's in that context that I'm sure it's no surprise to you that I'm very interested in React server components, because it's such a big shift in terms of how we think about React. But I have to admit that when I first looked at server components, I found them quite intimidating. Not at a high-level API perspective, but more from the sense that it I had less of an idea of how I'm supposed to think about the architecture of my application, what's the implications on how I think about and build my apps, how does it even work, and especially if I'm in a framework context, what does it mean to build a framework on top of server components? There are a lot of open questions, and people I respected that knew a lot about React were also struggling with this question. To me, this was in stark contrast to my experience with React up until that point, because I found that, generally, I was always able to have a very simple mental model of how React worked. For example, if I had my app component that we're all used to working with, I could render it to an element on the screen, but equally, I could take that same application component, and I could render it to a string of HTML on the server. This is what got me interested in React in the first place. And to me, this mental model was nice and simple. When it came to rendering a component, of course, early on, the natural question would be what is a component, given every framework has a different take on what that sort of concept might mean. And what was interesting in React is that the answer was nice and simple, is that conceptually components are basically pure functions that just described what should be on the screen at that given time. So in the early days of React, we didn't have functional components. We had React.create class, and it would have a render method, among other properties on that object. And inside of that method, we would have access to this.props on the instance of the component. So it's a very different API. But if you squint, it kind of felt like working with a pure function. And that's how I described it to people who were new to React. And funnily enough, that ended up being the API we deal with today. They literally are functions now. And, of course, our components are going to be rendering JSX and the question then would be what is JSX? For many of us, especially in those early days, it was a very interesting question to have to deal with, but the answer was quite simple. It's that JSX is just function calls. That's just the way you had to think about it. So when we saw code like this that, again, in the early days of React, for many of us, it was almost heretical that we would be returning HTML elements from our JavaScript functions. It almost made no sense to us.

2. Understanding Server Components

Short description:

When it was explained to us that JSX is just function calls, it became straightforward. However, the simple answer of server components being components that only run on the server is not sufficient. I want to simplify server components and provide a good mental model of how they work beyond the high-level APIs.

But when it was explained to us that it's really just a syntax sugar for writing code like this where you're just calling a function, passing in some arguments to describe what element you want, the element type, the props, the children, it was quite straightforward.

So now that brings us to the latest question in React, which is what are server components? Seems like a straightforward enough question. And the simple answer that people tend to reach for, I've found, is something along the lines of this where you say server components are components that only run on the server.

Now, the problem I have with this as an answer, beyond the fact that it's basically just rearranging the words of the question, is that it leaves me with no mental model for how they work, what are the constraints or tradeoffs, what does that mean for my architecture, what can I do, what can't I do with them, how do I use them at an API level from React? So I had very little to work with here. So the goal here for my talk is to help do to you what I had to work to achieve which is simplifying server components. Hopefully not oversimplifying them but simplifying them enough so you have a good mental model of how they work beyond the high-level APIs that you might write to generate server components.

QnA

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Exploring React Server Component Fundamentals
React Day Berlin 2023React Day Berlin 2023
21 min
Exploring React Server Component Fundamentals
Top Content
I've been developing a minimalistic framework for React Server Components (RSC). This talk will share my journey to deeply understand RSC from a technical perspective. I'll demonstrate how RSC features operate at a low level and provide insights into what RSC offers at its core. By the end, you should have a stronger mental model of React Server Components fundamentals.
Server Components: The Epic Tale of Rendering UX
React Summit 2023React Summit 2023
26 min
Server Components: The Epic Tale of Rendering UX
Server components, introduced in React v18 end these shortcomings, enabling rendering React components fully on the server, into an intermediate abstraction format without needing to add to the JavaScript bundle. This talk aims to cover the following points:1. A fun story of how we needed CSR and how SSR started to take its place2. What are server components and what benefits did they bring like 0 javascript bundle size3. Demo of a simple app using client-side rendering, SSR, and server components and analyzing the performance gains and understanding when to use what4. My take on how rendering UI will change with this approach
A Practical Guide for Migrating to Server Components
React Advanced Conference 2023React Advanced Conference 2023
28 min
A Practical Guide for Migrating to Server Components
Server Components are the hot new thing, but so far much of the discourse around them has been abstract. Let's change that. This talk will focus on the practical side of things, providing a roadmap to navigate the migration journey. Starting from an app using the older Next.js pages router and React Query, we’ll break this journey down into a set of actionable, incremental steps, stopping only when we have something shippable that’s clearly superior to what we began with. We’ll also discuss next steps and strategies for gradually embracing more aspects of this transformative paradigm.
Batteries Included Reimagined - The Revival of GraphQL Yoga
GraphQL Galaxy 2021GraphQL Galaxy 2021
33 min
Batteries Included Reimagined - The Revival of GraphQL Yoga
The Guild has recently released Envelop - a new, modern GraphQL Server Framework and plugin system. In this talk I’ll share a brief overview of Envelop and why you should probably upgrade your existing GraphQL server to it.
React Server Components
React Day Berlin 2023React Day Berlin 2023
27 min
React Server Components
React Server Components are a newer way of working with React that is widely adopted in frameworks like Next.js. In this talk, we will look under the surface of how they work and are executed on the server side, and how they fit with server rendering and traditional React apps.

Workshops on related topic

Next.js 13: Data Fetching Strategies
React Day Berlin 2022React Day Berlin 2022
53 min
Next.js 13: Data Fetching Strategies
Top Content
WorkshopFree
Alice De Mauro
Alice De Mauro
- Introduction- Prerequisites for the workshop- Fetching strategies: fundamentals- Fetching strategies – hands-on: fetch API, cache (static VS dynamic), revalidate, suspense (parallel data fetching)- Test your build and serve it on Vercel- Future: Server components VS Client components- Workshop easter egg (unrelated to the topic, calling out accessibility)- Wrapping up
React Server Components Unleashed: A Deep Dive into Next-Gen Web Development
React Advanced Conference 2023React Advanced Conference 2023
153 min
React Server Components Unleashed: A Deep Dive into Next-Gen Web Development
Workshop
Maurice de Beijer
Maurice de Beijer
Get ready to supercharge your web development skills with React Server Components! In this immersive, 3-hour workshop, we'll unlock the full potential of this revolutionary technology and explore how it's transforming the way developers build lightning-fast, efficient web applications.
Join us as we delve into the exciting world of React Server Components, which seamlessly blend server-side rendering with client-side interactivity for unparalleled performance and user experience. You'll gain hands-on experience through practical exercises, real-world examples, and expert guidance on how to harness the power of Server Components in your own projects.
Throughout the workshop, we'll cover essential topics, including:
- Understanding the differences between Server and Client Components- Implementing Server Components to optimize data fetching and reduce JavaScript bundle size- Integrating Server and Client Components for a seamless user experience- Strategies for effectively passing data between components and managing state- Tips and best practices for maximizing the performance benefits of React Server Components
Workshop level: 
No matter your current level of React expertise, this workshop will equip you with the knowledge and tools to take your web development game to new heights. Don't miss this opportunity to stay ahead of the curve and master the cutting-edge technology that's changing the face of web development. Sign up now and unleash the full power of React Server Components!
Build a Custom Storefront on Shopify with Hydrogen
React Advanced Conference 2021React Advanced Conference 2021
170 min
Build a Custom Storefront on Shopify with Hydrogen
Workshop
Matt Seccafien
Cathryn Griffiths
2 authors
Hydrogen is an opinionated React framework and SDK for building fast, custom storefronts powered Shopify. Hydrogen embraces React Server Components and makes use of Vite and Tailwind CSS. In this workshop participants will get a first look at Hydrogen, learn how and when to use it, all while building a fully functional custom storefront with the Hydrogen team themselves.
Build a Product Page with Shopify’s Hydrogen Framework
React Advanced Conference 2022React Advanced Conference 2022
81 min
Build a Product Page with Shopify’s Hydrogen Framework
WorkshopFree
David Witt
David Witt
Get hands on with Hydrogen, a React-based framework for building headless storefronts. Hydrogen is built for Shopify commerce with all the features you need for a production-ready storefront. It provides a quick start, build-fast environment so you can focus on the fun stuff - building unique commerce experiences. In this workshop we’ll scaffold a new storefront and rapidly build a product page. We’ll cover how to get started, file-based routing, fetching data from the Storefront API, Hydrogen’s built-in components and how to apply styling with Tailwind.You will know:- Get started with the hello-world template on StackBlitz- File-based routing to create a /products/example route- Dynamic routing /products/:handle- Hit the Storefront API with GraphQL- Move the query into the Hydrogen app- Update the query to fetch a product by handle- Display title, price, image & description.- Tailwind styling- Variant picker and buy now button- Bonus if there’s time: Collections page
Prerequisites: - A Chromium-based browser (StackBlitz)- Ideally experience with React. A general web development background would be fine.