@shopify/hydrogen 2026.10.1 → 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.
Files changed (265) hide show
  1. package/README.md +3 -5
  2. package/dist/cli/index.mjs +8 -5
  3. package/dist/client/client.mjs +45 -12
  4. package/dist/client/client.mjs.map +1 -1
  5. package/dist/client/i18n-variables.d.mts +13 -0
  6. package/dist/client/i18n-variables.mjs +92 -0
  7. package/dist/client/i18n-variables.mjs.map +1 -0
  8. package/dist/client/types.d.mts +21 -8
  9. package/dist/core/cache/fetch-with-cache.mjs +8 -1
  10. package/dist/core/cache/fetch-with-cache.mjs.map +1 -1
  11. package/dist/core/cart/cart.mjs +111 -24
  12. package/dist/core/cart/cart.mjs.map +1 -1
  13. package/dist/core/cart/cookie.mjs +6 -1
  14. package/dist/core/cart/cookie.mjs.map +1 -1
  15. package/dist/core/cart/form.d.mts +17 -5
  16. package/dist/core/cart/form.mjs +5 -0
  17. package/dist/core/cart/form.mjs.map +1 -1
  18. package/dist/core/cart/index.d.mts +1 -1
  19. package/dist/core/cart/queries.d.mts +57 -57
  20. package/dist/core/collection/url.mjs +8 -1
  21. package/dist/core/collection/url.mjs.map +1 -1
  22. package/dist/core/constants.mjs +2 -1
  23. package/dist/core/constants.mjs.map +1 -1
  24. package/dist/core/csp/index.d.mts +56 -0
  25. package/dist/core/csp/index.mjs +117 -0
  26. package/dist/core/csp/index.mjs.map +1 -0
  27. package/dist/core/csp/types.d.mts +52 -0
  28. package/dist/core/headers.mjs +2 -2
  29. package/dist/core/headers.mjs.map +1 -1
  30. package/dist/core/i18n/define.d.mts +54 -0
  31. package/dist/core/i18n/define.mjs +135 -0
  32. package/dist/core/i18n/define.mjs.map +1 -0
  33. package/dist/core/i18n/errors.d.mts +18 -0
  34. package/dist/core/i18n/errors.mjs +24 -0
  35. package/dist/core/i18n/errors.mjs.map +1 -0
  36. package/dist/core/i18n/href.d.mts +28 -0
  37. package/dist/core/i18n/href.mjs +45 -0
  38. package/dist/core/i18n/href.mjs.map +1 -0
  39. package/dist/core/i18n/locale.d.mts +21 -0
  40. package/dist/core/i18n/locale.mjs +36 -0
  41. package/dist/core/i18n/locale.mjs.map +1 -0
  42. package/dist/core/i18n/match.d.mts +37 -0
  43. package/dist/core/i18n/match.mjs +82 -0
  44. package/dist/core/i18n/match.mjs.map +1 -0
  45. package/dist/core/i18n/types.d.mts +80 -0
  46. package/dist/core/index.d.mts +14 -5
  47. package/dist/core/index.mjs +9 -2
  48. package/dist/core/predictive-search/index.d.mts +2 -2
  49. package/dist/core/predictive-search/queries.d.mts +2 -2
  50. package/dist/core/predictive-search/server-handlers.d.mts +27 -6
  51. package/dist/core/predictive-search/server-handlers.mjs +1 -4
  52. package/dist/core/predictive-search/server-handlers.mjs.map +1 -1
  53. package/dist/core/predictive-search/url.d.mts +2 -2
  54. package/dist/core/predictive-search/url.mjs.map +1 -1
  55. package/dist/core/product/accept-variant-id.mjs +1 -1
  56. package/dist/core/product/accept-variant-id.mjs.map +1 -1
  57. package/dist/core/request-context.d.mts +61 -35
  58. package/dist/core/request-context.mjs +11 -7
  59. package/dist/core/request-context.mjs.map +1 -1
  60. package/dist/core/request-routing/handle-shopify-routes.mjs.map +1 -1
  61. package/dist/core/request-routing/interceptors/api-proxy.mjs +9 -1
  62. package/dist/core/request-routing/interceptors/api-proxy.mjs.map +1 -1
  63. package/dist/core/request-routing/interceptors/checkout.mjs +11 -5
  64. package/dist/core/request-routing/interceptors/checkout.mjs.map +1 -1
  65. package/dist/core/request-routing/interceptors/proxy.mjs.map +1 -1
  66. package/dist/core/request-routing/interceptors/standard-routes.mjs +1 -1
  67. package/dist/core/request-routing/interceptors/standard-routes.mjs.map +1 -1
  68. package/dist/core/request-routing/interceptors/url-redirects.mjs +2 -1
  69. package/dist/core/request-routing/interceptors/url-redirects.mjs.map +1 -1
  70. package/dist/core/request-routing/registered-routes.d.mts +13 -2
  71. package/dist/core/request-routing/registered-routes.mjs +33 -9
  72. package/dist/core/request-routing/registered-routes.mjs.map +1 -1
  73. package/dist/core/request-routing/route-types.d.mts +18 -8
  74. package/dist/core/shop-pay/shop-pay.mjs +5 -4
  75. package/dist/core/shop-pay/shop-pay.mjs.map +1 -1
  76. package/dist/core/shopify-scripts/analytics.mjs +3 -5
  77. package/dist/core/shopify-scripts/analytics.mjs.map +1 -1
  78. package/dist/core/shopify-scripts/constants.mjs +3 -1
  79. package/dist/core/shopify-scripts/constants.mjs.map +1 -1
  80. package/dist/core/shopify-scripts/global.mjs +13 -11
  81. package/dist/core/shopify-scripts/global.mjs.map +1 -1
  82. package/dist/core/shopify-scripts/hashes.d.mts +17 -0
  83. package/dist/core/shopify-scripts/hashes.mjs +12 -0
  84. package/dist/core/shopify-scripts/hashes.mjs.map +1 -0
  85. package/dist/core/shopify-scripts/index.d.mts +1 -0
  86. package/dist/core/shopify-scripts/index.mjs +12 -9
  87. package/dist/core/shopify-scripts/index.mjs.map +1 -1
  88. package/dist/core/shopify-scripts/page-view.mjs +4 -1
  89. package/dist/core/shopify-scripts/page-view.mjs.map +1 -1
  90. package/dist/core/shopify-scripts/perfkit.mjs +8 -2
  91. package/dist/core/shopify-scripts/perfkit.mjs.map +1 -1
  92. package/dist/core/shopify-scripts/types.d.mts +4 -2
  93. package/dist/core/shopify-scripts/utils/inline-script.mjs +4 -1
  94. package/dist/core/shopify-scripts/utils/inline-script.mjs.map +1 -1
  95. package/dist/core/standard-routes/build.d.mts +7 -2
  96. package/dist/core/standard-routes/build.mjs +10 -3
  97. package/dist/core/standard-routes/build.mjs.map +1 -1
  98. package/dist/core/standard-routes/match.mjs +11 -1
  99. package/dist/core/standard-routes/match.mjs.map +1 -1
  100. package/dist/core/standard-routes/path.mjs +14 -3
  101. package/dist/core/standard-routes/path.mjs.map +1 -1
  102. package/dist/core/standard-routes/types.d.mts +6 -1
  103. package/dist/core/url.mjs +5 -3
  104. package/dist/core/url.mjs.map +1 -1
  105. package/dist/core/utils/load-script.mjs +6 -6
  106. package/dist/core/utils/load-script.mjs.map +1 -1
  107. package/dist/customer-account/client.d.mts +14 -10
  108. package/dist/customer-account/client.mjs +4 -5
  109. package/dist/customer-account/client.mjs.map +1 -1
  110. package/dist/customer-account/graphql.d.mts +7 -1
  111. package/dist/customer-account/graphql.mjs +6 -7
  112. package/dist/customer-account/graphql.mjs.map +1 -1
  113. package/dist/customer-account/session.mjs +3 -4
  114. package/dist/customer-account/session.mjs.map +1 -1
  115. package/dist/development/client/client.mjs +45 -12
  116. package/dist/development/client/client.mjs.map +1 -1
  117. package/dist/development/client/i18n-variables.d.mts +13 -0
  118. package/dist/development/client/i18n-variables.mjs +92 -0
  119. package/dist/development/client/i18n-variables.mjs.map +1 -0
  120. package/dist/development/client/types.d.mts +21 -8
  121. package/dist/development/core/cache/fetch-with-cache.mjs +8 -1
  122. package/dist/development/core/cache/fetch-with-cache.mjs.map +1 -1
  123. package/dist/development/core/cart/cart.mjs +111 -24
  124. package/dist/development/core/cart/cart.mjs.map +1 -1
  125. package/dist/development/core/cart/cookie.mjs +6 -1
  126. package/dist/development/core/cart/cookie.mjs.map +1 -1
  127. package/dist/development/core/cart/form.d.mts +17 -5
  128. package/dist/development/core/cart/form.mjs +5 -0
  129. package/dist/development/core/cart/form.mjs.map +1 -1
  130. package/dist/development/core/cart/index.d.mts +1 -1
  131. package/dist/development/core/cart/queries.d.mts +57 -57
  132. package/dist/development/core/collection/url.mjs +8 -1
  133. package/dist/development/core/collection/url.mjs.map +1 -1
  134. package/dist/development/core/constants.mjs +2 -1
  135. package/dist/development/core/constants.mjs.map +1 -1
  136. package/dist/development/core/csp/index.d.mts +56 -0
  137. package/dist/development/core/csp/index.mjs +128 -0
  138. package/dist/development/core/csp/index.mjs.map +1 -0
  139. package/dist/development/core/csp/types.d.mts +52 -0
  140. package/dist/development/core/development.d.mts +14 -5
  141. package/dist/development/core/development.mjs +9 -2
  142. package/dist/development/core/headers.mjs +2 -2
  143. package/dist/development/core/headers.mjs.map +1 -1
  144. package/dist/development/core/i18n/define.d.mts +54 -0
  145. package/dist/development/core/i18n/define.mjs +135 -0
  146. package/dist/development/core/i18n/define.mjs.map +1 -0
  147. package/dist/development/core/i18n/errors.d.mts +18 -0
  148. package/dist/development/core/i18n/errors.mjs +24 -0
  149. package/dist/development/core/i18n/errors.mjs.map +1 -0
  150. package/dist/development/core/i18n/href.d.mts +28 -0
  151. package/dist/development/core/i18n/href.mjs +45 -0
  152. package/dist/development/core/i18n/href.mjs.map +1 -0
  153. package/dist/development/core/i18n/locale.d.mts +21 -0
  154. package/dist/development/core/i18n/locale.mjs +36 -0
  155. package/dist/development/core/i18n/locale.mjs.map +1 -0
  156. package/dist/development/core/i18n/match.d.mts +37 -0
  157. package/dist/development/core/i18n/match.mjs +82 -0
  158. package/dist/development/core/i18n/match.mjs.map +1 -0
  159. package/dist/development/core/i18n/types.d.mts +80 -0
  160. package/dist/development/core/index.d.mts +13 -4
  161. package/dist/development/core/predictive-search/index.d.mts +2 -2
  162. package/dist/development/core/predictive-search/queries.d.mts +2 -2
  163. package/dist/development/core/predictive-search/server-handlers.d.mts +27 -6
  164. package/dist/development/core/predictive-search/server-handlers.mjs +1 -4
  165. package/dist/development/core/predictive-search/server-handlers.mjs.map +1 -1
  166. package/dist/development/core/predictive-search/url.d.mts +2 -2
  167. package/dist/development/core/predictive-search/url.mjs.map +1 -1
  168. package/dist/development/core/product/accept-variant-id.mjs +1 -1
  169. package/dist/development/core/product/accept-variant-id.mjs.map +1 -1
  170. package/dist/development/core/request-context.d.mts +61 -35
  171. package/dist/development/core/request-context.mjs +11 -7
  172. package/dist/development/core/request-context.mjs.map +1 -1
  173. package/dist/development/core/request-routing/handle-shopify-routes.mjs.map +1 -1
  174. package/dist/development/core/request-routing/interceptors/api-proxy.mjs +9 -1
  175. package/dist/development/core/request-routing/interceptors/api-proxy.mjs.map +1 -1
  176. package/dist/development/core/request-routing/interceptors/checkout.mjs +11 -5
  177. package/dist/development/core/request-routing/interceptors/checkout.mjs.map +1 -1
  178. package/dist/development/core/request-routing/interceptors/proxy.mjs.map +1 -1
  179. package/dist/development/core/request-routing/interceptors/standard-routes.mjs +1 -1
  180. package/dist/development/core/request-routing/interceptors/standard-routes.mjs.map +1 -1
  181. package/dist/development/core/request-routing/interceptors/url-redirects.mjs +2 -1
  182. package/dist/development/core/request-routing/interceptors/url-redirects.mjs.map +1 -1
  183. package/dist/development/core/request-routing/registered-routes.d.mts +13 -2
  184. package/dist/development/core/request-routing/registered-routes.mjs +33 -9
  185. package/dist/development/core/request-routing/registered-routes.mjs.map +1 -1
  186. package/dist/development/core/request-routing/route-types.d.mts +18 -8
  187. package/dist/development/core/shop-pay/shop-pay.mjs +5 -4
  188. package/dist/development/core/shop-pay/shop-pay.mjs.map +1 -1
  189. package/dist/development/core/shopify-scripts/analytics.mjs +3 -5
  190. package/dist/development/core/shopify-scripts/analytics.mjs.map +1 -1
  191. package/dist/development/core/shopify-scripts/constants.mjs +3 -1
  192. package/dist/development/core/shopify-scripts/constants.mjs.map +1 -1
  193. package/dist/development/core/shopify-scripts/global.mjs +13 -11
  194. package/dist/development/core/shopify-scripts/global.mjs.map +1 -1
  195. package/dist/development/core/shopify-scripts/hashes.d.mts +17 -0
  196. package/dist/development/core/shopify-scripts/hashes.mjs +12 -0
  197. package/dist/development/core/shopify-scripts/hashes.mjs.map +1 -0
  198. package/dist/development/core/shopify-scripts/index.d.mts +1 -0
  199. package/dist/development/core/shopify-scripts/index.mjs +12 -9
  200. package/dist/development/core/shopify-scripts/index.mjs.map +1 -1
  201. package/dist/development/core/shopify-scripts/page-view.mjs +4 -1
  202. package/dist/development/core/shopify-scripts/page-view.mjs.map +1 -1
  203. package/dist/development/core/shopify-scripts/perfkit.mjs +8 -2
  204. package/dist/development/core/shopify-scripts/perfkit.mjs.map +1 -1
  205. package/dist/development/core/shopify-scripts/types.d.mts +4 -2
  206. package/dist/development/core/shopify-scripts/utils/inline-script.mjs +4 -1
  207. package/dist/development/core/shopify-scripts/utils/inline-script.mjs.map +1 -1
  208. package/dist/development/core/standard-routes/build.d.mts +7 -2
  209. package/dist/development/core/standard-routes/build.mjs +10 -3
  210. package/dist/development/core/standard-routes/build.mjs.map +1 -1
  211. package/dist/development/core/standard-routes/match.mjs +11 -1
  212. package/dist/development/core/standard-routes/match.mjs.map +1 -1
  213. package/dist/development/core/standard-routes/path.mjs +14 -3
  214. package/dist/development/core/standard-routes/path.mjs.map +1 -1
  215. package/dist/development/core/standard-routes/types.d.mts +6 -1
  216. package/dist/development/core/url.mjs +5 -3
  217. package/dist/development/core/url.mjs.map +1 -1
  218. package/dist/development/core/utils/load-script.mjs +6 -6
  219. package/dist/development/core/utils/load-script.mjs.map +1 -1
  220. package/dist/development/customer-account/session.mjs.map +1 -1
  221. package/dist/development/globals.d.mts +8 -4
  222. package/dist/development/graphql/type-resolver.d.mts +39 -1
  223. package/dist/development/react/cart.mjs +79 -25
  224. package/dist/development/react/cart.mjs.map +1 -1
  225. package/dist/development/react/index.d.mts +2 -2
  226. package/dist/globals.d.mts +8 -4
  227. package/dist/graphql/type-resolver.d.mts +39 -1
  228. package/dist/react/cart.mjs +79 -25
  229. package/dist/react/cart.mjs.map +1 -1
  230. package/dist/react/index.d.mts +2 -2
  231. package/dist/vite/index.d.mts +11 -1
  232. package/dist/vite/index.mjs +21 -1
  233. package/dist/vite/index.mjs.map +1 -0
  234. package/package.json +13 -3
  235. package/skills/hydrogen-analytics/SKILL.md +2 -2
  236. package/skills/hydrogen-analytics/references/react.md +2 -2
  237. package/skills/hydrogen-cart-ui/SKILL.md +2 -2
  238. package/skills/hydrogen-markets/SKILL.md +127 -93
  239. package/skills/hydrogen-markets/references/nextjs.md +77 -87
  240. package/skills/hydrogen-oxygen/references/react-router.md +1 -2
  241. package/skills/hydrogen-predictive-search/SKILL.md +18 -1
  242. package/skills/hydrogen-request-handlers/SKILL.md +24 -6
  243. package/skills/hydrogen-request-handlers/references/content-security-policy.md +103 -0
  244. package/skills/hydrogen-request-handlers/references/frameworks.md +9 -12
  245. package/skills/hydrogen-request-handlers/references/nextjs.md +7 -3
  246. package/skills/hydrogen-request-handlers/references/nuxt.md +7 -7
  247. package/skills/hydrogen-robots-txt/SKILL.md +87 -0
  248. package/skills/hydrogen-routing/SKILL.md +36 -14
  249. package/skills/hydrogen-setup/SKILL.md +2 -2
  250. package/skills/hydrogen-setup/references/analytics.md +5 -5
  251. package/skills/hydrogen-setup/steps/2-scaffold.md +3 -0
  252. package/skills/hydrogen-setup/steps/7-shopify-runtime-scripts.md +4 -3
  253. package/skills/hydrogen-setup/steps/9-account-page.md +1 -1
  254. package/skills/hydrogen-smoke-test/SKILL.md +9 -2
  255. package/skills/hydrogen-storefront-client/SKILL.md +29 -9
  256. package/skills/hydrogen-storefront-client/references/astro.md +8 -3
  257. package/skills/hydrogen-storefront-client/references/caching.md +2 -0
  258. package/skills/hydrogen-storefront-client/references/nextjs.md +8 -3
  259. package/skills/hydrogen-storefront-client/references/nuxt.md +9 -5
  260. package/skills/hydrogen-storefront-client/references/react-router.md +6 -3
  261. package/skills/hydrogen-storefront-client/references/solidstart.md +6 -2
  262. package/skills/hydrogen-storefront-client/references/sveltekit.md +10 -4
  263. package/skills/migrate-to-hydrogen-2026-10/SKILL.md +20 -22
  264. package/skills/migrate-to-hydrogen-2026-10/references/sitemap-and-seo.md +1 -0
  265. package/skills/migrate-to-hydrogen-2026-10/references/typescript-and-gql-tada.md +1 -1
@@ -21,7 +21,7 @@ Read each step file and complete it fully before opening the next. Every step en
21
21
  - Setup is **not complete** until the final verify step's commands have been executed in this session and passed. If you are about to summarize results and have not just run them, stop and run them. Reporting success with failing or unrun checks is a failed setup, not a finished one.
22
22
 
23
23
  1. `steps/1-inspect-app.md` — verify basic compatibility, identify the styling approach, detect the framework and its reference files.
24
- 2. `steps/2-scaffold.md` — route conventions, environment variable names, server-side env access, Storefront API client with `hydrogen gql check`, API route handlers, Customer Account API.
24
+ 2. `steps/2-scaffold.md` — route conventions, environment variable names, server-side env access, Storefront API client with `hydrogen gql check`, API route handlers, `robots.txt`, Customer Account API.
25
25
  3. `steps/3-build-home-page.md` — server-rendered home page listing collections and products.
26
26
  4. `steps/4-collection-and-search.md` — collection and search browsing with URL-synced filters.
27
27
  5. `steps/5-cart.md` — the `/cart` route with progressive enhancement.
@@ -38,7 +38,7 @@ Read each step file and complete it fully before opening the next. Every step en
38
38
 
39
39
  - **Account UI / session storage** — the `hydrogen-customer-account` skill wires sessions and OAuth handlers during scaffold, and the account-page step builds the minimal profile + logout UI, but the app owns the framework session adapter, richer account pages, and order history UI. Keep account tokens server-side or in encrypted HttpOnly cookies, and do not retry account mutations after a timeout unless the operation is externally idempotent.
40
40
  - **Image optimization** — use the framework's image component (or `<img srcset>`) with Shopify CDN URL transforms; do not expect a Hydrogen `Image` component.
41
- - **SEO** — render meta/Open Graph tags and JSON-LD `Product`/`BreadcrumbList` structured data with the framework's head/metadata API using Storefront API data.
41
+ - **SEO** — render meta/Open Graph tags and JSON-LD `Product`/`BreadcrumbList` structured data with the framework's head/metadata API using Storefront API data. Serve `/robots.txt` with the `hydrogen-robots-txt` skill during scaffold.
42
42
 
43
43
  Mention these to the user when they are relevant to the storefront being built rather than skipping them silently.
44
44
 
@@ -212,7 +212,7 @@ Destinations are consent-gated and receive retained history once tracking is all
212
212
 
213
213
  Each framework should derive `shop` and `i18n` on the server and render ShopifyScripts before publishing. The exact env API varies by framework; these examples show the data flow, not a requirement to use these file names.
214
214
 
215
- Do not query `localization.language` just to echo the language already passed to `@inContext`. If the app only knows country/language and does not have a market currency code, add `currencyCode` to the app's market config or query `localization { country { currency { isoCode } } }` as a fallback.
215
+ Read the locale from `requestContext.locale` (or `storefrontClient.locale`), the `{ language, country, pathPrefix }` resolved for the request from the `defineShopifyI18n` definition. Do not query `localization.language` just to echo the language already passed to `@inContext`. If the app does not have a currency code for the locale, add `currency` to the locale entries in `defineShopifyI18n` (extra fields survive on `requestContext.locale`) or query `localization { country { currency { isoCode } } }` as a fallback.
216
216
 
217
217
  React root layout:
218
218
 
@@ -223,7 +223,7 @@ React root layout:
223
223
  storefrontId: env.PUBLIC_STOREFRONT_ID ?? "0",
224
224
  myshopifyDomain: env.PUBLIC_STORE_DOMAIN,
225
225
  }}
226
- i18n={{ country: market.country, language: market.language, currency: market.currencyCode }}
226
+ i18n={{ ...storefrontClient.locale, currency: currencyCode }}
227
227
  consent={{ mode: "default-banner" }}
228
228
  />
229
229
  ```
@@ -237,7 +237,7 @@ const shopifyTags = renderShopifyScriptTags({
237
237
  storefrontId: env.PUBLIC_STOREFRONT_ID ?? "0",
238
238
  myshopifyDomain: env.PUBLIC_STORE_DOMAIN,
239
239
  },
240
- i18n: { country: market.country, language: market.language, currency: market.currencyCode },
240
+ i18n: { ...requestContext.locale, currency: currencyCode },
241
241
  consent: { mode: "default-banner" },
242
242
  });
243
243
  ```
@@ -583,7 +583,7 @@ analytics?.addDestination({
583
583
 
584
584
  Register all event consumers with `addDestination()` and subscribe inside its setup callback. Consent gating happens at the bus level before destination callbacks see the payload.
585
585
 
586
- Removing and re-adding a destination, even with the same name, creates a fresh registration and replays retained history again. This can duplicate deliveries on component remounts, including React Strict Mode's development effect replay. Keep destinations registered for the page's lifetime; use the returned cleanup when intentionally removing an integration.
586
+ The bus tracks replay progress by destination name. Re-adding a removed name resumes after the last event the bus processed for that name, including events it did not subscribe to, so component remounts and React Strict Mode's development effect replay do not redeliver retained events. If a re-added destination subscribes to additional event types, earlier retained events of those types are not replayed. A re-added name does receive retained events published while it was removed. A new name starts from the beginning of retained history. Still prefer registering destinations for the page's lifetime; use the returned cleanup when intentionally removing an integration.
587
587
 
588
588
  Destinations that need Shopify visitor IDs can call `getTrackingValues()` from the callback's second argument: `subscribe(event, (payload, { getTrackingValues }) => { ... })`. It reads current `uniqueToken` and `visitToken` values from the consent API when called, including during replay, and requests fallback generation with the tag `hydrogen:<destination name>`. Unavailable tokens are empty strings, and the getter also returns empty strings whenever analytics tracking is not currently allowed, so a retained getter cannot read or generate tokens after consent is revoked. Call it inside the destination callback; registration itself does not read or generate tokens.
589
589
 
@@ -615,7 +615,7 @@ For production, re-verify against the production bundle. Several gotchas only ap
615
615
  - **Astro page-view fires only on full loads.** Astro is MPA-by-default. If you adopt View Transitions, listen for `astro:after-swap` instead of relying on the inline-script-runs-on-load behavior — otherwise SPA-nav transitions skip `page_viewed`.
616
616
  - **Required product fields silently drop the Monorail leg.** Missing `id`/`title`/`vendor`/`variantId`/`variantTitle`/`price` causes the Shopify analytics subscriber to skip Monorail dispatch and log a field-specific error. The bus event still fires for your subscribers — the loss is only in Shopify analytics. Watch the console.
617
617
  - **A product event without a currency logs a warning. Shopify analytics still sends it.** `[shopify:warn:analytics] product_added_to_cart was sent without a currency` means the cart fragment's `cost.amountPerQuantity` has no `currencyCode` and `window.Shopify.currency.active` is unset. Select `currencyCode` in the fragment or pass `i18n.currency`. `product_viewed` cannot reach this warning through the typed `ProductPayload`, whose `price` is `MoneyV2`.
618
- - **Register destinations once per page lifetime.** Hydrogen owns the shared bus. Removing and re-adding a destination resets its replay position, so component remounts can deliver retained events again.
618
+ - **Replay progress is keyed by destination name.** Re-adding a removed name resumes where it left off, but a new name (for example one that includes a random suffix or a route key) receives all retained history again. Use a stable name per integration.
619
619
  - **Lighthouse skip is silent.** Monorail dispatch is skipped for Chrome Lighthouse user-agents. If your synthetic monitoring runs Lighthouse, you will see no Monorail requests in those runs — this is intentional.
620
620
 
621
621
  ---
@@ -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, // resolved market country, e.g. "US"
25
- language, // resolved market language, e.g. "EN"
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 market used by Storefront API requests (`country` + `language`, optional `currency`) — not a locale string, and not the analytics consent config.
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 origin is not registered, verify the signed-out rendering and handler wiring; skip the signed-in checks and say so instead of faking them.
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; when the local origin is not registered, verify the signed-out checks and say so instead of faking signed-in ones.
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: { country: "US", language: "EN" },
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: getLocaleFromRequest(request),
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: { country: "US", language: "EN" },
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` variables are auto-injected from `requestContext.i18n` when declared in the query. Static clients still create a request context, usually with empty headers plus the resolved locale. You only pass the variables you own:
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,9 @@ const { data } = await client.graphql(PRODUCTS, {
247
264
  });
248
265
  ```
249
266
 
250
- User-provided values take precedence over auto-injected ones.
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`.
268
+
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.
251
270
 
252
271
  ### Request state storage
253
272
 
@@ -299,7 +318,7 @@ const client = createStorefrontClient({
299
318
  type: "public",
300
319
  requestContext: createShopifyRequestContext({
301
320
  request: { headers: new Headers() },
302
- i18n: { country: "US", language: "EN" },
321
+ i18n: defineShopifyI18n({ defaultLocale: { language: "EN", country: "US" } }),
303
322
  }),
304
323
  config: {
305
324
  storeDomain: "test.myshopify.com",
@@ -315,7 +334,8 @@ const client = createStorefrontClient({
315
334
 
316
335
  - **Private tokens throw in browser** — a `typeof document !== "undefined"` guard fires at construction.
317
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.
318
- - **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 static `i18n`. Private per-buyer clients and clients with a real incoming request context must be created per request.
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.
319
339
 
320
340
  ---
321
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: { country: "US", language: "EN" },
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: { country: "US", language: "EN" },
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: { country: "US", language: "EN" },
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: { country: "US", language: "EN" },
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: { country: "US", language: "EN" },
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: { country: "US", language: "EN" },
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 7
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: { country: "US", language: "EN" },
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
- Verify React Router framework middleware is enabled with `future.v8_middleware: true` in `react-router.config.ts`. 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.
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: { country: "US", language: "EN" },
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: { country: "US", language: "EN" },
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: { country: "US", language: "EN" },
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: { country: "US", language: "EN" },
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: { country: "US", language: "EN" },
133
+ i18n,
134
+ locale: i18n.defaultLocale,
129
135
  });
130
136
 
131
137
  export const staticStorefrontClient = createStorefrontClient({