Building custom storefronts on Shopify with Hydrogen

Rate this content
Bookmark

Get hands-on with Hydrogen, a React-based framework powered by Shopify. In this workshop, we'll explore the framework and get a custom storefront up and running quickly. You'll learn how (and when) to leverage React Server Components and caching mechanisms to build fast, dynamic, custom storefronts.

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

FAQ

The workshop aims to teach participants how to build headless storefronts using Shopify's new tool called Hydrogen. This includes hands-on coding and understanding the major features of Hydrogen to help ship and build fast, custom storefronts.

The workshop is hosted by Megan and Abe, both of whom are developer advocates at Shopify. Megan is active in the community and available on Discord, Twitter, and YouTube. Abe also has a Twitter account and is available via email for any Shopify developer-related questions.

Hydrogen is a framework recently released by Shopify that allows developers to build custom storefronts using headless APIs. Unlike traditional Shopify store building which relies on a drag-and-drop interface and pre-built themes, Hydrogen offers APIs to build any UI on top of a Shopify store, providing more flexibility and power.

Hydrogen uses three strategies: React server components, streaming server-side rendering, and flexible cache policies. These strategies work together to make building e-commerce sites faster and more efficient.

React server components allow both the server and the client to collaborate when rendering a React application. This enables faster app performance and more secure data fetching, as heavy code modules and data fetching can be handled server-side.

Hydrogen uses a new SSR API powered by React 18's suspense feature. This eliminates data fetching waterfalls, provides fast first-byte loading, and supports progressive hydration, allowing components to be rendered at different times based on their loading speed.

Flexible cache policies in Hydrogen allow you to cache entire pages or individual requests. You can set different cache durations for various pieces of data, improving both speed and data freshness for your e-commerce site.

The workshop utilizes Hydrogen, React, GraphQL, and StackBlitz. Participants will learn to use hooks, utilities, and components provided by Hydrogen to build custom storefronts.

Currently, Hydrogen is designed to work within its own ecosystem and is not intended to be used with other frameworks like Next.js. It relies on specific configurations and components that are unique to Hydrogen.

For more information and updates about Hydrogen, you can join the Shopify Discord and follow the custom storefronts channel. This channel provides the latest releases, notes, and targeted updates about Hydrogen.

Abe Haskins
Abe Haskins
Megan Majewski
Megan Majewski
71 min
01 Jul, 2022

Comments

Sign in or register to post your comment.
Video Summary and Transcription
This workshop introduces Shopify's Hydrogen, a React-based framework for building headless storefronts. Hydrogen offers fast client-side rendering, flexible caching, and a simplified development process. It uses file-based routing and allows for dynamic routes. The workshop covers querying the Storefront API with GraphiQL, using GraphQL queries in Hydrogen, and accessing product details. It also demonstrates the use of the product options provider, the cart provider, and the add to cart button. Hydrogen is recommended for larger merchants and provides scalability and flexibility for building e-commerce stores.

1. Introduction to Shopify's Hydrogen

Short description:

Welcome to the workshop on building headless storefronts using Shopify's Hydrogen. I'm Megan, a dev advocate at Shopify, and I'm excited to share this latest workshop with you. I'm Abe, another developer advocate, here to support Megan and answer any questions you may have. Let's get started!

So, let's dive right in. All right, cool. Well, welcome, everybody. As the title slide says, and I'm sure you know since you signed up for this workshop, we're gonna be going over building headless storefronts using Shopify's new tool called Hydrogen. We'll kind of get some hands-on coding today, but I'm super excited to be sharing with you this workshop because it's kind of the latest from Shopify and React.

I'm Megan. You can find me on Discord, Twitter, YouTube. I'm a dev advocate here at Shopify. So, I'm pretty active in the community. So, feel free to say, hi, if you kind of see me around. So, part of my team work focuses on kind of bringing you guys workshops like this one and highlighting some of the other cool things that Shopify is doing, as well as kind of hearing from you guys and understanding what you're interested in Shopify doing and seeing all the cool stuff that the community is building.

And I'm Abe. I'm also a developer advocate at Shopify. My job is mostly to let Megan do her job and then show up to actually give the talk and act like I did any of the work to prepare for it. Similarly, I flirt around on various socials. I do have a Twitter account and things like that, but I wouldn't recommend following me because I don't tweet anything interesting. But I'm around. You'll see me pop up in all sorts of different Shopify related resources. And, of course, you can always shoot me an email if you have any specific questions or thoughts either about the workshop or anything Shopify developer related in general. Always happy to chat or route your question to someone who has a better answer than I do.

2. Introduction to Hydrogen

Short description:

Today we'll be using Hydrogen to build a product page. Hydrogen is a framework that Shopify recently released, allowing you to put a head on top of the headless APIs. It's a React-based framework with utilities to simplify building an e-commerce store. Hydrogen powers personalized, dynamic e-commerce sites using React server components, streaming server-side rendering, and flexible cache policies.

Cool. So today we'll be using Hydrogen to build a product page. What you'll learn is some major features that Hydrogen has developed to help you ship and build fast. And by the end of the workshop, we'll get hands on, we'll do some coding. You'll check out some of the tools that Shopify has developed to help you rapidly build a custom storefront. And hopefully by the end, there'll be some time for Q&A. But if you have any questions, feel free to put them in the chat as we go through and we'll try to tag team and get through them there as well.

So let's get into it. Abe, you want to kick us off? Yeah. So, for anyone who's not familiar, Hydrogen is a framework that Shopify recently released. Basically, what it is, is a way for you to put a head on top of the headless APIs that Shopify offers. When a lot of people see Shopify, they think of people who go into our public interface and design a shop using the drag and drop interface and kind of pick a theme from the store, things like that, kind of just customizing off the shelf e-commerce experiences. But Hydrogen is a very different approach. We offer all these APIs that basically let you do everything that we can do with your store, you can do through an API. And then Hydrogen lets you build any UI you want on top of that. So we're going to get into it a bit here, but the important parts are, it's a React based framework. So it'll be familiar to anyone who's worked with React, with a bunch of cool helpers and utilities to help building a Shopify powered store. E-commerce in general is like super hard and you'll see here that, like, we've tried to pull together a bunch of utilities and helpers and things that are kind of like the common use cases for building a store. You know, you need like a cart, you need product pages, you need all these different little components, like different versions or variants that we'll talk about. So, you know, if you have a product that has different colors or things like that, all of this is pretty generic to e-commerce. And this is kind of the problem Hydrogen is hoping to solve. Simplify the problem, make building an e-commerce store easier, but still give you the absolute maximum amount of power you could need to do whatever crazy type of store you want to do.

Yeah, so as I was just saying, Hydrogen is built to power personalized, dynamic e-commerce sites. And to do this, we have three separate strategies that kind of work together. They are React server components, streaming, server-side rendering, which for me is a mouthful. So if I start slurring that, I apologize. That's what I mean. Streaming, server-side rendering and the final one is flexible cache policies. Let's talk details about each of these. So React server components. Maybe you heard about this with React 18. It's prominently featured in Hydrogen and it's like kind of the new up and coming React topic. It's not the same as server-side rendering. I know it's like a little bit confusing. I actually thought they were the same thing for a while until I started digging into Hydrogen and how we make use of it. But server components allow both the server and the client, meaning the browser, to collaborate together when rendering your React application. So if you think about your typical React application, this is like an element tree of React components that are including more React components, and it's all kind of loaded and done on the browser side. React server components make it possible for some of those components in the tree instead to be rendered by the server. And then you can push off some of the work to the server side and still have some client rendered components by the browser. This has a couple of advantages. The first one is, of course, your server has more direct access to your data sources, so things like your database, GraphQL, endpoints, or even your file system, things like that. The server can directly fetch the data that you need and it doesn't have to go through an API endpoint like your client side would normally have to. So this makes your app faster and also more secure because you don't have to go through that API layer. And if you have a lot of heavy code modules, so maybe, for example, you have like an expensive date formatting library or something like that, you can use that on your server component. So that means the library that you're using that might be a little big and bloated stays on your server, doesn't ever need to be transferred to your client. So you reduce your overall bundle size and also help the speediness of the loading. One thing to understand while we're kind of talking about this topic is server components, like we said, can fetch data and access the system or maybe your file system, but you cannot store state or have any context in these components. So if you need access to a state or context or anything like that, that's when you would have to bring in a client component because that work is obviously done on the browser. This next topic that we've included, the streaming server side, rendering server side, rendering is not itself a new component, but in react18. There's a new SSR API powered by suspense, and this really kind of unlocks a lot of cool features for server side rendering, so it eliminates data fetching waterfalls.

QnA

Watch more workshops on 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.
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.
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.
Create a Visually Editable Next.js Website Using React Bricks, With Blog and E-commerce
React Summit 2023React Summit 2023
139 min
Create a Visually Editable Next.js Website Using React Bricks, With Blog and E-commerce
Top Content
WorkshopFree
Matteo Frana
Matteo Frana
- React Bricks: why we built it, what it is and how it works- Create a free account- Create a new project with Next.js and Tailwind- Explore the directory structure- Anatomy of a Brick- Create a new Brick (Text-Image)- Add a title and description with RichText visual editing- Add an Image with visual editing- Add Sidebar controls to edit props (padding and image side)- Nesting Bricks using the Repeater component- Create an Image gallery brick- Publish on Netlify or Vercel- Page Types and Custom fields- Access Page meta values- Internationalization- How to reuse content across pages: Stories and Embeds- How to create an E-commerce with Products’ data from an external database and landing pages created visually in React Bricks- Advanced enterprise features: flexible permissions, locked structure, custom visual components
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

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 2023React Advanced 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 2023React Advanced 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.
RSCs In Production: 1 Year Later
React Summit 2024React Summit 2024
24 min
RSCs In Production: 1 Year Later
This Talk explores the experience of shipping server components in production and highlights the benefits and challenges of using Server Components in Next.js apps. The Talk discusses the deployment of UploadThing and the use of AppRouter for safe production usage. It delves into the implementation of different layouts, data fetching, and code centralization for improved performance. The Talk also covers the use of server components for performance optimization and latency handling. Additionally, it explores the use of Edge and Lambda for partial pre-rendering and the challenges faced with webpack performance and hydration. Overall, the Talk emphasizes the benefits and challenges of working with Server Components in Next.js applications.