@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
|
@@ -90,10 +90,13 @@ Invoke the `hydrogen-storefront-client` skill to wire the Storefront API client
|
|
|
90
90
|
|
|
91
91
|
Invoke the `hydrogen-request-handlers` skill to wire `handleShopifyRoutes` before routing, `handleShopifyRedirects` after a 404 or in the framework's catch-all route, and request-context response-header propagation for custom and framework responses.
|
|
92
92
|
|
|
93
|
+
Then invoke the `hydrogen-robots-txt` skill to serve `/robots.txt`, so crawlers stay off the cart, account, checkout, and Hydrogen handler paths.
|
|
94
|
+
|
|
93
95
|
### Continue when
|
|
94
96
|
|
|
95
97
|
- [ ] `/api/graphiql` returns 200 in development mode
|
|
96
98
|
- [ ] `/admin` redirects to the Shopify Admin in development mode
|
|
99
|
+
- [ ] `/robots.txt` returns 200 `text/plain` with the `hydrogen-robots-txt` rules adjusted to the app's routes
|
|
97
100
|
|
|
98
101
|
## Set Up The Customer Account API
|
|
99
102
|
|
|
@@ -21,8 +21,9 @@ const shop: ShopifyScriptsShop = {
|
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
const i18n: ShopifyScriptsI18n = {
|
|
24
|
-
country, //
|
|
25
|
-
language, //
|
|
24
|
+
country: requestContext.locale.country, // e.g. "US"
|
|
25
|
+
language: requestContext.locale.language, // e.g. "EN"
|
|
26
|
+
pathPrefix: requestContext.locale.pathPrefix, // "" for the default locale
|
|
26
27
|
};
|
|
27
28
|
```
|
|
28
29
|
|
|
@@ -32,7 +33,7 @@ All three `shop` fields are required and identify different things:
|
|
|
32
33
|
- `storefrontId` — the specific **headless/Hydrogen storefront instance** attached to the shop. A shop can have several storefronts; analytics and PerfKit use this ID to attribute traffic to this one. Use `"0"` when the app has no provisioned storefront ID.
|
|
33
34
|
- `myshopifyDomain` — the shop's permanent `*.myshopify.com` domain, exposed as `window.Shopify.shop`.
|
|
34
35
|
|
|
35
|
-
`i18n` is the same resolved
|
|
36
|
+
`i18n` is the same resolved locale used by Storefront API requests: read `country`, `language`, and `pathPrefix` from `requestContext.locale` (or `storefrontClient.locale`), plus optional `currency`. It is not the `defineShopifyI18n` definition, not a locale string, and not the analytics consent config.
|
|
36
37
|
|
|
37
38
|
For vanilla browser code that does not use SSR or a framework head API, render the HTML from core and include it in the document shell. If your app renders tags through core helpers instead of a framework binding, call `initializeShopifyScripts()` from bundled client code:
|
|
38
39
|
|
|
@@ -41,7 +41,7 @@ Invoke the `hydrogen-customer-account` skill for the session/token rules (read-o
|
|
|
41
41
|
|
|
42
42
|
## OAuth Caveat
|
|
43
43
|
|
|
44
|
-
Completing a real login requires a public HTTPS origin whose `/account/authorize` callback is registered in the Customer Account app configuration. When the local
|
|
44
|
+
Completing a real login requires a public HTTPS origin whose `/account/authorize` callback is registered in the Customer Account app configuration. When account routes fail with "Customer Account OAuth origin must use HTTPS", follow the `hydrogen-local-https` skill. On Vite-based frameworks, the path is the `dev:https` script run in a real terminal outside CI: the `localHttps` Vite plugin then serves trusted HTTPS and registers the Customer Account callback, JavaScript origin, and logout URLs through Shopify CLI (Next.js needs those URLs configured manually; see that skill). Agent shells usually run with `CI` set and no TTY, which skips both, so ask the user to run `dev:https` themselves. `npx hydrogen certs install` only provisions certificate files; it registers no URLs. If the user can't run `dev:https`, verify the signed-out rendering and handler wiring; skip the signed-in checks and say so instead of faking them.
|
|
45
45
|
|
|
46
46
|
## Continue when
|
|
47
47
|
|
|
@@ -4,7 +4,7 @@ description: >
|
|
|
4
4
|
Smoke-test checklist for Hydrogen storefronts built by agents. Use after
|
|
5
5
|
creating or modifying a Hydrogen storefront, setup flow, cart, product page,
|
|
6
6
|
collection/search browsing, analytics, request handlers, Shopify redirects,
|
|
7
|
-
Shop Pay, or framework middleware integration.
|
|
7
|
+
robots.txt, Shop Pay, or framework middleware integration.
|
|
8
8
|
---
|
|
9
9
|
|
|
10
10
|
# Hydrogen Storefront Smoke Tests
|
|
@@ -29,6 +29,7 @@ Request handlers:
|
|
|
29
29
|
- [ ] GET /api/cart returns cart handler JSON (no cart cookie -> {cart: null})
|
|
30
30
|
- [ ] GET /admin redirects to the configured shop/admin domain
|
|
31
31
|
- [ ] Unknown path returns framework 404 unless a Shopify URL redirect matches
|
|
32
|
+
- [ ] When the app serves /robots.txt: 200 text/plain, publicly cacheable, no Set-Cookie
|
|
32
33
|
|
|
33
34
|
Navigation:
|
|
34
35
|
- [ ] Every navbar and footer link href returns 200 when curled directly (no invented routes)
|
|
@@ -125,6 +126,12 @@ curl -i http://localhost:<port>/this-does-not-exist
|
|
|
125
126
|
|
|
126
127
|
Expected: framework 404 unless Shopify has a matching URL redirect.
|
|
127
128
|
|
|
129
|
+
```bash
|
|
130
|
+
curl -i http://localhost:<port>/robots.txt
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Run this check when the app serves `/robots.txt`. Expected: `200` with `Content-Type: text/plain`, a public `Cache-Control`, and no `Set-Cookie` header. The rules themselves are the app's policy; see the `hydrogen-robots-txt` skill.
|
|
134
|
+
|
|
128
135
|
## Navigation
|
|
129
136
|
|
|
130
137
|
Extract every `href` from the rendered navbar and footer and request each one directly:
|
|
@@ -145,7 +152,7 @@ Expected: a redirect whose `location` header points at Shopify's hosted login, n
|
|
|
145
152
|
|
|
146
153
|
- `/account` renders the signed-out panel when no session exists, without touching access tokens.
|
|
147
154
|
- The logout control is a native `<form method="post" action="/account/logout">`; the handler enforces same-origin POST and returns a raw redirect only a native browser submit can follow.
|
|
148
|
-
- Completing a real login requires a public HTTPS origin registered for the OAuth callback;
|
|
155
|
+
- Completing a real login requires a public HTTPS origin registered for the OAuth callback. To get one locally, follow the `hydrogen-local-https` skill. On Vite-based frameworks, ask the user to run the `dev:https` script in a real terminal outside CI, where the `localHttps` Vite plugin serves trusted HTTPS and registers the Customer Account URLs through Shopify CLI. Next.js needs its HTTPS command and manual URL configuration; see that skill. Agent shells usually run with `CI` set and no TTY, so don't assume the agent shell can complete local HTTPS or URL registration itself. `npx hydrogen certs install` only provisions certificate files; it registers no URLs. If the user can't provide a registered HTTPS local origin, verify the signed-out checks and say so instead of faking signed-in ones.
|
|
149
156
|
|
|
150
157
|
## Product Page
|
|
151
158
|
|
|
@@ -53,12 +53,27 @@ Wire `publicStorefrontToken` from the canonical env variable without asserting i
|
|
|
53
53
|
|
|
54
54
|
This example belongs in a server-only module unless the config values are explicitly passed into browser code by a server boundary.
|
|
55
55
|
|
|
56
|
+
Every request context takes the storefront's i18n definition. Declare it once at module scope with `defineShopifyI18n` and import it wherever a request context is created:
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
// lib/i18n.ts
|
|
60
|
+
import { defineShopifyI18n } from "@shopify/hydrogen";
|
|
61
|
+
|
|
62
|
+
// Single-locale storefront. Add `routing` to serve more locales by path prefix or hostname;
|
|
63
|
+
// see the hydrogen-markets skill.
|
|
64
|
+
export const i18n = defineShopifyI18n({
|
|
65
|
+
defaultLocale: { language: "EN", country: "US" },
|
|
66
|
+
});
|
|
67
|
+
```
|
|
68
|
+
|
|
56
69
|
```ts
|
|
57
70
|
import { createStorefrontClient, createShopifyRequestContext } from "@shopify/hydrogen";
|
|
71
|
+
import { i18n } from "./lib/i18n";
|
|
58
72
|
|
|
59
73
|
const requestContext = createShopifyRequestContext({
|
|
60
74
|
request: { headers: new Headers() },
|
|
61
|
-
i18n
|
|
75
|
+
i18n,
|
|
76
|
+
locale: i18n.defaultLocale,
|
|
62
77
|
});
|
|
63
78
|
|
|
64
79
|
const client = createStorefrontClient({
|
|
@@ -73,10 +88,11 @@ const client = createStorefrontClient({
|
|
|
73
88
|
|
|
74
89
|
### Private client (SSR upgrade)
|
|
75
90
|
|
|
76
|
-
Use when the app has a private token and trusted buyer context. Requires `buyerIp` to forward trusted buyer context. Resolve request-derived values before creating the client:
|
|
91
|
+
Use when the app has a private token and trusted buyer context. Requires `buyerIp` to forward trusted buyer context. Resolve request-derived values before creating the client. With a real `Request`, the locale is matched from `request.url` against the definition, so no `locale` override is needed:
|
|
77
92
|
|
|
78
93
|
```ts
|
|
79
94
|
import { createStorefrontClient, createShopifyRequestContext } from "@shopify/hydrogen";
|
|
95
|
+
import { i18n } from "./lib/i18n";
|
|
80
96
|
|
|
81
97
|
function getBuyerIp(headers: Headers) {
|
|
82
98
|
const buyerIp = headers.get("oxygen-buyer-ip");
|
|
@@ -87,7 +103,7 @@ function getBuyerIp(headers: Headers) {
|
|
|
87
103
|
const buyerIp = getBuyerIp(request.headers);
|
|
88
104
|
const requestContext = createShopifyRequestContext({
|
|
89
105
|
request,
|
|
90
|
-
i18n
|
|
106
|
+
i18n,
|
|
91
107
|
buyerIp,
|
|
92
108
|
});
|
|
93
109
|
|
|
@@ -114,12 +130,13 @@ When using `handleShopifyRoutes`, pass the trusted `buyerIp` into `createShopify
|
|
|
114
130
|
|
|
115
131
|
### Private client without buyer context
|
|
116
132
|
|
|
117
|
-
For queries not on behalf of a specific buyer (pre-rendering, static site generation). No buyer IP is forwarded.
|
|
133
|
+
For queries not on behalf of a specific buyer (pre-rendering, static site generation). No buyer IP is forwarded. There is no request URL to match a locale from, so pin one with `locale`; it must be a locale the definition contains or the request context throws.
|
|
118
134
|
|
|
119
135
|
```ts
|
|
120
136
|
const requestContext = createShopifyRequestContext({
|
|
121
137
|
request: { headers: new Headers() },
|
|
122
|
-
i18n
|
|
138
|
+
i18n,
|
|
139
|
+
locale: i18n.defaultLocale,
|
|
123
140
|
});
|
|
124
141
|
|
|
125
142
|
const client = createStorefrontClient({
|
|
@@ -232,7 +249,7 @@ export type ProductCardData =
|
|
|
232
249
|
|
|
233
250
|
### Variables and i18n auto-injection
|
|
234
251
|
|
|
235
|
-
`$country` and `$language` are auto-injected from `requestContext.
|
|
252
|
+
`$country` and `$language` are auto-injected from `requestContext.locale` when the query declares them as `$country: CountryCode` and `$language: LanguageCode` (nullable or `!`). `requestContext.locale` is the `{ language, country, pathPrefix }` resolved for this request, also exposed as `client.locale`. `requestContext.i18n` and `client.i18n` are deprecated aliases of it; don't use them. Static clients still create a request context, usually with empty headers plus an explicit `locale`. You only pass the variables you own:
|
|
236
253
|
|
|
237
254
|
```ts
|
|
238
255
|
const PRODUCTS = gql(`
|
|
@@ -247,7 +264,7 @@ const { data } = await client.graphql(PRODUCTS, {
|
|
|
247
264
|
});
|
|
248
265
|
```
|
|
249
266
|
|
|
250
|
-
For those declarations the request context wins: the variables type
|
|
267
|
+
For those declarations the request context wins: the client overwrites any value you pass. The variables type leaves out `country` and `language`, but it only reports an error for them when the query has other variables too. If they're the only variables, the type is `{}` and a passed `country` still compiles. To query another market, create the client with a request context for that `i18n`.
|
|
251
268
|
|
|
252
269
|
A same-named variable of any other type stays yours and keeps its nullability, for example `$country: String!` as a metafield key, `$country: [CountryCode!]!`, or `$language: ProductSortKeys`. Only the first operation's declarations count.
|
|
253
270
|
|
|
@@ -301,7 +318,7 @@ const client = createStorefrontClient({
|
|
|
301
318
|
type: "public",
|
|
302
319
|
requestContext: createShopifyRequestContext({
|
|
303
320
|
request: { headers: new Headers() },
|
|
304
|
-
i18n: {
|
|
321
|
+
i18n: defineShopifyI18n({ defaultLocale: { language: "EN", country: "US" } }),
|
|
305
322
|
}),
|
|
306
323
|
config: {
|
|
307
324
|
storeDomain: "test.myshopify.com",
|
|
@@ -317,7 +334,8 @@ const client = createStorefrontClient({
|
|
|
317
334
|
|
|
318
335
|
- **Private tokens throw in browser** — a `typeof document !== "undefined"` guard fires at construction.
|
|
319
336
|
- **Env APIs are server-only** — examples that use `process.env` belong in server-only modules. Browser bundles may leave `process.env` undefined, inline stale build-time values, or accidentally expose config. Pass safe public values through server data when browser code needs them.
|
|
320
|
-
- **Module-scope only for request-independent clients** — static public clients and `private_no_buyer_context` clients can be module-scoped when their `requestContext` uses static headers and
|
|
337
|
+
- **Module-scope only for request-independent clients** — static public clients and `private_no_buyer_context` clients can be module-scoped when their `requestContext` uses static headers and an explicit `locale`. Private per-buyer clients and clients with a real incoming request context must be created per request.
|
|
338
|
+
- **`define*` vs `create*`** — `defineShopifyI18n` and `defineShopifyRouteTemplates` return module-scope, serializable configuration that server and client code can both import. `createShopifyRequestContext` and `createStorefrontClient` return stateful objects tied to a request or a token; keep them out of shared config modules.
|
|
321
339
|
|
|
322
340
|
---
|
|
323
341
|
|
|
@@ -6,6 +6,8 @@ Astro pages run their frontmatter on the server, so `Astro.request` and `Astro.c
|
|
|
6
6
|
|
|
7
7
|
Use `Astro.locals` to pass the storefront client from middleware to pages. The middleware creates the client once per request. The scaffold defaults to a public client; `PUBLIC_STOREFRONT_API_TOKEN` may be unset, which means tokenless access (all mock.shop supports). Once the app has a private token and trusted buyer context, switch to `type: "private"` and resolve `buyerIp` (e.g. from `Astro.clientAddress`) per the `hydrogen-storefront-client` buyer-IP guidance.
|
|
8
8
|
|
|
9
|
+
`i18n` is the module-scope `defineShopifyI18n` definition (see `SKILL.md`); the request context matches the locale from `context.request.url`.
|
|
10
|
+
|
|
9
11
|
```ts
|
|
10
12
|
// src/middleware.ts
|
|
11
13
|
import { defineMiddleware } from "astro:middleware";
|
|
@@ -13,11 +15,12 @@ import {
|
|
|
13
15
|
createStorefrontClient,
|
|
14
16
|
createShopifyRequestContext,
|
|
15
17
|
} from "@shopify/hydrogen";
|
|
18
|
+
import { i18n } from "./lib/i18n";
|
|
16
19
|
|
|
17
20
|
export const onRequest = defineMiddleware(async (context, next) => {
|
|
18
21
|
const requestContext = createShopifyRequestContext({
|
|
19
22
|
request: context.request,
|
|
20
|
-
i18n
|
|
23
|
+
i18n,
|
|
21
24
|
});
|
|
22
25
|
const client = createStorefrontClient({
|
|
23
26
|
type: "public",
|
|
@@ -70,15 +73,17 @@ This requires `output: "server"` in `astro.config.mjs` (all pages SSR by default
|
|
|
70
73
|
|
|
71
74
|
## Static pages (no buyer IP)
|
|
72
75
|
|
|
73
|
-
For prerendered pages — marketing, collection listings — use a module-scoped `private_no_buyer_context` client. No middleware needed since there's no request to read from.
|
|
76
|
+
For prerendered pages — marketing, collection listings — use a module-scoped `private_no_buyer_context` client. No middleware needed since there's no request to read from, which also means no URL to match a locale from: pin `locale` explicitly.
|
|
74
77
|
|
|
75
78
|
```ts
|
|
76
79
|
// src/lib/storefront-static.ts
|
|
77
80
|
import { createStorefrontClient, createShopifyRequestContext } from "@shopify/hydrogen";
|
|
81
|
+
import { i18n } from "./i18n";
|
|
78
82
|
|
|
79
83
|
const requestContext = createShopifyRequestContext({
|
|
80
84
|
request: { headers: new Headers() },
|
|
81
|
-
i18n
|
|
85
|
+
i18n,
|
|
86
|
+
locale: i18n.defaultLocale,
|
|
82
87
|
});
|
|
83
88
|
|
|
84
89
|
export const staticStorefrontClient = createStorefrontClient({
|
|
@@ -25,3 +25,5 @@ A stale-while-revalidate refresh runs under `waitUntil` after the caller already
|
|
|
25
25
|
## Never cache private data
|
|
26
26
|
|
|
27
27
|
Do not pass a `cache` strategy to personalized reads (cart, customer); keep them on a request-scoped client. Cache mode `private` is unsupported — for buyer-specific caching use `createRunWithCache` with an explicit private key.
|
|
28
|
+
|
|
29
|
+
The client never stores a Storefront API response whose `Cache-Control` header contains `private` or `no-store`, even when the query passes a `cache` strategy, and such a response makes the final response private through `applyResponseHeaders()`. There is no option to override this.
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
Next.js server components don't receive a `Request` object. The pattern: a server-only cached factory that reads `headers()`, creates a request context from those headers, and creates a request-scoped client for that RSC request. The scaffold defaults to a public client; `NEXT_PUBLIC_STOREFRONT_API_TOKEN` may be unset, which means tokenless access (all mock.shop supports). Once the app has a private token and trusted buyer context, switch to `type: "private"` and resolve `buyerIp` per the `hydrogen-storefront-client` buyer-IP guidance (e.g. from trusted `x-forwarded-for` data).
|
|
6
6
|
|
|
7
|
+
`i18n` is the module-scope `defineShopifyI18n` definition from `lib/i18n.ts` (see `SKILL.md`). With headers-only requests the locale is matched from the `x-storefront-url` header that `proxy.ts` forwards via `requestContext.getForwardedRequestHeaders()`.
|
|
8
|
+
|
|
7
9
|
```ts
|
|
8
10
|
// lib/storefront.ts
|
|
9
11
|
import { headers } from "next/headers";
|
|
@@ -12,12 +14,13 @@ import {
|
|
|
12
14
|
createStorefrontClient,
|
|
13
15
|
createShopifyRequestContext,
|
|
14
16
|
} from "@shopify/hydrogen";
|
|
17
|
+
import { i18n } from "@/lib/i18n";
|
|
15
18
|
|
|
16
19
|
export const getStorefrontClient = cache(async () => {
|
|
17
20
|
const requestHeaders = await headers();
|
|
18
21
|
const requestContext = createShopifyRequestContext({
|
|
19
22
|
request: { headers: requestHeaders },
|
|
20
|
-
i18n
|
|
23
|
+
i18n,
|
|
21
24
|
});
|
|
22
25
|
|
|
23
26
|
return createStorefrontClient({
|
|
@@ -56,15 +59,17 @@ The client is created inside the request path because `requestContext` is static
|
|
|
56
59
|
|
|
57
60
|
## Static pages (no buyer IP)
|
|
58
61
|
|
|
59
|
-
Pages that don't need buyer context — product listings, collection grids, marketing pages — can use `private_no_buyer_context` with a static request context. Because the component never calls `headers()`, `cookies()`, or reads `searchParams`, Next.js treats it as statically renderable and caches it at build time or via ISR.
|
|
62
|
+
Pages that don't need buyer context — product listings, collection grids, marketing pages — can use `private_no_buyer_context` with a static request context. Because the component never calls `headers()`, `cookies()`, or reads `searchParams`, Next.js treats it as statically renderable and caches it at build time or via ISR. There is no request URL here, so pin `locale` explicitly.
|
|
60
63
|
|
|
61
64
|
```ts
|
|
62
65
|
// lib/storefront-static.ts - private client, no buyer context
|
|
63
66
|
import { createStorefrontClient, createShopifyRequestContext } from "@shopify/hydrogen";
|
|
67
|
+
import { i18n } from "@/lib/i18n";
|
|
64
68
|
|
|
65
69
|
const requestContext = createShopifyRequestContext({
|
|
66
70
|
request: { headers: new Headers() },
|
|
67
|
-
i18n
|
|
71
|
+
i18n,
|
|
72
|
+
locale: i18n.defaultLocale,
|
|
68
73
|
});
|
|
69
74
|
|
|
70
75
|
export const staticStorefrontClient = createStorefrontClient({
|
|
@@ -9,7 +9,9 @@ Use the `hydrogen-request-handlers` skill when wiring middleware, response-heade
|
|
|
9
9
|
|
|
10
10
|
## Server Client
|
|
11
11
|
|
|
12
|
-
Create the client in server middleware where Nuxt exposes the incoming request. `PUBLIC_STOREFRONT_API_TOKEN` may be unset, which means tokenless access (all mock.shop supports). Once the app has a private token and trusted buyer context, switch to `type: "private"` and resolve `buyerIp` per the `hydrogen-storefront-client` buyer-IP guidance
|
|
12
|
+
Create the client in server middleware where Nuxt exposes the incoming request. `PUBLIC_STOREFRONT_API_TOKEN` may be unset, which means tokenless access (all mock.shop supports). Once the app has a private token and trusted buyer context, switch to `type: "private"` and resolve `buyerIp` per the `hydrogen-storefront-client` buyer-IP guidance.
|
|
13
|
+
|
|
14
|
+
`i18n` is the module-scope `defineShopifyI18n` definition (see `SKILL.md`). Keep it in a module both server and client code can import, since the client plugin below needs it too.
|
|
13
15
|
|
|
14
16
|
```ts
|
|
15
17
|
import {
|
|
@@ -17,12 +19,13 @@ import {
|
|
|
17
19
|
createShopifyRequestContext,
|
|
18
20
|
type ShopifyRequestContext,
|
|
19
21
|
} from "@shopify/hydrogen";
|
|
22
|
+
import { i18n } from "~/lib/i18n";
|
|
20
23
|
|
|
21
24
|
export default defineEventHandler((event) => {
|
|
22
25
|
const request = toWebRequest(event);
|
|
23
26
|
const requestContext = createShopifyRequestContext({
|
|
24
27
|
request,
|
|
25
|
-
i18n
|
|
28
|
+
i18n,
|
|
26
29
|
});
|
|
27
30
|
|
|
28
31
|
event.context.storefrontClient = createPublicStorefrontClient(requestContext);
|
|
@@ -67,16 +70,17 @@ Augment `#app`, `h3`, and `vue` types so `$storefrontClient` is available in pag
|
|
|
67
70
|
|
|
68
71
|
## Client Plugin
|
|
69
72
|
|
|
70
|
-
Browser-side Storefront API calls should go through the same-origin SFAPI proxy installed by `handleShopifyRoutes`. Do not call the remote store domain directly from the browser.
|
|
73
|
+
Browser-side Storefront API calls should go through the same-origin SFAPI proxy installed by `handleShopifyRoutes`. Do not call the remote store domain directly from the browser. Pass the page URL as `request.url` so the browser client resolves the same locale as the server did:
|
|
71
74
|
|
|
72
75
|
```ts
|
|
73
76
|
import { createStorefrontClient, createShopifyRequestContext } from "@shopify/hydrogen";
|
|
77
|
+
import { i18n } from "~/lib/i18n";
|
|
74
78
|
|
|
75
79
|
export default defineNuxtPlugin(() => {
|
|
76
80
|
const config = useRuntimeConfig().public;
|
|
77
81
|
const requestContext = createShopifyRequestContext({
|
|
78
|
-
request: { headers: new Headers() },
|
|
79
|
-
i18n
|
|
82
|
+
request: { headers: new Headers(), url: window.location.href },
|
|
83
|
+
i18n,
|
|
80
84
|
});
|
|
81
85
|
const storefrontClient = createStorefrontClient({
|
|
82
86
|
type: "public",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# React Router
|
|
1
|
+
# React Router
|
|
2
2
|
|
|
3
3
|
Middleware creates a per-request public client. `requestContext` carries request lifecycle headers and captures SFAPI response headers so middleware can merge them into the final response. `PUBLIC_STOREFRONT_API_TOKEN` may be unset, which means tokenless access (all mock.shop supports). Once the app has a private token and trusted buyer context, switch to `type: "private"` and resolve `buyerIp` per the `hydrogen-storefront-client` buyer-IP guidance.
|
|
4
4
|
|
|
@@ -12,12 +12,15 @@ export const storefrontContext = createContext<StorefrontClient>();
|
|
|
12
12
|
|
|
13
13
|
This `createContext` is React Router's request context for passing values from middleware to loaders; it is not React's component `createContext`.
|
|
14
14
|
|
|
15
|
+
`i18n` is the module-scope `defineShopifyI18n` definition (see `SKILL.md`); the request context matches the locale from `request.url`.
|
|
16
|
+
|
|
15
17
|
```ts
|
|
16
18
|
// app/storefront.middleware.ts
|
|
17
19
|
import {
|
|
18
20
|
createStorefrontClient,
|
|
19
21
|
createShopifyRequestContext,
|
|
20
22
|
} from "@shopify/hydrogen";
|
|
23
|
+
import { i18n } from "~/lib/i18n";
|
|
21
24
|
import { storefrontContext } from "./storefront.context";
|
|
22
25
|
import type { Route } from "./+types/root";
|
|
23
26
|
|
|
@@ -27,7 +30,7 @@ export const storefrontMiddleware: Route.MiddlewareFunction = async (
|
|
|
27
30
|
) => {
|
|
28
31
|
const requestContext = createShopifyRequestContext({
|
|
29
32
|
request,
|
|
30
|
-
i18n
|
|
33
|
+
i18n,
|
|
31
34
|
});
|
|
32
35
|
|
|
33
36
|
const client = createStorefrontClient({
|
|
@@ -55,7 +58,7 @@ import type { Route } from "./+types/root";
|
|
|
55
58
|
export const middleware: Route.MiddlewareFunction[] = [storefrontMiddleware];
|
|
56
59
|
```
|
|
57
60
|
|
|
58
|
-
|
|
61
|
+
Make sure middleware is enabled for your version of React Router. If the app also needs Hydrogen route handlers and Shopify redirects, use the `hydrogen-request-handlers` React Router shape so this client creation, `handleShopifyRoutes()`, context setup, `handleShopifyRedirects()`, and response-header propagation all live in one root middleware chain.
|
|
59
62
|
|
|
60
63
|
```ts
|
|
61
64
|
// app/routes/product.tsx — loader reads client from context
|
|
@@ -6,6 +6,8 @@ SolidStart uses Vinxi (Nitro under the hood) and provides middleware via `create
|
|
|
6
6
|
|
|
7
7
|
The middleware creates the client per-request and attaches it to `event.locals`. Server functions retrieve it via `getRequestEvent()`. The scaffold defaults to a public client; `PUBLIC_STOREFRONT_API_TOKEN` may be unset, which means tokenless access (all mock.shop supports). Once the app has a private token and trusted buyer context, switch to `type: "private"` and resolve `buyerIp` per the `hydrogen-storefront-client` buyer-IP guidance.
|
|
8
8
|
|
|
9
|
+
`i18n` is the module-scope `defineShopifyI18n` definition (see `SKILL.md`); the request context matches the locale from `event.request.url`.
|
|
10
|
+
|
|
9
11
|
```ts
|
|
10
12
|
// src/middleware.ts
|
|
11
13
|
import { createMiddleware } from "@solidjs/start/middleware";
|
|
@@ -13,12 +15,13 @@ import {
|
|
|
13
15
|
createStorefrontClient,
|
|
14
16
|
createShopifyRequestContext,
|
|
15
17
|
} from "@shopify/hydrogen";
|
|
18
|
+
import { i18n } from "~/lib/i18n";
|
|
16
19
|
|
|
17
20
|
export default createMiddleware({
|
|
18
21
|
onRequest: (event) => {
|
|
19
22
|
const requestContext = createShopifyRequestContext({
|
|
20
23
|
request: event.request,
|
|
21
|
-
i18n
|
|
24
|
+
i18n,
|
|
22
25
|
});
|
|
23
26
|
|
|
24
27
|
const client = createStorefrontClient({
|
|
@@ -98,12 +101,13 @@ import {
|
|
|
98
101
|
createStorefrontClient,
|
|
99
102
|
createShopifyRequestContext,
|
|
100
103
|
} from "@shopify/hydrogen";
|
|
104
|
+
import { i18n } from "~/lib/i18n";
|
|
101
105
|
|
|
102
106
|
export default createMiddleware({
|
|
103
107
|
onRequest: (event) => {
|
|
104
108
|
const requestContext = createShopifyRequestContext({
|
|
105
109
|
request: event.request,
|
|
106
|
-
i18n
|
|
110
|
+
i18n,
|
|
107
111
|
});
|
|
108
112
|
|
|
109
113
|
const client = createStorefrontClient({
|
|
@@ -13,6 +13,8 @@ SvelteKit's `handle` hook in `hooks.server.ts` runs on every server request and
|
|
|
13
13
|
|
|
14
14
|
The scaffold defaults to a public client; `PUBLIC_STOREFRONT_API_TOKEN` may be unset, which means tokenless access (all mock.shop supports) — read it through `$env/dynamic/public`, since `$env/static/public` fails the build for unset vars. Once the app has a private token and trusted buyer context, switch to `type: "private"` and resolve `buyerIp` (e.g. from `event.getClientAddress()`) per the `hydrogen-storefront-client` buyer-IP guidance.
|
|
15
15
|
|
|
16
|
+
`i18n` is the module-scope `defineShopifyI18n` definition (see `SKILL.md`); the request context matches the locale from `event.request.url`.
|
|
17
|
+
|
|
16
18
|
```ts
|
|
17
19
|
// src/hooks.server.ts
|
|
18
20
|
import type { Handle } from "@sveltejs/kit";
|
|
@@ -22,11 +24,12 @@ import {
|
|
|
22
24
|
} from "@shopify/hydrogen";
|
|
23
25
|
import { env } from "$env/dynamic/public";
|
|
24
26
|
import { PUBLIC_STORE_DOMAIN } from "$env/static/public";
|
|
27
|
+
import { i18n } from "$lib/i18n";
|
|
25
28
|
|
|
26
29
|
export const handle: Handle = async ({ event, resolve }) => {
|
|
27
30
|
const requestContext = createShopifyRequestContext({
|
|
28
31
|
request: event.request,
|
|
29
|
-
i18n
|
|
32
|
+
i18n,
|
|
30
33
|
});
|
|
31
34
|
const client = createStorefrontClient({
|
|
32
35
|
type: "public",
|
|
@@ -89,11 +92,12 @@ export const load: PageServerLoad = async ({ params, locals }) => {
|
|
|
89
92
|
// src/hooks.server.ts — response header propagation
|
|
90
93
|
import { env } from "$env/dynamic/public";
|
|
91
94
|
import { PUBLIC_STORE_DOMAIN } from "$env/static/public";
|
|
95
|
+
import { i18n } from "$lib/i18n";
|
|
92
96
|
|
|
93
97
|
export const handle: Handle = async ({ event, resolve }) => {
|
|
94
98
|
const requestContext = createShopifyRequestContext({
|
|
95
99
|
request: event.request,
|
|
96
|
-
i18n
|
|
100
|
+
i18n,
|
|
97
101
|
});
|
|
98
102
|
|
|
99
103
|
const client = createStorefrontClient({
|
|
@@ -115,17 +119,19 @@ export const handle: Handle = async ({ event, resolve }) => {
|
|
|
115
119
|
|
|
116
120
|
## Static pages (no buyer IP)
|
|
117
121
|
|
|
118
|
-
For prerendered pages, use a module-scoped `private_no_buyer_context` client and export `prerender = true`.
|
|
122
|
+
For prerendered pages, use a module-scoped `private_no_buyer_context` client and export `prerender = true`. There is no request URL to match a locale from, so pin `locale` explicitly.
|
|
119
123
|
|
|
120
124
|
```ts
|
|
121
125
|
// src/lib/storefront-static.ts
|
|
122
126
|
import { createStorefrontClient, createShopifyRequestContext } from "@shopify/hydrogen";
|
|
123
127
|
import { PRIVATE_STOREFRONT_API_TOKEN } from "$env/static/private";
|
|
124
128
|
import { PUBLIC_STORE_DOMAIN } from "$env/static/public";
|
|
129
|
+
import { i18n } from "$lib/i18n";
|
|
125
130
|
|
|
126
131
|
const requestContext = createShopifyRequestContext({
|
|
127
132
|
request: { headers: new Headers() },
|
|
128
|
-
i18n
|
|
133
|
+
i18n,
|
|
134
|
+
locale: i18n.defaultLocale,
|
|
129
135
|
});
|
|
130
136
|
|
|
131
137
|
export const staticStorefrontClient = createStorefrontClient({
|