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.
Hydrogen: An Early Look at Server Components in the Wild
AI Generated Video Summary
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
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
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.
3. Server Components and the Future of Headless
When something goes wrong with server components, there's a lack of tooling. However, server components offer great encapsulation and allow for fast rendering via HTML. The future of headless is exciting with new technologies like Edgeworkers and hosting platforms like Oxygen. Server rendering will become more prevalent. Visit addogen.new to try a demo shop with server components. We are hiring at Shopify. Thank you!
Like when something goes wrong with server components, we don't know how to take a look. There's still not enough tooling around, so that's something where it would be nice to invest in, but still, the good thing about server components is that encapsulation is really great. I can still do the same as with client components and have like, something like this, and be able to just render things fast and via HTML and use them directly.
So I guess the future of headless, I think, is exciting. We are having new things like Edgeworkers, where we can have renders really close to the user. So we can do server rendering really fast, and we have now a lot of hosting platforms like Oxygen, which is something that we have in Shopify. And because of that, we are starting to see Lighthouse cores that look like this, even with e-commerce sites that are highly dynamic and could have a lot of intricacies. Right.
So, conclusion, for me, is that server rendering will happen more. And, yeah, if you want to check it out, you can go to this website, addogen.new, and you can actually play with a demo shop that we did, and play with server components. And we are hiring at Shopify. So, yeah, that's it for me. That's all. Thank you. Thanks. It was a pleasure.
Comments