Okay this bit is for the devs and the tech-heads If you’re not into the intricate stuff, feel free to keep scrolling and read our analysis below.
Shopify have already highlighted a number of areas where changes and updates are coming for Hydrogen developers. Let’s take a look at them:
Data loading
Shopify’s acquisition of Remix has changed the way data loading takes place within Hydrogen builds. Previously reliant on React Server Components, Remix makes the transition to edge computing and modern server caching strategies. Queries are moved to route-level data loaders that run server side rather than on React Server Components, giving more reliable performance levels.
By clearly separating server work from client components, there’s less confusion between how the two are supposed to mix together, resulting in a simpler developer experience and fewer mistakes.
Shopify remain in close collaboration with the React core team and the RSC. However it looks like from now on the Remix data loading patterns will continue to play the key role. In Shopify’s own words: “it’s the ideal solution for the performance and resiliency of our merchants' websites”.
Routing
The Remix router has introduced an innovative approach to nested routing, something that was crucially missed in Shopify’s previous declarative and file-based router solution. A few syntactical differences aside, the new solution follows much the same logic, with Remix adding some extra benefits on top.
- The “root” route offers a more intuitive way to provide a consistent layout component for your website’s shell.
- “$” gives a catch-all route that creates dedicated places in your file structure for pages like the 404.
Error boundaries
Mistakes are a fact of life. Development is no different and no matter how skilled you are at coding, you will make mistakes. It’s great, then, when you know that any mistakes are both easy to spot and contained as much as possible.
Nested error boundaries keep everything around a mistake working as they should, and make sure that only specifically affected areas of your website are disrupted by mistakes.
You can write messages and fallback UI for individual parts of each page related to distinct fetch requests, and for whatever status code you want to throw.
Mutations
E-commerce has some key fundamental features that, if done well, make a store run smoothly and have a big impact on conversion rates. Letting shoppers pick up right where they left off, allowing them to easily share links with friends and keeping the path to purchase clear from clutter. These 3 are key moments in an effective storefront, but they’re famously difficult to get right.
With the introduction of Remix’s useMatches, useSearchParams and useFetcher, however, it’s becoming a lot easier on Shopify’s hydrogen stores. These are each incredibly powerful ways to revalidate server data while keeping a single source of truth in your URL.
The forthcoming Hydrogen cart will move all actions to the server and therefore remove client-side JavaScript. It’ll also feature Optimistic UI to give that instantaneous feeling to all add-to-cart actions.
With simple and flexible APIs for working with paginated Storefront API queries, the Hydrogen Pagination component makes product grids, search results and order history requests much easier to handle.
Take infinite scroll, for example, not only will it now (finally) be easy to do right, the URL will be automatically updated and store restoration will make sure you swipe back right to where you left off. And if you share a link with a friend, they’ll even land on the very same grid of products you were looking at when you stopped scrolling. How good’s that?