Shopify is building their own headless solution, known as Hydrogen, on top of the React Remix framework, which Shopify acquired back in 2022. Remix is a competitor to Next.js and differs in certain respects, though both are ultimately just React frameworks. A critical decision is which platform to use for headeless development? Why not just use Shopify's Hydrogen based on Remix instead of Next.js?
This is an excellent question and I'll spend this post discussing our reasons for opting to use Next.js, at this point to build a storefront, rather than Hydrogen/Remix.
First of all, I'll state at the start that both Remix and Next.js are excellent platforms and either is great option to build a headless store. With that being said, here are the reasons why Next.js, at least at this time appears to be a better framework choice:
Strengths of Next.js over Remix
-
Next.js is more Popular By any standard Next.js is the more popular framework for React, and going with the leader is generally the better option for production deployments because of the ease of support. For example, for virtually any issue you will face in Next.js you can almost always find a solution online or easily find a skilled Next.js developer, or better yet use ChatGPT (the LLM's are better at Next.js simply due to the larger volume of information for Next.js which available for training).
-
Next.js is more Powerful With the advent of Next.js App router and Next 14, Next.js essentially took all of the best features of Remix and just turbocharged them, for lack of a better phrase. Instead of the Remix loader pattern, for example, Next.js now has React Server Components. Of course, I don't want to imply that RSC is the same as a Loader, but the coding pattern is similar and RSC's are light years ahead of a Loader in Remix, in terms of functionality. Next.js also has middleware running on Edge (powered by Cloudflare), Server Actions for forms (again one upping Remix, where the form functionality was previously superior to Next.js), and quite simply a better setup for standalone API routes. All in all, it seems to me that Next.js is currently a much more powerful framework that allow for much greater customization and scale.
-
Next.js is more Versatile While both Next.js and Remix both now push more for server-side functionality vs the browser, the reality is that in any React app, you will need a substantial amount of client-side code. While slightly more complex now on the App router, it is still relatively trivial to build client-side apps on Next.js using your tool of choice, like Tanstack query. On Remix, it not so easy, and as of the date of this post, better client-side tooling is a just an RFC on Remix
Change and Portability
Of course, all of the above may change rapidly in the future, as Remix now has substantial support from Shopify, and may far outpace Next.js in a few years. At the same time, it's also entirely conceivable that at some point some other framework, will oust both Next.js and Remix (unfortunately React frameworks have a tendency to go in and out of favor quite quickly). In fact, we are already investigating using other React platforms, like Docusaurus (which this website is built on), to build out a complete e-commerce solution. Stay tuned...
However, if you build with the Next.js App router and stick to edge functions in Next.js, I don't believe porting code will be all the difficult as Next.js App router and edge is more and more attuned to the fundamental Web APIs that you can find on MDN, like Remix has always been (see Why I'm Using Next.js). It is much easier to port standard Javascript code to any new platform. In fact, it is somewhat easy to port code from Remix to Next.js, again if you stick to the App router and Edge functions. So I don't think you lose anything by using Next.js, and all the code will be easily portable to any other framework.
Why did Shopify build on Remix?
To close out this post, I want to address an interesting question. If Next.js is seemingly the better platform, why did Shopify decide to build Hydrogen on Remix, as opposed to Next.js? I believe there are two answers this question: the timing of technology releases, and more importantly critical business considerations.
Technology Timing
Initially, Shopify attempted to build their own React framework, using RSC, to power Hydrogen. This failed. When it did, I imagine Shopify did consider using Next.js, and may have even attempted to buy Vercel (the creator of Next.js). However, back in 2022, Next.js hadn't yet released a stable version of the App router (still as of this post, the App router has some glaring issues, mostly around cache), and so it's doubtful Shopify saw any benefit in building Hydrogen on top of Next.js Pages router. Of course, the Pages router is stable and proven, but it's tough to see any benefit of Pages over Remix, and in that contest, I'd say Remix has an edge. So, in this respect, the decision to use Remix was more of a timing issue, more than anything else. Would Shopify use Remix now when the Next.js App router is stable? From a purely technology perspective, I'd say the answer would be a resounding no, because Remix is in all respects behind Next.js at this point. However, technology is never the only consideration. There are critical business reasons why Shopify would never build on Next.js, unless they could buy them.
A Business Decision to Maintain Control
The reality is that Shopify simply cannot rely on Next.js as the underlying platform, as they want complete control over the entire headless experience. Next.js is managed by Vercel, and despite claims to the contrary, for the best experience with Next.js in production, you must host by Vercel. There is no way Shopify would cede the hosting of their headless platforms to Vercel. As it is now stands, Shopify will also claim you can host Hydrogen anywhere, but the reality is that it is built for their Oxygen hosting platform, and if you are going the route you should host with Shopify Oxygen.
Furthermore, how could Shopify rely on Next.js to prioritize platform issues that relate to Shopify stores? They can't. The only way Shopify can make sure a framework is meeting its needs is to own the platform outright.
So in the interest of controlling the entire headless ecosystem, Shopify had to buy a framework, and pour resources into it. Since Vercel as apparently not for sale (or not at the price Shopify was willing to pay), Remix was really the only other mature platform in 2022 that was available, and so that's what Shopify bought.
Was it the right decision? Time will tell. But it doesn't really matter, as Shopify ultimately doesn't care which React platform you use, as long as you use Shopify as the product CMS and checkout. Of course, internally, they will and can only really focus on Remix now, but as Remix code is basically just React and standard Javascript, you don't have to use it, and it seems like a better choice to just go with the more powerful platform, Next.js, and hope for the best.