Skip to main content

Hydrogen developer preview

Hydrogen is Shopify's framework for building headless storefronts. It provides commerce primitives like cart, products, collections, and a typed Storefront API client, so you can build a fast headless storefront backed by Shopify.

This developer preview is the next version of Hydrogen. It keeps the same commerce primitives but removes the tie to React Router, so you can build with any JavaScript framework and deploy to any JavaScript runtime. It comes with skills that coding agents use to build storefronts.


Anchor to How this preview differs from current HydrogenHow this preview differs from current Hydrogen

Current HydrogenDeveloper preview
What it isFrameworkSDK + Agent Skills
FrameworkReact RouterAny JavaScript framework
RuntimeOxygen or NodeAny JavaScript runtime
Setupnpm create @shopify/hydrogen@latestnpx @shopify/hydrogen@preview setup

Use current Hydrogen if you want Shopify's fully supported path for building with React Router. Use the developer preview to build with Hydrogen's commerce primitives in any JavaScript framework.


The developer preview requires:

  • A server-rendered JavaScript storefront, built with the framework of your choice.
  • Node.js and npm installed.
  • Storefront API access for the store you want to connect. To create a storefront and manage your credentials, use the Headless channel.

The developer preview is built for coding agents. It ships with skills, focused instructions that teach an agent how to build each part of a storefront, so the agent you already use can set most of it up for you.

Create a project with the framework you want, then add @shopify/hydrogen@preview:

npx create-react-router@latest my-store
cd my-store
npx @shopify/hydrogen@preview setup
npx create-next-app@latest my-store
cd my-store
npx @shopify/hydrogen@preview setup
npx sv create my-store
cd my-store
npx @shopify/hydrogen@preview setup
npm create nuxt@latest my-store
cd my-store
npx @shopify/hydrogen@preview setup
npm init solid@latest my-store
cd my-store
npx @shopify/hydrogen@preview setup

The setup command installs the developer preview package and copies the skills into your project's agent skills folder. Then open your project in the coding assistant of your choice and ask it to build your storefront:

Prompt

Can you set up my store with Shopify?

The agent picks up the skills and uses them to set up the Storefront API client, build the cart, and create your product and collection pages.

To connect your storefront to your Shopify store and pull in your products, add your store credentials to your project's environment:

.env

PUBLIC_STORE_DOMAIN="your-shop.myshopify.com"
PUBLIC_STOREFRONT_API_TOKEN="..." # public token, safe for the browser
PRIVATE_STOREFRONT_API_TOKEN="..." # private token, server-only, never expose

Find these values in the Headless channel for your store.

Then start your dev server (for example, npm run dev) and open your storefront. You should see your products and a working cart.

Developer preview

Share what's working well and any feedback in the Shopify developer community.


The preview includes the commerce primitives you need to build a storefront:

  • A typed Storefront API client.
  • Cart, product, and collection primitives.
  • Money formatting.
  • First-party analytics with consent handling.
  • Shop Pay buttons.
  • Request handlers that proxy the Storefront API, cart, and redirects.
  • Support for Shopify standard storefront events and actions.

Customer accounts and predictive search are coming soon.


Hydrogen's commerce logic is written in plain JavaScript, with no framework required. Framework bindings are a thin layer on top.

Anchor to The Storefront API clientThe Storefront API client

Create a request-scoped client on the server, then query it with typed gql() documents:

storefront.ts

import {
createStorefrontClient,
createStorefrontRequestContext,
gql,
} from '@shopify/hydrogen';

const storefront = createStorefrontClient({
type: 'private',
config: {
storeDomain: process.env.PUBLIC_STORE_DOMAIN,
privateStorefrontToken: process.env.PRIVATE_STOREFRONT_API_TOKEN,
i18n: {language: 'EN', country: 'US'},
buyerIp: getBuyerIp(request.headers), // your helper to read the forwarded client IP
requestContext: createStorefrontRequestContext(request),
},
});

const {data} = await storefront.graphql(
gql(`
query Home {
products(first: 3) {
nodes { handle title }
}
}
`),
);

Here request is the incoming request from your framework's server handler, and getBuyerIp is a small helper you write to read the forwarded client IP from its headers. Because the query is written with gql(), data comes back fully typed against the Storefront API schema. createStorefrontRequestContext carries the request's cookies and timing headers so analytics and caching stay correct.

A small set of request handlers own the routes your framework's router shouldn't touch, like the Storefront API proxy, cart endpoints, checkout and cart permalinks, and redirects. They run in your server around your framework's router:

Request lifecycle

handleShopifyRoutes(); // before your router
// your framework router
handleShopifyRedirects(); // only after a 404
// your framework 404 page

Load the Standard Actions runtime once in your root document, before wiring the cart:

Root document

<script type="module" src="https://cdn.shopify.com/storefront/standard-actions.js" crossorigin="anonymous"></script>

You create a cart, connect it, and subscribe to it. Then you can read or update the cart from anywhere in your code. React comes with bindings, a provider and hooks. Other frameworks use the same core primitives directly. Here's reading the cart count in each:

import {createCartComponents} from '@shopify/hydrogen/react';
import {cartHandlers} from './cart-handlers';

// Create your typed cart components once.
const {CartProvider, useCart} = createCartComponents<typeof cartHandlers>();

// Read a slice of the cart anywhere; re-renders only when totalQuantity changes.
function CartCount() {
const totalQuantity = useCart((cart) => cart.data.totalQuantity);
return <span>{totalQuantity}</span>;
}

// Mount the provider once, with the cart fetched on the server.
export function App({initialCart, children}) {
return <CartProvider initialData={initialCart}>{children}</CartProvider>;
}
'use client';

import {createCartComponents} from '@shopify/hydrogen/react';
import {cartHandlers} from './cart-handlers';

// Next.js uses the same React bindings.
const {CartProvider, useCart} = createCartComponents<typeof cartHandlers>();

function CartCount() {
const totalQuantity = useCart((cart) => cart.data.totalQuantity);
return <span>{totalQuantity}</span>;
}
<script>
import {createCartStore} from '@shopify/hydrogen';
import {readable} from 'svelte/store';
import {onMount} from 'svelte';

const cart = createCartStore({initialData});

// connect() is browser-only, so run it after mount.
onMount(() => cart.connect());

// Wire the core store into a Svelte store.
const totalQuantity = readable(cart.getState().data.totalQuantity, (set) =>
cart.subscribe((state) => set(state.data.totalQuantity)),
);
</script>

<span>{$totalQuantity}</span>
<script setup>
import {createCartStore} from '@shopify/hydrogen';
import {shallowRef, onMounted} from 'vue';

const cart = createCartStore({initialData});
const totalQuantity = shallowRef(cart.getState().data.totalQuantity);

// Wire the core store into Vue reactivity.
onMounted(() => {
cart.connect();
cart.subscribe((state) => {
totalQuantity.value = state.data.totalQuantity;
});
});
</script>

<template>
<span>{{ totalQuantity }}</span>
</template>
import {createCartStore} from '@shopify/hydrogen';
import {createSignal, onMount} from 'solid-js';

function CartCount() {
const cart = createCartStore({initialData});
const [totalQuantity, setTotalQuantity] = createSignal(cart.getState().data.totalQuantity);

// Wire the core store into a Solid signal after mount.
onMount(() => {
cart.connect();
cart.subscribe((state) => setTotalQuantity(state.data.totalQuantity));
});

return <span>{totalQuantity()}</span>;
}
import {createCartStore} from '@shopify/hydrogen';

const cart = createCartStore({initialData});

// Listen for cart mutations from your UI, third-party apps, and agents.
cart.connect();

// Update the DOM whenever the cart changes.
cart.subscribe((state) => {
document.querySelector('#cart-count').textContent = String(state.data.totalQuantity);
});

The preview ships a runnable example of the same storefront in each framework, so you can see how the primitives fit:


The preview includes skills that guide coding agents through building each part of a storefront. They're part of the package, so they stay aligned with the version you install, and the setup command copies them into your project's agent skills folder.

They cover the full storefront:

SkillCovers
hydrogen-setupEnd-to-end setup and verification in an existing project
hydrogen-storefront-clientThe typed Storefront API client and gql() queries
hydrogen-request-handlershandleShopifyRoutes, handleShopifyRedirects, and cart and Storefront API proxy wiring
hydrogen-cart-uiThe cart route and progressive line-item forms
hydrogen-cart-drawerAn accessible cart drawer
hydrogen-collection-browserCollection and search browsing, filters, and sort
hydrogen-variant-formProduct pages and variant selection
hydrogen-moneyCurrency-correct money formatting
hydrogen-shop-payShop Pay buttons
hydrogen-marketsLocalization with Shopify Markets
hydrogen-analyticsStorefront analytics and consent
hydrogen-smoke-testRuntime verification of the storefront

To see what each skill does, refer to the skills in the project repo.


Was this page helpful?