Hydrogen: An Early Look at Server Components in the Wild

Rate this content
Bookmark

Shopify's Hydrogen framework has been released with an early version of React's server components. In this talk I will discuss: * What is Hydrogen? * What are server component and how are we using them? * How are they different than client and shared components? * How are server side rendering and server components different? * I'll also show examples in the wild After the talk I hope the attendees will understand the Hydrogen framework and React server components better.

This talk has been presented at React Advanced Conference 2022, check out the latest edition of this React Conference.

FAQ

Hydrogen is a framework developed by Shopify for building headless storefronts using React 18, server components, and Vita.

The Hydrogen framework is maintained by a team at Shopify.

Server components in React 18 allow developers to send HTML directly from the server to the browser, reducing the client-side bundle size and improving initial load times.

Major merchants using Hydrogen in production include Allbirds, Denim Tears, and Atoms.

A headless storefront was built using Hydrogen by one developer in three months, compared to the average of 12 months.

The advantage of using server components in Hydrogen is that they reduce the client-side bundle size by sending HTML directly from the server, making the site faster and more efficient.

Challenges with server components include compatibility issues with existing libraries, increased data fetching times, and difficulties in debugging due to a lack of tooling.

Suspense in React 18 is a feature that allows developers to wrap heavy components, so they load separately, improving the overall performance and user experience.

Edgeworkers are a new technology that allows server rendering to be done close to the user, resulting in faster load times. Hosting platforms like Shopify's Oxygen leverage Edgeworkers for improved performance.

You can try a demo of the Hydrogen framework at the website addogen.new.

Daniel Rios Pavia
Daniel Rios Pavia
7 min
21 Oct, 2022

Comments

Sign in or register to post your comment.

Video Summary and Transcription

Hydrogen and server components are being used by big merchants in production sites to build headless storefronts quickly. React 18 introduces server components that allow for interactive rendering without adding anything to the bundle. However, not all libraries are compatible and data fetching can slow down the site, but React provides suspense to handle heavy components. Server components offer great encapsulation and fast rendering via HTML, and the future of headless is promising with technologies like Edgeworkers and hosting platforms like Oxygen. Shopify is hiring and offers a demo shop with server components at addogen.new.

1. Introduction to Hydrogen and Server Components

Short description:

I'm here to talk about Hydrogen and an early look at server components. We use React 18, server components, and Vita. We have big merchants using them in production sites. Hydrogen allows you to build a headless storefront quickly. Rendering React used to be simple, but now we have server-side rendering and hydration.

Hello. Hi, everybody. I was not sure. I made so many slides, I had to delete so many to make it a lightning talk.

Anyway, I'm here to talk about Hydrogen and an early look at server components. This is me. I work at Shopify. I am part of the maintainers of this framework, which is made for headless storefronts. What's interesting about the framework is that we use React 18. We use server components and Vita. I want to talk about some of our experiences with server components in the wild. For some references, we already have some big merchants using them in production sites. Allbirds, this is merchants that already get billions. This is another one made with hydrogen. Denim tears. Atoms.

What is curious with hydrogen is that we give components so that you can build really fast this headless storefront. And for example, this one was built with one developer, three months. And in average, it takes around 12 months to do this. So I think that's pretty great. And, yeah. So they are all with server components in the wild.

I wanted to talk about rendering React. It used to be, at the beginning, we used to just have the components. And then we just bundle all together. And then send it to the browser. And then the person sees this white screen for a while until everything gets rendered. At some point, we complicated things, or I don't know, made it more interesting having server-side rendering and hydration. And I guess now what happens is we send a server-rendered version of the site, and then the client bundle. And then we hydrate it.

2. Introduction to React 18 and Server Components

Short description:

And then it becomes interactive, but still kind of awkward. We use React 18, which gives you three components: server, client, and shared. The cool thing about server components is that you don't add anything to the bundle. We still need interactivity, so we use server components for specific tasks. However, not all libraries are compatible, and data fetching can slow down the site. React provides suspense to handle heavy components.

And then it becomes interactive, but still kind of awkward. And I guess what we would like to have, especially for commerce sites, is something more like this, right? It opens, and I can buy immediately.

So right, that's why we are using React 18. React 18 gives you three components now. The server ones. Client and shared. And the client components is what we kind of already do, right? We use state, and we do this, I don't know, these functions. And they get sent to the browser. They get rendered there. Except with all the iteration stuff that I talked about that is, you know, all the magic. The new ones are server components, and these are very interesting because you do the same thing as client components. But the end result is that this is HTML that gets sent directly. And the final one is shared components. Which is something that could be in the client, or in the server as well. But I think the main thing I want to talk about is client and server components.

The cool thing about server components is that you don't add anything to the bundle. So you just send HTML directly. The way we use them in Hydrogen is we build them normally, like any other component, but we also do queries to the database. And then we put them in the components, and the end result is just send HTML directly to the browser. So why don't we use server components for everything? Because we still need interactivity. If I want to buy a different amount of products, I want to be able to choose that and do a server render. Because of that, it's maybe too much. Just some of our learnings has been that, as we roll out server components, not all libraries out there are compatible. So that's one issue that we've had. So sometimes you have to mingle around to try to make them work. A second learning is that, as soon as we gave server components to people, they started to do a lot of data fetching. This could take long, and then people are like, OK, is the server components supposed to make my site faster, but actually slower? But it's because we are data fetching a lot of stuff. So something that Reacting is giving is suspense. So what you would do is wrap this component that's very heavy in suspense, and the result is, for example, in this example here, everything is rendered, but that little part that might be a bit heavy gets later rendered and served. They are still hard to debug.

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

Simplifying Server Components
React Advanced Conference 2023React Advanced Conference 2023
27 min
Simplifying Server Components
Top Content
Watch video: Simplifying Server Components
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.
Exploring React Server Component Fundamentals
React Day Berlin 2023React Day Berlin 2023
21 min
Exploring React Server Component Fundamentals
Top Content
Watch video: Exploring React Server Component Fundamentals
This Talk introduces React Server Components (RSC) and explores their serialization process. It compares RSC to traditional server-side rendering (SSR) and explains how RSC handles promises and integrates client components. The Talk also discusses the RSC manifest and deserialization process. The speaker then introduces the Waku framework, which supports bundling, server, routing, and SSR. The future plans for Waku include integration with client state management libraries.
And Now You Understand React Server Components
React Summit 2024React Summit 2024
27 min
And Now You Understand React Server Components
Top Content
In this Talk, Kent C. Dodds introduces React Server Components (RSCs) and demonstrates how to build them from scratch. He explains the process of integrating RSCs with the UI, switching to RSC and streaming for improved performance, and the benefits of using RSCs with async components. Dodds also discusses enhancements with streaming and server context, client support and loaders, server component rendering and module resolution, handling UI updates and rendering, handling back buttons and caching, and concludes with further resources for diving deeper into the topic.
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
Top Content
Watch video: A Practical Guide for Migrating to Server Components
React query version five is live and we'll be discussing the migration process to server components using Next.js and React Query. The process involves planning, preparing, and setting up server components, migrating pages, adding layouts, and moving components to the server. We'll also explore the benefits of server components such as reducing JavaScript shipping, enabling powerful caching, and leveraging the features of the app router. Additionally, we'll cover topics like handling authentication, rendering in server components, and the impact on server load and costs.
Server Components: The Epic Tale of Rendering UX
React Summit 2023React Summit 2023
26 min
Server Components: The Epic Tale of Rendering UX
Top Content
Watch video: Server Components: The Epic Tale of Rendering UX
This Talk introduces server components in React, which provide an intermediate format for rendering and offer advantages for both client-side and server-side rendering. Server components reduce bundle size on the client and improve search engine optimization. They abstract the rendering process, allowing for faster rendering and flexibility in choosing where to render components. While server components are still in the experimental stage, Next.js is a good starting point to try them out.
Batteries Included Reimagined - The Revival of GraphQL Yoga
GraphQL Galaxy 2021GraphQL Galaxy 2021
33 min
Batteries Included Reimagined - The Revival of GraphQL Yoga
Envelope is a powerful GraphQL plugin system that simplifies server development and allows for powerful plugin integration. It provides conformity for large corporations with multiple GraphQL servers and can be used with various frameworks. Envelope acts as the Babel of GraphQL, allowing the use of non-spec features. The Guild offers GraphQL Hive, a service similar to Apollo Studio, and encourages collaboration with other frameworks and languages.

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
The Gateway to Backend: A Frontend Developer's Guide to Full-Stack Development
React Summit US 2023React Summit US 2023
160 min
The Gateway to Backend: A Frontend Developer's Guide to Full-Stack Development
Top Content
WorkshopFree
Amy Dutton
Amy Dutton
This workshop will guide you through the product development life cycle of creating a real-world web application. You will learn about React Server Components, building a design system within Storybook, and using frontend development to approach becoming a full-stack developer. The workshop will cover increasing confidence in your application with unit tests and implementing authentication and authorization. You'll have the opportunity to work through product features and examine a real-world RedwoodJS project, gaining valuable experience in real-world product development. RedwoodJS makes it simple to approach full-stack development, and this workshop will give you the skills you need to create your own real-world web applications.
Advanced Application Deployment Patterns with React Server Components (feat. a DIY RSC Framework)
React Summit US 2023React Summit US 2023
104 min
Advanced Application Deployment Patterns with React Server Components (feat. a DIY RSC Framework)
Top Content
WorkshopFree
 Greg Brimble
Greg Brimble
The developer ecosystem is always moving fast and this year has proved no exception. React Server Components can offer a significant improvement to developer experience and to application performance. But I think it's fair to say that this new server-first paradigm can be tricky to wrap your head around!In the first half of this workshop, we'll explore React Server Components from the ground-up: building our own mini meta-framework to help us understand how RSCs work. We'll discover exactly what is produced by an RSC build and we'll connect those pieces together to form a full application.Next, we'll deploy it! Cloudflare have also had a busy year too — Smart Placement, in particular, is a new technology that we've developed which fits the RSC model perfectly. We'll explore why that makes sense for our workshop app, and we'll actually deploy it onto the Cloudflare Developer Platform.Finally, we'll build out our app a little further, using D1 (our serverless SQL database) to really show off the React Server Component's power when combined with Smart Placement.You should come away from this workshop with a greater understanding of how React Server Components work (both behind-the-scenes and also how you as a developer can use them day-to-day), as well as insight into some of the new deployment patterns that are now possible after recent innovations in the platform space.
Building a Shopify App with React & Node
React Summit Remote Edition 2021React Summit Remote Edition 2021
87 min
Building a Shopify App with React & Node
Top Content
WorkshopFree
Jennifer Gray
Hanna Chen
2 authors
Shopify merchants have a diverse set of needs, and developers have a unique opportunity to meet those needs building apps. Building an app can be tough work but Shopify has created a set of tools and resources to help you build out a seamless app experience as quickly as possible. Get hands on experience building an embedded Shopify app using the Shopify App CLI, Polaris and Shopify App Bridge.We’ll show you how to create an app that accesses information from a development store and can run in your local environment.
Building Reusable Server Components in NextJS
React Summit US 2023React Summit US 2023
88 min
Building Reusable Server Components in NextJS
Workshop
Will Bishop
Mettin Parzinski
2 authors
React continues to evolve their beta capability, React Server Components, and they're continuing to further develop them in partnership with frameworks like NextJS.In this workshop, attendees will learn what React Server Components are, how to effectively build and use them in NextJS, and focus on one of the major advantages of React/NextJS: reusability through components.We will also cover related beta technologies enabled by the `app` directory, such as nested layouts and server actions (alpha/experimental capability).Join us for this hands-on, 120 minute workshop!Technologies:
React, JavaScript/Typescript, NextJS, Miro
React Server Components Unleashed: A Deep Dive into Next-Gen Web Development
React Day Berlin 2023React Day Berlin 2023
149 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