@shopify/hydrogen 2026.10.2 → 2026.10.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -5
- package/dist/cli/index.mjs +2 -2
- package/dist/client/client.mjs +44 -9
- package/dist/client/client.mjs.map +1 -1
- package/dist/client/i18n-variables.d.mts +1 -1
- package/dist/client/i18n-variables.mjs +14 -6
- package/dist/client/i18n-variables.mjs.map +1 -1
- package/dist/client/types.d.mts +12 -6
- package/dist/core/cache/fetch-with-cache.mjs +8 -1
- package/dist/core/cache/fetch-with-cache.mjs.map +1 -1
- package/dist/core/cart/cart.mjs +1 -1
- package/dist/core/cart/cookie.mjs +6 -1
- package/dist/core/cart/cookie.mjs.map +1 -1
- package/dist/core/cart/form.d.mts +17 -5
- package/dist/core/cart/form.mjs +5 -0
- package/dist/core/cart/form.mjs.map +1 -1
- package/dist/core/cart/index.d.mts +1 -1
- package/dist/core/collection/url.mjs +8 -1
- package/dist/core/collection/url.mjs.map +1 -1
- package/dist/core/constants.mjs +2 -1
- package/dist/core/constants.mjs.map +1 -1
- package/dist/core/csp/index.d.mts +56 -0
- package/dist/core/csp/index.mjs +117 -0
- package/dist/core/csp/index.mjs.map +1 -0
- package/dist/core/csp/types.d.mts +52 -0
- package/dist/core/headers.mjs +2 -2
- package/dist/core/headers.mjs.map +1 -1
- package/dist/core/i18n/define.d.mts +54 -0
- package/dist/core/i18n/define.mjs +135 -0
- package/dist/core/i18n/define.mjs.map +1 -0
- package/dist/core/i18n/errors.d.mts +18 -0
- package/dist/core/i18n/errors.mjs +24 -0
- package/dist/core/i18n/errors.mjs.map +1 -0
- package/dist/core/i18n/href.d.mts +28 -0
- package/dist/core/i18n/href.mjs +45 -0
- package/dist/core/i18n/href.mjs.map +1 -0
- package/dist/core/i18n/locale.d.mts +21 -0
- package/dist/core/i18n/locale.mjs +36 -0
- package/dist/core/i18n/locale.mjs.map +1 -0
- package/dist/core/i18n/match.d.mts +37 -0
- package/dist/core/i18n/match.mjs +82 -0
- package/dist/core/i18n/match.mjs.map +1 -0
- package/dist/core/i18n/types.d.mts +80 -0
- package/dist/core/index.d.mts +14 -5
- package/dist/core/index.mjs +9 -2
- package/dist/core/predictive-search/index.d.mts +2 -2
- package/dist/core/predictive-search/server-handlers.d.mts +27 -6
- package/dist/core/predictive-search/server-handlers.mjs +1 -4
- package/dist/core/predictive-search/server-handlers.mjs.map +1 -1
- package/dist/core/predictive-search/url.d.mts +2 -2
- package/dist/core/predictive-search/url.mjs.map +1 -1
- package/dist/core/product/accept-variant-id.mjs +1 -1
- package/dist/core/product/accept-variant-id.mjs.map +1 -1
- package/dist/core/request-context.d.mts +61 -35
- package/dist/core/request-context.mjs +11 -7
- package/dist/core/request-context.mjs.map +1 -1
- package/dist/core/request-routing/handle-shopify-routes.mjs.map +1 -1
- package/dist/core/request-routing/interceptors/api-proxy.mjs +9 -1
- package/dist/core/request-routing/interceptors/api-proxy.mjs.map +1 -1
- package/dist/core/request-routing/interceptors/checkout.mjs +11 -5
- package/dist/core/request-routing/interceptors/checkout.mjs.map +1 -1
- package/dist/core/request-routing/interceptors/standard-routes.mjs +1 -1
- package/dist/core/request-routing/interceptors/standard-routes.mjs.map +1 -1
- package/dist/core/request-routing/interceptors/url-redirects.mjs +2 -1
- package/dist/core/request-routing/interceptors/url-redirects.mjs.map +1 -1
- package/dist/core/request-routing/registered-routes.d.mts +10 -3
- package/dist/core/request-routing/registered-routes.mjs +13 -3
- package/dist/core/request-routing/registered-routes.mjs.map +1 -1
- package/dist/core/request-routing/route-types.d.mts +2 -2
- package/dist/core/shop-pay/shop-pay.mjs +5 -4
- package/dist/core/shop-pay/shop-pay.mjs.map +1 -1
- package/dist/core/shopify-scripts/analytics.mjs +3 -5
- package/dist/core/shopify-scripts/analytics.mjs.map +1 -1
- package/dist/core/shopify-scripts/constants.mjs +3 -1
- package/dist/core/shopify-scripts/constants.mjs.map +1 -1
- package/dist/core/shopify-scripts/global.mjs +13 -11
- package/dist/core/shopify-scripts/global.mjs.map +1 -1
- package/dist/core/shopify-scripts/hashes.d.mts +17 -0
- package/dist/core/shopify-scripts/hashes.mjs +12 -0
- package/dist/core/shopify-scripts/hashes.mjs.map +1 -0
- package/dist/core/shopify-scripts/index.d.mts +1 -0
- package/dist/core/shopify-scripts/index.mjs +12 -9
- package/dist/core/shopify-scripts/index.mjs.map +1 -1
- package/dist/core/shopify-scripts/page-view.mjs +4 -1
- package/dist/core/shopify-scripts/page-view.mjs.map +1 -1
- package/dist/core/shopify-scripts/types.d.mts +4 -2
- package/dist/core/shopify-scripts/utils/inline-script.mjs +4 -1
- package/dist/core/shopify-scripts/utils/inline-script.mjs.map +1 -1
- package/dist/core/standard-routes/build.d.mts +7 -2
- package/dist/core/standard-routes/build.mjs +10 -3
- package/dist/core/standard-routes/build.mjs.map +1 -1
- package/dist/core/standard-routes/match.mjs +11 -1
- package/dist/core/standard-routes/match.mjs.map +1 -1
- package/dist/core/standard-routes/path.mjs +14 -3
- package/dist/core/standard-routes/path.mjs.map +1 -1
- package/dist/core/standard-routes/types.d.mts +6 -1
- package/dist/core/url.mjs +5 -3
- package/dist/core/url.mjs.map +1 -1
- package/dist/customer-account/client.d.mts +14 -10
- package/dist/customer-account/client.mjs +4 -5
- package/dist/customer-account/client.mjs.map +1 -1
- package/dist/customer-account/graphql.d.mts +7 -1
- package/dist/customer-account/graphql.mjs +6 -7
- package/dist/customer-account/graphql.mjs.map +1 -1
- package/dist/customer-account/session.mjs +3 -4
- package/dist/customer-account/session.mjs.map +1 -1
- package/dist/development/client/client.mjs +44 -9
- package/dist/development/client/client.mjs.map +1 -1
- package/dist/development/client/i18n-variables.d.mts +1 -1
- package/dist/development/client/i18n-variables.mjs +13 -5
- package/dist/development/client/i18n-variables.mjs.map +1 -1
- package/dist/development/client/types.d.mts +12 -6
- package/dist/development/core/cache/fetch-with-cache.mjs +8 -1
- package/dist/development/core/cache/fetch-with-cache.mjs.map +1 -1
- package/dist/development/core/cart/cart.mjs +1 -1
- package/dist/development/core/cart/cookie.mjs +6 -1
- package/dist/development/core/cart/cookie.mjs.map +1 -1
- package/dist/development/core/cart/form.d.mts +17 -5
- package/dist/development/core/cart/form.mjs +5 -0
- package/dist/development/core/cart/form.mjs.map +1 -1
- package/dist/development/core/cart/index.d.mts +1 -1
- package/dist/development/core/cart/queries.d.mts +57 -57
- package/dist/development/core/collection/url.mjs +8 -1
- package/dist/development/core/collection/url.mjs.map +1 -1
- package/dist/development/core/constants.mjs +2 -1
- package/dist/development/core/constants.mjs.map +1 -1
- package/dist/development/core/csp/index.d.mts +56 -0
- package/dist/development/core/csp/index.mjs +128 -0
- package/dist/development/core/csp/index.mjs.map +1 -0
- package/dist/development/core/csp/types.d.mts +52 -0
- package/dist/development/core/development.d.mts +14 -5
- package/dist/development/core/development.mjs +9 -2
- package/dist/development/core/headers.mjs +2 -2
- package/dist/development/core/headers.mjs.map +1 -1
- package/dist/development/core/i18n/define.d.mts +54 -0
- package/dist/development/core/i18n/define.mjs +135 -0
- package/dist/development/core/i18n/define.mjs.map +1 -0
- package/dist/development/core/i18n/errors.d.mts +18 -0
- package/dist/development/core/i18n/errors.mjs +24 -0
- package/dist/development/core/i18n/errors.mjs.map +1 -0
- package/dist/development/core/i18n/href.d.mts +28 -0
- package/dist/development/core/i18n/href.mjs +45 -0
- package/dist/development/core/i18n/href.mjs.map +1 -0
- package/dist/development/core/i18n/locale.d.mts +21 -0
- package/dist/development/core/i18n/locale.mjs +36 -0
- package/dist/development/core/i18n/locale.mjs.map +1 -0
- package/dist/development/core/i18n/match.d.mts +37 -0
- package/dist/development/core/i18n/match.mjs +82 -0
- package/dist/development/core/i18n/match.mjs.map +1 -0
- package/dist/development/core/i18n/types.d.mts +80 -0
- package/dist/development/core/index.d.mts +13 -4
- package/dist/development/core/predictive-search/index.d.mts +2 -2
- package/dist/development/core/predictive-search/queries.d.mts +2 -2
- package/dist/development/core/predictive-search/server-handlers.d.mts +27 -6
- package/dist/development/core/predictive-search/server-handlers.mjs +1 -4
- package/dist/development/core/predictive-search/server-handlers.mjs.map +1 -1
- package/dist/development/core/predictive-search/url.d.mts +2 -2
- package/dist/development/core/predictive-search/url.mjs.map +1 -1
- package/dist/development/core/product/accept-variant-id.mjs +1 -1
- package/dist/development/core/product/accept-variant-id.mjs.map +1 -1
- package/dist/development/core/request-context.d.mts +61 -35
- package/dist/development/core/request-context.mjs +11 -7
- package/dist/development/core/request-context.mjs.map +1 -1
- package/dist/development/core/request-routing/handle-shopify-routes.mjs.map +1 -1
- package/dist/development/core/request-routing/interceptors/api-proxy.mjs +9 -1
- package/dist/development/core/request-routing/interceptors/api-proxy.mjs.map +1 -1
- package/dist/development/core/request-routing/interceptors/checkout.mjs +11 -5
- package/dist/development/core/request-routing/interceptors/checkout.mjs.map +1 -1
- package/dist/development/core/request-routing/interceptors/standard-routes.mjs +1 -1
- package/dist/development/core/request-routing/interceptors/standard-routes.mjs.map +1 -1
- package/dist/development/core/request-routing/interceptors/url-redirects.mjs +2 -1
- package/dist/development/core/request-routing/interceptors/url-redirects.mjs.map +1 -1
- package/dist/development/core/request-routing/registered-routes.d.mts +10 -3
- package/dist/development/core/request-routing/registered-routes.mjs +13 -3
- package/dist/development/core/request-routing/registered-routes.mjs.map +1 -1
- package/dist/development/core/request-routing/route-types.d.mts +2 -2
- package/dist/development/core/shop-pay/shop-pay.mjs +5 -4
- package/dist/development/core/shop-pay/shop-pay.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/analytics.mjs +3 -5
- package/dist/development/core/shopify-scripts/analytics.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/constants.mjs +3 -1
- package/dist/development/core/shopify-scripts/constants.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/global.mjs +13 -11
- package/dist/development/core/shopify-scripts/global.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/hashes.d.mts +17 -0
- package/dist/development/core/shopify-scripts/hashes.mjs +12 -0
- package/dist/development/core/shopify-scripts/hashes.mjs.map +1 -0
- package/dist/development/core/shopify-scripts/index.d.mts +1 -0
- package/dist/development/core/shopify-scripts/index.mjs +12 -9
- package/dist/development/core/shopify-scripts/index.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/page-view.mjs +4 -1
- package/dist/development/core/shopify-scripts/page-view.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/types.d.mts +4 -2
- package/dist/development/core/shopify-scripts/utils/inline-script.mjs +4 -1
- package/dist/development/core/shopify-scripts/utils/inline-script.mjs.map +1 -1
- package/dist/development/core/standard-routes/build.d.mts +7 -2
- package/dist/development/core/standard-routes/build.mjs +10 -3
- package/dist/development/core/standard-routes/build.mjs.map +1 -1
- package/dist/development/core/standard-routes/match.mjs +11 -1
- package/dist/development/core/standard-routes/match.mjs.map +1 -1
- package/dist/development/core/standard-routes/path.mjs +14 -3
- package/dist/development/core/standard-routes/path.mjs.map +1 -1
- package/dist/development/core/standard-routes/types.d.mts +6 -1
- package/dist/development/core/url.mjs +5 -3
- package/dist/development/core/url.mjs.map +1 -1
- package/dist/development/customer-account/session.mjs.map +1 -1
- package/dist/development/globals.d.mts +8 -4
- package/dist/development/graphql/type-resolver.d.mts +13 -1
- package/dist/development/react/index.d.mts +2 -2
- package/dist/globals.d.mts +8 -4
- package/dist/graphql/type-resolver.d.mts +13 -1
- package/dist/react/index.d.mts +2 -2
- package/dist/vite/index.mjs +1 -1
- package/dist/vue/shopify-scripts.d.mts +1 -1
- package/package.json +13 -3
- package/skills/hydrogen-analytics/SKILL.md +2 -2
- package/skills/hydrogen-analytics/references/react.md +2 -2
- package/skills/hydrogen-markets/SKILL.md +127 -93
- package/skills/hydrogen-markets/references/nextjs.md +77 -87
- package/skills/hydrogen-oxygen/references/react-router.md +1 -2
- package/skills/hydrogen-predictive-search/SKILL.md +18 -1
- package/skills/hydrogen-request-handlers/SKILL.md +23 -5
- package/skills/hydrogen-request-handlers/references/content-security-policy.md +103 -0
- package/skills/hydrogen-request-handlers/references/frameworks.md +8 -6
- package/skills/hydrogen-request-handlers/references/nextjs.md +7 -3
- package/skills/hydrogen-request-handlers/references/nuxt.md +7 -5
- package/skills/hydrogen-robots-txt/SKILL.md +87 -0
- package/skills/hydrogen-routing/SKILL.md +36 -14
- package/skills/hydrogen-setup/SKILL.md +2 -2
- package/skills/hydrogen-setup/references/analytics.md +5 -5
- package/skills/hydrogen-setup/steps/2-scaffold.md +3 -0
- package/skills/hydrogen-setup/steps/7-shopify-runtime-scripts.md +4 -3
- package/skills/hydrogen-setup/steps/9-account-page.md +1 -1
- package/skills/hydrogen-smoke-test/SKILL.md +9 -2
- package/skills/hydrogen-storefront-client/SKILL.md +27 -9
- package/skills/hydrogen-storefront-client/references/astro.md +8 -3
- package/skills/hydrogen-storefront-client/references/caching.md +2 -0
- package/skills/hydrogen-storefront-client/references/nextjs.md +8 -3
- package/skills/hydrogen-storefront-client/references/nuxt.md +9 -5
- package/skills/hydrogen-storefront-client/references/react-router.md +6 -3
- package/skills/hydrogen-storefront-client/references/solidstart.md +6 -2
- package/skills/hydrogen-storefront-client/references/sveltekit.md +10 -4
- package/skills/migrate-to-hydrogen-2026-10/SKILL.md +20 -22
- package/skills/migrate-to-hydrogen-2026-10/references/sitemap-and-seo.md +1 -0
- package/skills/migrate-to-hydrogen-2026-10/references/typescript-and-gql-tada.md +1 -1
|
@@ -15,7 +15,7 @@ Migrate a classic-Hydrogen storefront (Remix- or React-Router-based) to Hydrogen
|
|
|
15
15
|
|
|
16
16
|
## The mental model (get this right first)
|
|
17
17
|
|
|
18
|
-
1. **Hydrogen 2026-10 is a server-handler library, not a framework.** (A `@shopify/hydrogen` version **before `2026.10` is still the old framework**, not the library — the classic line runs through `2026.4.x` — so an installed version below `2026.10` means the store hasn't been migrated yet, regardless of its React Router status.) You compose the request lifecycle yourself: `createShopifyRequestContext({request, i18n, buyerIp})` → `createStorefrontClient({type: 'private', requestContext, config})` (config carries `storeDomain`, `privateStorefrontToken`, `storefrontId`, `cache`, `waitUntil`; a store without a private token uses `type: 'public'` instead — see the `hydrogen-storefront-client` packaged skill for the choice) → `handleShopifyRoutes({request, requestContext,
|
|
18
|
+
1. **Hydrogen 2026-10 is a server-handler library, not a framework.** (A `@shopify/hydrogen` version **before `2026.10` is still the old framework**, not the library — the classic line runs through `2026.4.x` — so an installed version below `2026.10` means the store hasn't been migrated yet, regardless of its React Router status.) You compose the request lifecycle yourself: `createShopifyRequestContext({request, i18n, buyerIp})` → `createStorefrontClient({type: 'private', requestContext, config})` (config carries `storeDomain`, `privateStorefrontToken`, `storefrontId`, `cache`, `waitUntil`; a store without a private token uses `type: 'public'` instead — see the `hydrogen-storefront-client` packaged skill for the choice) → `handleShopifyRoutes({request, requestContext, storefrontClient, routeTemplates, handlers})`, plus `sessionManager` when a registered handler reads the session (returns a `Promise<Response>` for handler-owned paths, else `null` — decided synchronously, so truthy-check it without `await`) → `handleShopifyRedirects` on 404 → handler groups for the rest: `createCartServerHandlers()` for cart and `createCustomerAccountServerHandlers(…)` (from `@shopify/hydrogen/customer-account`) for auth, both registered through the `handlers` array. Hydrogen no longer owns routing or the entry — you wire these into your React Router server/middleware.
|
|
19
19
|
|
|
20
20
|
2. **Dev and build are plain Vite/React Router — the classic `shopify hydrogen dev|build` commands and the `hydrogen()` Vite plugin are gone.** `dev` is `vite dev` with the `oxygen()` plugin from `@shopify/mini-oxygen/vite` (workerd runtime, `.env` injection); `build` is `react-router build`; `preview` is `vite preview` after a build. The `hydrogen` bin that ships with the library covers the rest: `hydrogen setup`, `hydrogen skills check|sync`, `hydrogen gql check`, `npx hydrogen certs install|uninstall` for local HTTPS. `@shopify/cli` stays a devDependency for the `shopify hydrogen` commands the library does not replace: `deploy`, `link`, `env pull`. Do **not** add `@shopify/hydrogen-classic` or any aliased classic package — the 2026-10 library has no classic sibling.
|
|
21
21
|
|
|
@@ -33,19 +33,20 @@ Hydrogen migration:
|
|
|
33
33
|
- [ ] 1. Dependencies + version pins (@shopify/hydrogen ^2026.10.0 and the seed below; drop classic-era deps)
|
|
34
34
|
- [ ] 2. Scripts: hydrogen skills check --mode=warn && vite dev / react-router build / vite preview; deploy via @shopify/cli
|
|
35
35
|
- [ ] 3. vite.config plugins: [localHttps({enabled}), ...oxygen(), reactRouter()]
|
|
36
|
-
- [ ] 4. react-router.config.ts added (
|
|
37
|
-
- [ ] 5. Request wiring (request context + storefront client + route templates
|
|
36
|
+
- [ ] 4. react-router.config.ts added (middleware enabled for your React Router version, buildDirectory 'dist')
|
|
37
|
+
- [ ] 5. Request wiring (request context + storefront client + route templates, plus a session manager when a handler needs one)
|
|
38
38
|
- [ ] 6. Route filename + import + json()/defer() sweep
|
|
39
|
-
- [ ] CSP/nonce:
|
|
39
|
+
- [ ] CSP/nonce: create a per-document policy with `createContentSecurityPolicy({shop})` and apply it with `csp.applyResponseHeaders(response.headers)`; keep React nonce context in app code, then check the browser console for CSP violations
|
|
40
40
|
- [ ] 7. Connect a store — env vars in .env (private token, or public token), or MOCK_SHOP=1 for the tokenless mock.shop demo
|
|
41
41
|
- [ ] Optional subsystems: detect each → migrate or skip, and report every skip
|
|
42
|
+
- [ ] Root middleware runs: GET /api/cart returns 200 JSON from the cart handler; a 404 or the app's 404 page means middleware isn't enabled for your React Router version (step 4)
|
|
42
43
|
- [ ] 8. Verify (build/typecheck gate, hydrogen-smoke-test, browser console on the home page), then hand off to the user
|
|
43
44
|
```
|
|
44
45
|
|
|
45
46
|
1. **Dependencies** — *(Remix swap only if not already on React Router)* replace `@remix-run/react`, `@remix-run/node`, `@remix-run/server-runtime`, `@remix-run/dev` and `@shopify/remix-oxygen` with `react-router` + `@react-router/dev` (pin all React Router packages to one version; `react-router-dom` is not needed). Add `@shopify/hydrogen`, `@shopify/mini-oxygen`, `vite`, the `@types/*` packages and `@shopify/cli` at the versions in the seed below. Remove `@shopify/cli-hydrogen` and any `@shopify/hydrogen-classic`-style alias if present. Align versions to the seed rather than picking latest of each independently, and never pin React Router below the version the app already runs.
|
|
46
47
|
2. **Scripts** — `dev`: `hydrogen skills check --mode=warn && vite dev` (the prefix prints the resync command after a later `@shopify/hydrogen` bump without blocking dev; plain `hydrogen skills check` belongs in CI); `build`: `react-router build`; `preview`: `react-router build && vite preview`; `deploy`: `shopify hydrogen deploy --assets-dir dist/client --worker-dir dist/server`. Add `dev:https` with the **same** command — the vite.config computes the `localHttps` `enabled` flag from `npm_lifecycle_event` (step 3), not the script body.
|
|
47
48
|
3. **`vite.config`** — plugins are `[localHttps({enabled}), ...oxygen(), reactRouter()]`, with `localHttps` from `@shopify/hydrogen/vite` and `oxygen` from `@shopify/mini-oxygen/vite` (it returns an **array** — spread it). `localHttps` takes a **required** `enabled: boolean` — it does not self-detect; compute it in the config: `const enabled = process.env.npm_lifecycle_event === 'dev:https'`. There is no `hydrogen()` plugin anymore. You do **not** pass an oxygen `entry` — it picks up the React Router server build.
|
|
48
|
-
4. **`react-router.config.ts`** — add it (React Router framework config + future flags
|
|
49
|
+
4. **`react-router.config.ts`** — add it (React Router framework config + future flags). Make sure middleware is enabled for your version of React Router — the middleware skeleton below depends on it. Set `buildDirectory: 'dist'` — React Router defaults to `build/`, and the deploy script's `--assets-dir dist/client --worker-dir dist/server` flags silently point at nothing without it. Explicit `routes.ts` route config and flat routes via `@react-router/fs-routes` both work — for a migration, fs-routes preserves the existing flat route filenames with the least churn.
|
|
49
50
|
5. **Request wiring** — in your server entry or a root middleware, build the request context and clients (mental-model step 1) and expose the storefront client to loaders via typed React Router contexts. If you already thread Oxygen `env`/`executionContext` through a context provider, keep it — the library does not force a specific context shape.
|
|
50
51
|
6. **Routes & imports** — *(skip the import swap if already on React Router)* swap `@remix-run/*` imports to `react-router`; migrate `json()`/`defer()` loader/action return helpers.
|
|
51
52
|
7. **Connect a store** — set `PUBLIC_STORE_DOMAIN`, `PUBLIC_STOREFRONT_ID` and `PRIVATE_STOREFRONT_API_TOKEN` in `.env` (on Oxygen, a linked storefront injects them); a store with only `PUBLIC_STOREFRONT_API_TOKEN` still uses the real store through the public client. Customer accounts add `SHOP_ID`, `PUBLIC_CUSTOMER_ACCOUNT_API_CLIENT_ID` and `SESSION_SECRET` (full list in `references/dependencies-and-tooling.md`). With `MOCK_SHOP=1`, or no store domain at all, the skeleton's client factory falls back to the tokenless mock.shop demo store — useful to verify the migration before the user supplies credentials. mock.shop only accepts a **tokenless public client** (it rejects the private-token header with a 401), and it is a catalog of fictional stores: https://mock.shop/llms.txt lists them.
|
|
@@ -144,6 +145,7 @@ import {
|
|
|
144
145
|
type CachingStrategy,
|
|
145
146
|
createShopifyRequestContext,
|
|
146
147
|
createStorefrontClient,
|
|
148
|
+
defineShopifyI18n,
|
|
147
149
|
type PublicStorefrontClient,
|
|
148
150
|
type RequestScopedPrivateStorefrontClient,
|
|
149
151
|
type ShopifyRequestContext,
|
|
@@ -173,14 +175,15 @@ function getBuyerIp(headers: Headers) {
|
|
|
173
175
|
throw new Error('No buyer IP header on the request');
|
|
174
176
|
}
|
|
175
177
|
|
|
178
|
+
// Module scope. Add `routing` to serve more locales by path prefix or hostname; the request context matches the locale from the URL.
|
|
179
|
+
const i18n = defineShopifyI18n({defaultLocale: {country: 'US', language: 'EN'}});
|
|
180
|
+
|
|
176
181
|
export function createRequestStorefrontClient(
|
|
177
182
|
request: Request,
|
|
178
183
|
env: Env,
|
|
179
184
|
cache: CacheInstance,
|
|
180
185
|
waitUntil: ExecutionContext['waitUntil'],
|
|
181
186
|
): RequestStorefrontClient {
|
|
182
|
-
const i18n = {country: 'US', language: 'EN'} as const; // or derive from the URL/domain
|
|
183
|
-
|
|
184
187
|
// mock.shop is auth-free and 401s any token header, so it always gets the tokenless public client.
|
|
185
188
|
if (env.MOCK_SHOP === '1' || !env.PUBLIC_STORE_DOMAIN) {
|
|
186
189
|
return createStorefrontClient({
|
|
@@ -223,21 +226,20 @@ export function createRequestStorefrontClient(
|
|
|
223
226
|
`app/lib/route-templates.ts` — maps Shopify entities to your route shapes. Pass it to `handleShopifyRoutes` (optional in the type, but handler-owned URLs come out wrong without it), to `handleShopifyRedirects` (**required** there), and to the `routes` prop of `ShopifyScripts`:
|
|
224
227
|
|
|
225
228
|
```ts
|
|
226
|
-
import {
|
|
227
|
-
export const routeTemplates =
|
|
229
|
+
import {defineShopifyRouteTemplates} from '@shopify/hydrogen';
|
|
230
|
+
export const routeTemplates = defineShopifyRouteTemplates({
|
|
228
231
|
productInCollection: '/products/:productHandle',
|
|
229
232
|
});
|
|
230
233
|
```
|
|
231
234
|
|
|
232
|
-
**Classic data-layer call-sites map mechanically:** `storefront.query()` → `client.graphql(QUERY, {variables, cache})`, which returns `{data, errors, headers}` instead of merging errors into the result — check `errors` before reading `data`; `$country`/`$language` are auto-injected, so drop them from `variables`; `storefront.CacheLong()` → the per-call `Cache.long()` (classic's implicit default caching is **gone**, so give every query that relied on it an explicit `cache`, `Cache.short()` or `Cache.long()`, or it hits the API on every request); `storefront.i18n` → `client.i18n
|
|
235
|
+
**Classic data-layer call-sites map mechanically:** `storefront.query()` → `client.graphql(QUERY, {variables, cache})`, which returns `{data, errors, headers}` instead of merging errors into the result — check `errors` before reading `data`; `$country`/`$language` are auto-injected, so drop them from `variables`; `storefront.CacheLong()` → the per-call `Cache.long()` (classic's implicit default caching is **gone**, so give every query that relied on it an explicit `cache`, `Cache.short()` or `Cache.long()`, or it hits the API on every request); `storefront.i18n` → `client.locale` (the resolved `{language, country, pathPrefix}`; `client.i18n` is a deprecated alias of it).
|
|
233
236
|
|
|
234
|
-
Root **middleware** in `app/root.tsx` (needs
|
|
237
|
+
Root **middleware** in `app/root.tsx` (needs middleware enabled, see step 4) — the request lifecycle from mental-model step 1:
|
|
235
238
|
|
|
236
239
|
```ts
|
|
237
240
|
import {handleShopifyRedirects, handleShopifyRoutes} from '@shopify/hydrogen';
|
|
238
241
|
import {cartHandlers} from '~/lib/cart-handlers';
|
|
239
242
|
import {routeTemplates} from '~/lib/route-templates';
|
|
240
|
-
import {createEphemeralSessionManager} from '~/lib/session';
|
|
241
243
|
import {
|
|
242
244
|
createRequestStorefrontClient, envContext, storefrontClientContext, storefrontRequestContext,
|
|
243
245
|
} from '~/lib/storefront';
|
|
@@ -248,10 +250,9 @@ export const middleware: Route.MiddlewareFunction[] = [
|
|
|
248
250
|
const env = context.get(envContext);
|
|
249
251
|
const storefrontClient = createRequestStorefrontClient(request, env, context.cache, context.waitUntil);
|
|
250
252
|
const requestContext = storefrontClient.requestContext; // reuse — a fresh one throws in handleShopifyRoutes
|
|
251
|
-
const sessionManager = createEphemeralSessionManager(request);
|
|
252
253
|
|
|
253
254
|
const shopifyRoute = handleShopifyRoutes({ // handler-owned paths (e.g. /api/cart) return early
|
|
254
|
-
request, requestContext,
|
|
255
|
+
request, requestContext, storefrontClient, routeTemplates, handlers: [cartHandlers], // cart handlers don't read the session
|
|
255
256
|
});
|
|
256
257
|
if (shopifyRoute) return shopifyRoute; // Promise<Response> or null — do NOT await the call
|
|
257
258
|
|
|
@@ -259,9 +260,6 @@ export const middleware: Route.MiddlewareFunction[] = [
|
|
|
259
260
|
context.set(storefrontRequestContext, requestContext);
|
|
260
261
|
|
|
261
262
|
const response = await next();
|
|
262
|
-
|
|
263
|
-
const sessionHeaders = new Headers((await sessionManager.commit?.()) ?? undefined);
|
|
264
|
-
for (const [name, value] of sessionHeaders) response.headers.append(name, value);
|
|
265
263
|
if (response.status === 404) { // 404 → Shopify URL redirects
|
|
266
264
|
const redirect = await handleShopifyRedirects({request, storefrontClient, routeTemplates});
|
|
267
265
|
if (redirect) return redirect; // headers already applied by the library
|
|
@@ -272,7 +270,7 @@ export const middleware: Route.MiddlewareFunction[] = [
|
|
|
272
270
|
];
|
|
273
271
|
```
|
|
274
272
|
|
|
275
|
-
|
|
273
|
+
**Session manager — only when a handler reads the session.** Plain `createCartServerHandlers()` doesn't, so the cart-only middleware above passes no `sessionManager`. Customer Account handlers and cart handlers created with `customerSession` do, and `handleShopifyRoutes` then requires one at the type level. The `sessionManager` contract is **four required methods** (item values are typed `unknown`, not `string`) plus an optional `commit()` that returns cookie headers; after `next()`, append those headers to the response before the 404 check, as the template's root middleware does. For customer accounts, copy the template's cookie-backed `createRequestSessionManager` from `app/lib/session.ts` (a signed `__Host-session` cookie built on `@remix-run/cookie` + `@remix-run/session`, keyed by `SESSION_SECRET`). An in-memory map can't complete Customer Account login: the OAuth state is written on `/account/login` and read back on `/account/authorize`, two different requests. If you register the account handlers only when Customer Accounts are configured, as the template does, the handler types still require a session manager on every request. For requests without Customer Accounts, the template passes an in-memory stand-in:
|
|
276
274
|
|
|
277
275
|
```ts
|
|
278
276
|
import type {WritableCustomerSessionManager} from '@shopify/hydrogen/customer-account';
|
|
@@ -293,9 +291,9 @@ export function createEphemeralSessionManager(request: Request): WritableCustome
|
|
|
293
291
|
}
|
|
294
292
|
```
|
|
295
293
|
|
|
296
|
-
Supporting files: `app/lib/cart-handlers.ts` → `export const cartHandlers = createCartServerHandlers()` (options: `fragment` to extend the cart query, `customerSession` to sync buyer identity — see `references/cart.md`); `app/lib/cart.ts` → `createCartComponents<typeof cartHandlers>()` yields `CartProvider`/`useCart`/`useCartForm`; when the store has customer accounts, add the `createCustomerAccountServerHandlers({customerSession, …})` group next to `cartHandlers` in the middleware's `handlers` array and
|
|
294
|
+
Supporting files: `app/lib/cart-handlers.ts` → `export const cartHandlers = createCartServerHandlers()` (options: `fragment` to extend the cart query, `customerSession` to sync buyer identity — see `references/cart.md`); `app/lib/cart.ts` → `createCartComponents<typeof cartHandlers>()` yields `CartProvider`/`useCart`/`useCartForm`; when the store has customer accounts, add the `createCustomerAccountServerHandlers({customerSession, …})` group next to `cartHandlers` in the middleware's `handlers` array and pass the cookie-backed session manager as `sessionManager` (see `references/customer-account.md`); `react-router.config.ts` → `{buildDirectory: 'dist'}` plus middleware enabled for your version of React Router (step 4).
|
|
297
295
|
|
|
298
|
-
Two lines in that middleware are easy to omit and fail **silently**: `applyResponseHeaders` on the normal response path (Shopify response headers disappear) and `routeTemplates` into both handler calls (handler-owned URLs and redirect targets come out wrong). A third, `buyerIp` into `createShopifyRequestContext`, fails **loudly** for the private client (`TypeError: requestContext.buyerIp is required for private Storefront API clients`) — keep the `getBuyerIp` helper rather than deleting the option to silence it. For the customer-account session wiring, follow the `hydrogen-customer-account` packaged skill rather than extending the in-memory
|
|
296
|
+
Two lines in that middleware are easy to omit and fail **silently**: `applyResponseHeaders` on the normal response path (Shopify response headers disappear) and `routeTemplates` into both handler calls (handler-owned URLs and redirect targets come out wrong). A third, `buyerIp` into `createShopifyRequestContext`, fails **loudly** for the private client (`TypeError: requestContext.buyerIp is required for private Storefront API clients`) — keep the `getBuyerIp` helper rather than deleting the option to silence it. For the customer-account session wiring, follow the `hydrogen-customer-account` packaged skill rather than extending the in-memory stand-in by hand.
|
|
299
297
|
|
|
300
298
|
## Optional subsystems
|
|
301
299
|
|
|
@@ -321,11 +319,11 @@ Each file is a short list of the specific "it renders but is wrong" traps for th
|
|
|
321
319
|
|
|
322
320
|
## Verification
|
|
323
321
|
|
|
324
|
-
Don't trust "it renders." Gate on the build first: `react-router build` and `react-router typegen && tsc && hydrogen gql check --fail-on-warn` must both exit 0 (most import/return-helper and gql traps surface here — fix the root cause, don't suppress it; a red build makes everything downstream meaningless). Then run the local `hydrogen-smoke-test` skill for functional/runtime verification — request handlers, product, cart, collection/search, analytics, money, and the production pass. That skill owns "does the storefront work"; don't restate its checks here.
|
|
322
|
+
Don't trust "it renders." Gate on the build first: `react-router build` and `react-router typegen && tsc && hydrogen gql check --fail-on-warn` must both exit 0 (most import/return-helper and gql traps surface here — fix the root cause, don't suppress it; a red build makes everything downstream meaningless). Next, prove the root middleware actually runs: with the dev server up, `GET /api/cart` must return 200 JSON from the Hydrogen cart handler. A 404, or the app's own 404 page, means middleware isn't enabled for your React Router version (step 4), so cart routes, redirects, the storefront context and response headers are all silently skipped. Then run the local `hydrogen-smoke-test` skill for functional/runtime verification — request handlers, product, cart, collection/search, analytics, money, and the production pass. That skill owns "does the storefront work"; don't restate its checks here.
|
|
325
323
|
|
|
326
324
|
After the build gate and smoke test pass, **keep the dev server running and load the home page in a browser.** Fix every console error and warning before handing off. If you have no browser tool, say so in the handoff and ask the user to check the console themselves. Then hand off to the user. Tell them to test the migrated code with `npm run dev` (or `npm run dev:https` when they need customer login locally), and to pay special attention to the areas a migration most often gets subtly wrong while still compiling:
|
|
327
325
|
|
|
328
|
-
- **CSP/nonce** —
|
|
326
|
+
- **CSP/nonce** — use `createContentSecurityPolicy({shop})` from `@shopify/hydrogen`. The returned policy exposes `nonce` and `header`; `csp.applyResponseHeaders()` sends the policy and prevents nonce-bearing HTML from being cached. Apply Shopify request-context headers separately with `requestContext.applyResponseHeaders(response.headers)`. Keep `NonceProvider`/`useNonce` in app code and pass the nonce to the server renderer, framework scripts, and `ShopifyScripts`. For cached HTML or a prerendered shell, use `nonce: false` and authorize inline scripts explicitly; CSP then leaves cache headers unchanged. Move classic's top-level directive properties under `directives`; arrays still extend defaults, with a replacement exception for defaults consisting only of `'none'`. Convert source strings to arrays and `false` omissions to `null`. Review `defaultSrc` customizations: the new policy has explicit script, image, font, media, and frame directives that take precedence over the fallback. The development build adds common local connection sources automatically. See `hydrogen-request-handlers/references/content-security-policy.md` for the full migration comparison and framework wiring. A dropped nonce can silently prevent hydration — verify browser behavior after migrating.
|
|
329
327
|
- **Analytics** — the commerce funnel (`view_item`/`add_to_cart`/…) silently dropping while page views still fire (`references/analytics.md`).
|
|
330
328
|
- **Cart actions** — add / remove / quantity edits and the drawer opening on add (`references/cart.md`).
|
|
331
329
|
- **Customer login** — the full OAuth round-trip, which needs an HTTPS origin locally (`references/customer-account.md`).
|
|
@@ -3,3 +3,4 @@
|
|
|
3
3
|
Read if the source has `sitemap.xml`/`robots.txt` routes or a `seo` export.
|
|
4
4
|
|
|
5
5
|
- **Sitemaps: `getSitemap`/`getSitemapIndex` are gone.** The 2026-10 library does not ship them, and the classic versions were typed for the classic `Storefront` client (`.query`) — the new request-scoped client only exposes `.graphql`, so they don't port. Write a small local `app/lib/sitemap.ts` that runs the sitemap queries via `storefront.graphql` and preserves any custom URL transforms (renamed routes, locale prefixes). The route files then call the local lib.
|
|
6
|
+
- **robots.txt: keep the merchant's rules, then add the new handler paths.** The classic route ports as-is, so don't swap it for a default file. Remove anything that queries the classic client (`context.storefront.query(ROBOTS_QUERY)` for `shop.id`, used only to build `/{shopId}/checkouts` and `/{shopId}/orders` rules). Re-check each rule against the migrated routes, and drop rules for paths the app no longer serves. Then add rules for the paths Hydrogen 2026-10's request handlers serve when they aren't already covered: `/admin`, `/checkout`, `/buy/`, `/api/`, `/__shopify`. Keep `/.well-known/` reachable. Invoke the `hydrogen-robots-txt` skill for the reason behind each rule. If the source has no robots.txt route, add one with that skill.
|
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
These surface when you run `react-router typegen && tsc` and `hydrogen gql check`. Read before wiring typed queries or re-pointing imports.
|
|
4
4
|
|
|
5
5
|
- **Typed GraphQL runs through the library's ts-plugin, not app-owned gql.tada config.** `@shopify/hydrogen` ships the schemas and a TypeScript plugin: add `{"name": "@shopify/hydrogen/ts-plugin"}` to `compilerOptions.plugins` in `tsconfig.json` and delete any classic-era gql.tada `schema`/`schemas` tsconfig block pointing at generated schema files. The plugin writes its schema environments (`*-graphql-env.d.ts`) at the **project root**; gitignore them. Add `hydrogen gql check --fail-on-warn` to the `typecheck` script — a wrong setup fails silently otherwise: typing just stops working, and nothing errors until you run the check. Type results with the `StorefrontApi` namespace / `ResultOf`; the library's `gql()` returns a **branded query string**, not a gql.tada document, so `FragmentOf` does **not** apply — to type a fragment's data, compose a throwaway query that spreads the fragment and take `ResultOf` of that (see the `hydrogen-storefront-client` packaged skill).
|
|
6
|
-
- **Framework types dropped from core are gone — but check the installed exports before shimming.** Types the app imported from `@shopify/hydrogen` in classic Hydrogen (e.g. `I18nBase`) may no longer be exported, so a bare type import fails with "no exported member". `I18nBase` → the library's `
|
|
6
|
+
- **Framework types dropped from core are gone — but check the installed exports before shimming.** Types the app imported from `@shopify/hydrogen` in classic Hydrogen (e.g. `I18nBase`) may no longer be exported, so a bare type import fails with "no exported member". `I18nBase` → the library's `ShopifyLocale` (or `ShopifyMatchedLocale` for the resolved locale with `pathPrefix`). API object types → `@shopify/hydrogen/storefront-api-types` and `.../customer-account-api-types`. Several classic helpers **returned to core** (`flattenConnection`, `getSelectedProductOptions`, `formatMoney`, the `MoneyV2` type) — grep the installed package's `.d.mts` exports first. Only what is genuinely absent (component prop shapes, other helpers' types) gets a small local structural type for the fields the app actually uses; there is no classic package to fall back to.
|
|
7
7
|
- **gql result types are *partial and union-shaped*, unlike the old generated types.** Two distinct traps: (1) A query on a union/interface field (storefront `search`, metaobject `references`) is typed as the **full union** — the `types:`/`unavailableProducts:` argument and a single `...on X` inline fragment do **not** narrow it at the type level, so non-`X` members appear with only `__typename` and field access fails. Narrow with `Extract<…nodes[number], {__typename: 'X'}>` (a cast is honest here since the arg guarantees the runtime type). (2) A selection-derived type is **not** assignable to the full `storefront-api-types` type a component prop declares (e.g. `ProductVariant` requires `metafields` via `HasMetafields`, which the query didn't select). Either loosen the prop to the fields actually read (structural type) or bridge with a cast at the one boundary. Make `<Money>`/price components accept a structural `{amount, currencyCode}` and tolerate `null`/`undefined` — this also resolves the storefront-vs-customer-account `MoneyV2` **brand clash** that otherwise fails at every account money render.
|