@shopify/hydrogen 1.0.2 → 1.3.0

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 (419) hide show
  1. package/README.md +1 -1
  2. package/dist/esnext/FileSessionStorage.d.ts +1 -1
  3. package/dist/esnext/FileSessionStorage.js +1 -1
  4. package/dist/esnext/client.d.ts +16 -16
  5. package/dist/esnext/client.js +16 -16
  6. package/dist/esnext/components/AddToCartButton/AddToCartButton.client.d.ts +5 -2
  7. package/dist/esnext/components/AddToCartButton/AddToCartButton.client.js +6 -5
  8. package/dist/esnext/components/AddToCartButton/index.d.ts +1 -1
  9. package/dist/esnext/components/AddToCartButton/index.js +1 -1
  10. package/dist/esnext/components/BaseButton/BaseButton.client.d.ts +7 -5
  11. package/dist/esnext/components/BaseButton/BaseButton.client.js +5 -4
  12. package/dist/esnext/components/BaseButton/index.d.ts +1 -1
  13. package/dist/esnext/components/BaseButton/index.js +1 -1
  14. package/dist/esnext/components/BuyNowButton/BuyNowButton.client.d.ts +3 -2
  15. package/dist/esnext/components/BuyNowButton/BuyNowButton.client.js +2 -2
  16. package/dist/esnext/components/BuyNowButton/index.d.ts +1 -1
  17. package/dist/esnext/components/BuyNowButton/index.js +1 -1
  18. package/dist/esnext/components/CartCheckoutButton/CartCheckoutButton.client.js +1 -1
  19. package/dist/esnext/components/CartCheckoutButton/index.d.ts +1 -1
  20. package/dist/esnext/components/CartCheckoutButton/index.js +1 -1
  21. package/dist/esnext/components/CartCost/CartCost.client.d.ts +1 -1
  22. package/dist/esnext/components/CartCost/CartCost.client.js +2 -2
  23. package/dist/esnext/components/CartCost/index.d.ts +1 -1
  24. package/dist/esnext/components/CartCost/index.js +1 -1
  25. package/dist/esnext/components/CartLineImage/CartLineImage.client.d.ts +1 -1
  26. package/dist/esnext/components/CartLineImage/CartLineImage.client.js +2 -2
  27. package/dist/esnext/components/CartLineImage/index.d.ts +1 -1
  28. package/dist/esnext/components/CartLineImage/index.js +1 -1
  29. package/dist/esnext/components/CartLinePrice/CartLinePrice.client.d.ts +1 -1
  30. package/dist/esnext/components/CartLinePrice/CartLinePrice.client.js +2 -2
  31. package/dist/esnext/components/CartLinePrice/index.d.ts +1 -1
  32. package/dist/esnext/components/CartLinePrice/index.js +1 -1
  33. package/dist/esnext/components/CartLineProductTitle/CartLineProductTitle.client.js +1 -1
  34. package/dist/esnext/components/CartLineProductTitle/index.d.ts +1 -1
  35. package/dist/esnext/components/CartLineProductTitle/index.js +1 -1
  36. package/dist/esnext/components/CartLineProvider/CartLineProvider.client.d.ts +1 -1
  37. package/dist/esnext/components/CartLineProvider/CartLineProvider.client.js +1 -1
  38. package/dist/esnext/components/CartLineProvider/context.d.ts +13 -13
  39. package/dist/esnext/components/CartLineProvider/index.d.ts +2 -2
  40. package/dist/esnext/components/CartLineProvider/index.js +2 -2
  41. package/dist/esnext/components/CartLineQuantity/CartLineQuantity.client.js +1 -1
  42. package/dist/esnext/components/CartLineQuantity/index.d.ts +1 -1
  43. package/dist/esnext/components/CartLineQuantity/index.js +1 -1
  44. package/dist/esnext/components/CartLineQuantityAdjustButton/CartLineQuantityAdjustButton.d.ts +7 -8
  45. package/dist/esnext/components/CartLineQuantityAdjustButton/CartLineQuantityAdjustButton.js +3 -3
  46. package/dist/esnext/components/CartLineQuantityAdjustButton/index.d.ts +1 -1
  47. package/dist/esnext/components/CartLineQuantityAdjustButton/index.js +1 -1
  48. package/dist/esnext/components/CartLines/CartLines.client.d.ts +1 -1
  49. package/dist/esnext/components/CartLines/CartLines.client.js +2 -2
  50. package/dist/esnext/components/CartLines/index.d.ts +1 -1
  51. package/dist/esnext/components/CartLines/index.js +1 -1
  52. package/dist/esnext/components/CartProvider/CartProvider.client.d.ts +2 -2
  53. package/dist/esnext/components/CartProvider/CartProvider.client.js +13 -7
  54. package/dist/esnext/components/CartProvider/cart-queries.d.ts +1 -1
  55. package/dist/esnext/components/CartProvider/cart-queries.js +1 -0
  56. package/dist/esnext/components/CartProvider/context.d.ts +1 -1
  57. package/dist/esnext/components/CartProvider/graphql/CartAttributesUpdateMutation.d.ts +1 -1
  58. package/dist/esnext/components/CartProvider/graphql/CartBuyerIdentityUpdateMutation.d.ts +1 -1
  59. package/dist/esnext/components/CartProvider/graphql/CartCreateMutation.d.ts +1 -1
  60. package/dist/esnext/components/CartProvider/graphql/CartDiscountCodesUpdateMutation.d.ts +1 -1
  61. package/dist/esnext/components/CartProvider/graphql/CartFragment.d.ts +1 -1
  62. package/dist/esnext/components/CartProvider/graphql/CartLineAddMutation.d.ts +1 -1
  63. package/dist/esnext/components/CartProvider/graphql/CartLineRemoveMutation.d.ts +1 -1
  64. package/dist/esnext/components/CartProvider/graphql/CartLineUpdateMutation.d.ts +1 -1
  65. package/dist/esnext/components/CartProvider/graphql/CartNoteUpdateMutation.d.ts +1 -1
  66. package/dist/esnext/components/CartProvider/graphql/CartQuery.d.ts +1 -1
  67. package/dist/esnext/components/CartProvider/hooks.client.d.ts +2 -2
  68. package/dist/esnext/components/CartProvider/hooks.client.js +4 -4
  69. package/dist/esnext/components/CartProvider/index.d.ts +4 -4
  70. package/dist/esnext/components/CartProvider/index.js +3 -3
  71. package/dist/esnext/components/CartProvider/types.d.ts +2 -2
  72. package/dist/esnext/components/CartShopPayButton/CartShopPayButton.client.d.ts +1 -1
  73. package/dist/esnext/components/CartShopPayButton/CartShopPayButton.client.js +2 -2
  74. package/dist/esnext/components/CartShopPayButton/index.d.ts +1 -1
  75. package/dist/esnext/components/CartShopPayButton/index.js +1 -1
  76. package/dist/esnext/components/ExternalVideo/ExternalVideo.d.ts +2 -2
  77. package/dist/esnext/components/ExternalVideo/ExternalVideo.js +1 -1
  78. package/dist/esnext/components/ExternalVideo/index.d.ts +1 -1
  79. package/dist/esnext/components/ExternalVideo/index.js +1 -1
  80. package/dist/esnext/components/Image/Image.d.ts +2 -2
  81. package/dist/esnext/components/Image/Image.js +5 -5
  82. package/dist/esnext/components/Image/index.d.ts +2 -2
  83. package/dist/esnext/components/Image/index.js +1 -1
  84. package/dist/esnext/components/Link/Link.client.js +5 -5
  85. package/dist/esnext/components/Link/index.d.ts +1 -1
  86. package/dist/esnext/components/Link/index.js +1 -1
  87. package/dist/esnext/components/LocalizationProvider/LocalizationClientProvider.client.d.ts +1 -1
  88. package/dist/esnext/components/LocalizationProvider/LocalizationClientProvider.client.js +1 -1
  89. package/dist/esnext/components/LocalizationProvider/LocalizationProvider.server.d.ts +1 -1
  90. package/dist/esnext/components/LocalizationProvider/LocalizationProvider.server.js +5 -5
  91. package/dist/esnext/components/LocalizationProvider/index.d.ts +1 -1
  92. package/dist/esnext/components/LocalizationProvider/index.js +1 -1
  93. package/dist/esnext/components/MediaFile/MediaFile.d.ts +4 -4
  94. package/dist/esnext/components/MediaFile/MediaFile.js +4 -4
  95. package/dist/esnext/components/MediaFile/index.d.ts +1 -1
  96. package/dist/esnext/components/MediaFile/index.js +1 -1
  97. package/dist/esnext/components/Metafield/Metafield.client.d.ts +2 -2
  98. package/dist/esnext/components/Metafield/Metafield.client.js +6 -6
  99. package/dist/esnext/components/Metafield/components/StarRating/StarRating.d.ts +1 -1
  100. package/dist/esnext/components/Metafield/components/StarRating/index.d.ts +1 -1
  101. package/dist/esnext/components/Metafield/components/StarRating/index.js +1 -1
  102. package/dist/esnext/components/Metafield/components/index.d.ts +1 -1
  103. package/dist/esnext/components/Metafield/components/index.js +1 -1
  104. package/dist/esnext/components/Metafield/index.d.ts +2 -2
  105. package/dist/esnext/components/Metafield/index.js +1 -1
  106. package/dist/esnext/components/Metafield/types.d.ts +1 -1
  107. package/dist/esnext/components/ModelViewer/ModelViewer.client.d.ts +2 -2
  108. package/dist/esnext/components/ModelViewer/ModelViewer.client.js +1 -1
  109. package/dist/esnext/components/ModelViewer/index.d.ts +1 -1
  110. package/dist/esnext/components/ModelViewer/index.js +1 -1
  111. package/dist/esnext/components/Money/Money.client.d.ts +1 -1
  112. package/dist/esnext/components/Money/Money.client.js +1 -1
  113. package/dist/esnext/components/Money/index.d.ts +1 -1
  114. package/dist/esnext/components/Money/index.js +1 -1
  115. package/dist/esnext/components/ProductOptionsProvider/ProductOptionsProvider.client.d.ts +1 -1
  116. package/dist/esnext/components/ProductOptionsProvider/ProductOptionsProvider.client.js +3 -3
  117. package/dist/esnext/components/ProductOptionsProvider/context.d.ts +1 -1
  118. package/dist/esnext/components/ProductOptionsProvider/index.d.ts +1 -1
  119. package/dist/esnext/components/ProductOptionsProvider/index.js +1 -1
  120. package/dist/esnext/components/ProductPrice/ProductPrice.client.d.ts +2 -2
  121. package/dist/esnext/components/ProductPrice/ProductPrice.client.js +2 -2
  122. package/dist/esnext/components/ProductPrice/index.d.ts +1 -1
  123. package/dist/esnext/components/ProductPrice/index.js +1 -1
  124. package/dist/esnext/components/Seo/CollectionSeo.client.d.ts +1 -1
  125. package/dist/esnext/components/Seo/CollectionSeo.client.js +4 -4
  126. package/dist/esnext/components/Seo/DefaultPageSeo.client.d.ts +1 -1
  127. package/dist/esnext/components/Seo/DefaultPageSeo.client.js +5 -5
  128. package/dist/esnext/components/Seo/DescriptionSeo.client.d.ts +1 -1
  129. package/dist/esnext/components/Seo/DescriptionSeo.client.js +1 -1
  130. package/dist/esnext/components/Seo/HomePageSeo.client.d.ts +1 -1
  131. package/dist/esnext/components/Seo/HomePageSeo.client.js +3 -3
  132. package/dist/esnext/components/Seo/ImageSeo.client.d.ts +1 -1
  133. package/dist/esnext/components/Seo/ImageSeo.client.js +1 -1
  134. package/dist/esnext/components/Seo/NoIndexSeo.client.d.ts +1 -1
  135. package/dist/esnext/components/Seo/NoIndexSeo.client.js +2 -2
  136. package/dist/esnext/components/Seo/PageSeo.client.d.ts +1 -1
  137. package/dist/esnext/components/Seo/PageSeo.client.js +3 -3
  138. package/dist/esnext/components/Seo/ProductSeo.client.d.ts +1 -1
  139. package/dist/esnext/components/Seo/ProductSeo.client.js +6 -6
  140. package/dist/esnext/components/Seo/Seo.client.d.ts +4 -4
  141. package/dist/esnext/components/Seo/Seo.client.js +7 -7
  142. package/dist/esnext/components/Seo/TitleSeo.client.d.ts +1 -1
  143. package/dist/esnext/components/Seo/TitleSeo.client.js +1 -1
  144. package/dist/esnext/components/Seo/TwitterSeo.client.d.ts +1 -1
  145. package/dist/esnext/components/Seo/TwitterSeo.client.js +1 -1
  146. package/dist/esnext/components/Seo/index.d.ts +1 -1
  147. package/dist/esnext/components/Seo/index.js +1 -1
  148. package/dist/esnext/components/Seo/seo-types.d.ts +1 -1
  149. package/dist/esnext/components/ShopPayButton/ShopPayButton.client.js +2 -2
  150. package/dist/esnext/components/ShopPayButton/index.d.ts +1 -1
  151. package/dist/esnext/components/ShopPayButton/index.js +1 -1
  152. package/dist/esnext/components/Video/Video.d.ts +7 -2
  153. package/dist/esnext/components/Video/Video.js +3 -3
  154. package/dist/esnext/components/Video/index.d.ts +1 -1
  155. package/dist/esnext/components/Video/index.js +1 -1
  156. package/dist/esnext/components/index.d.ts +27 -27
  157. package/dist/esnext/components/index.js +25 -25
  158. package/dist/esnext/config.d.ts +5 -5
  159. package/dist/esnext/config.js +4 -4
  160. package/dist/esnext/constants.d.ts +1 -0
  161. package/dist/esnext/constants.js +1 -0
  162. package/dist/esnext/entry-client.d.ts +1 -1
  163. package/dist/esnext/entry-client.js +35 -14
  164. package/dist/esnext/entry-server.d.ts +1 -1
  165. package/dist/esnext/entry-server.js +86 -60
  166. package/dist/esnext/experimental.d.ts +2 -0
  167. package/dist/esnext/experimental.js +2 -0
  168. package/dist/esnext/foundation/Analytics/Analytics.client.js +1 -1
  169. package/dist/esnext/foundation/Analytics/Analytics.server.js +5 -5
  170. package/dist/esnext/foundation/Analytics/ClientAnalytics.d.ts +1 -1
  171. package/dist/esnext/foundation/Analytics/ClientAnalytics.js +4 -4
  172. package/dist/esnext/foundation/Analytics/ServerAnalyticsRoute.d.ts +1 -1
  173. package/dist/esnext/foundation/Analytics/ServerAnalyticsRoute.js +1 -1
  174. package/dist/esnext/foundation/Analytics/connectors/PerformanceMetrics/PerformanceMetrics.client.js +7 -5
  175. package/dist/esnext/foundation/Analytics/connectors/PerformanceMetrics/PerformanceMetricsDebug.client.js +1 -1
  176. package/dist/esnext/foundation/Analytics/connectors/PerformanceMetrics/ServerAnalyticsConnector.js +1 -1
  177. package/dist/esnext/foundation/Analytics/connectors/Shopify/ServerAnalyticsConnector.js +1 -1
  178. package/dist/esnext/foundation/Analytics/connectors/Shopify/ShopifyAnalytics.client.js +3 -3
  179. package/dist/esnext/foundation/Analytics/connectors/Shopify/ShopifyAnalytics.server.js +9 -9
  180. package/dist/esnext/foundation/Analytics/hook.js +2 -2
  181. package/dist/esnext/foundation/Analytics/index.d.ts +1 -1
  182. package/dist/esnext/foundation/Analytics/index.js +1 -1
  183. package/dist/esnext/foundation/Analytics/utils.js +1 -1
  184. package/dist/esnext/foundation/BuiltInRoutes/BuiltInRoutes.d.ts +1 -1
  185. package/dist/esnext/foundation/BuiltInRoutes/BuiltInRoutes.js +3 -3
  186. package/dist/esnext/foundation/Cache/cache-sub-request.d.ts +1 -1
  187. package/dist/esnext/foundation/Cache/cache-sub-request.js +4 -4
  188. package/dist/esnext/foundation/Cache/cache.d.ts +1 -1
  189. package/dist/esnext/foundation/Cache/cache.js +3 -4
  190. package/dist/esnext/foundation/Cache/strategies/index.d.ts +1 -1
  191. package/dist/esnext/foundation/Cookie/Cookie.js +2 -2
  192. package/dist/esnext/foundation/CookieSessionStorage/CookieSessionStorage.d.ts +2 -2
  193. package/dist/esnext/foundation/CookieSessionStorage/CookieSessionStorage.js +2 -1
  194. package/dist/esnext/foundation/DevTools/DevTools.client.js +1 -1
  195. package/dist/esnext/foundation/DevTools/DevTools.server.js +4 -3
  196. package/dist/esnext/foundation/DevTools/components/Heading.js +1 -1
  197. package/dist/esnext/foundation/DevTools/components/Interface.client.js +1 -1
  198. package/dist/esnext/foundation/DevTools/components/Panels.d.ts +2 -2
  199. package/dist/esnext/foundation/DevTools/components/Panels.js +28 -22
  200. package/dist/esnext/foundation/DevTools/components/Performance.client.js +1 -2
  201. package/dist/esnext/foundation/DevTools/components/Settings.client.d.ts +2 -1
  202. package/dist/esnext/foundation/DevTools/components/Settings.client.js +2 -5
  203. package/dist/esnext/foundation/DevTools/components/Table.js +3 -3
  204. package/dist/esnext/foundation/DevTools/components/index.d.ts +2 -2
  205. package/dist/esnext/foundation/DevTools/components/index.js +2 -2
  206. package/dist/esnext/foundation/FileRoutes/FileRoutes.server.d.ts +1 -1
  207. package/dist/esnext/foundation/FileRoutes/FileRoutes.server.js +5 -5
  208. package/dist/esnext/foundation/FileSessionStorage/FileSessionStorage.d.ts +3 -3
  209. package/dist/esnext/foundation/FileSessionStorage/FileSessionStorage.js +2 -2
  210. package/dist/esnext/foundation/Form/Form.client.d.ts +11 -0
  211. package/dist/esnext/foundation/Form/Form.client.js +51 -0
  212. package/dist/esnext/foundation/Head/Head.client.js +1 -1
  213. package/dist/esnext/foundation/Head/index.d.ts +1 -1
  214. package/dist/esnext/foundation/Head/index.js +1 -1
  215. package/dist/esnext/foundation/Html/Html.d.ts +1 -1
  216. package/dist/esnext/foundation/HydrogenRequest/HydrogenRequest.server.d.ts +6 -5
  217. package/dist/esnext/foundation/HydrogenRequest/HydrogenRequest.server.js +6 -7
  218. package/dist/esnext/foundation/HydrogenResponse/HydrogenResponse.server.d.ts +2 -4
  219. package/dist/esnext/foundation/HydrogenResponse/HydrogenResponse.server.js +4 -18
  220. package/dist/esnext/foundation/MemorySessionStorage/MemorySessionStorage.d.ts +2 -2
  221. package/dist/esnext/foundation/MemorySessionStorage/MemorySessionStorage.js +1 -1
  222. package/dist/esnext/foundation/Redirect/Redirect.client.js +1 -1
  223. package/dist/esnext/foundation/Route/Route.server.js +3 -3
  224. package/dist/esnext/foundation/Router/BrowserRouter.client.js +2 -2
  225. package/dist/esnext/foundation/Router/Router.server.js +1 -1
  226. package/dist/esnext/foundation/ServerPropsProvider/ServerPropsProvider.d.ts +3 -1
  227. package/dist/esnext/foundation/ServerPropsProvider/ServerPropsProvider.js +7 -7
  228. package/dist/esnext/foundation/ServerPropsProvider/index.d.ts +1 -1
  229. package/dist/esnext/foundation/ServerPropsProvider/index.js +1 -1
  230. package/dist/esnext/foundation/ServerRequestProvider/ServerRequestProvider.d.ts +2 -2
  231. package/dist/esnext/foundation/ServerRequestProvider/ServerRequestProvider.js +3 -3
  232. package/dist/esnext/foundation/ServerRequestProvider/index.d.ts +1 -1
  233. package/dist/esnext/foundation/ServerRequestProvider/index.js +1 -1
  234. package/dist/esnext/foundation/ShopifyProvider/ShopifyProvider.client.d.ts +1 -1
  235. package/dist/esnext/foundation/ShopifyProvider/ShopifyProvider.server.d.ts +2 -2
  236. package/dist/esnext/foundation/ShopifyProvider/ShopifyProvider.server.js +7 -6
  237. package/dist/esnext/foundation/ShopifyProvider/index.d.ts +1 -1
  238. package/dist/esnext/foundation/ShopifyProvider/index.js +1 -1
  239. package/dist/esnext/foundation/ShopifyProvider/types.d.ts +4 -3
  240. package/dist/esnext/foundation/fetchSync/ResponseSync.d.ts +14 -0
  241. package/dist/esnext/foundation/fetchSync/ResponseSync.js +38 -0
  242. package/dist/esnext/foundation/fetchSync/client/fetchSync.d.ts +2 -2
  243. package/dist/esnext/foundation/fetchSync/client/fetchSync.js +5 -10
  244. package/dist/esnext/foundation/fetchSync/server/fetchSync.d.ts +3 -3
  245. package/dist/esnext/foundation/fetchSync/server/fetchSync.js +7 -13
  246. package/dist/esnext/foundation/index.d.ts +3 -3
  247. package/dist/esnext/foundation/index.js +3 -3
  248. package/dist/esnext/foundation/session/session-types.d.ts +15 -0
  249. package/dist/esnext/foundation/{fetchSync/types.js → session/session-types.js} +0 -0
  250. package/dist/esnext/foundation/session/session.d.ts +7 -16
  251. package/dist/esnext/foundation/session/session.js +17 -1
  252. package/dist/esnext/foundation/ssr-interop.d.ts +2 -2
  253. package/dist/esnext/foundation/ssr-interop.js +2 -2
  254. package/dist/esnext/foundation/useNavigate/useNavigate.js +2 -2
  255. package/dist/esnext/foundation/useQuery/hooks.d.ts +4 -1
  256. package/dist/esnext/foundation/useQuery/hooks.js +5 -5
  257. package/dist/esnext/foundation/useQuery/index.d.ts +1 -1
  258. package/dist/esnext/foundation/useQuery/index.js +1 -1
  259. package/dist/esnext/foundation/useRequestContext/index.js +1 -1
  260. package/dist/esnext/foundation/useRouteParams/useRouteParams.js +2 -2
  261. package/dist/esnext/foundation/useServerProps/index.d.ts +1 -1
  262. package/dist/esnext/foundation/useServerProps/index.js +1 -1
  263. package/dist/esnext/foundation/useServerProps/use-server-props.d.ts +1 -1
  264. package/dist/esnext/foundation/useServerProps/use-server-props.js +1 -1
  265. package/dist/esnext/foundation/useSession/useSession.d.ts +1 -0
  266. package/dist/esnext/foundation/useSession/useSession.js +14 -1
  267. package/dist/esnext/foundation/useShop/index.d.ts +1 -1
  268. package/dist/esnext/foundation/useShop/index.js +1 -1
  269. package/dist/esnext/foundation/useShop/use-shop.d.ts +1 -1
  270. package/dist/esnext/foundation/useShop/use-shop.js +2 -2
  271. package/dist/esnext/foundation/useUrl/index.d.ts +1 -1
  272. package/dist/esnext/foundation/useUrl/index.js +1 -1
  273. package/dist/esnext/foundation/useUrl/useUrl.js +4 -4
  274. package/dist/esnext/framework/graphiql.js +26 -30
  275. package/dist/esnext/framework/load-config.js +2 -2
  276. package/dist/esnext/framework/middleware.d.ts +1 -1
  277. package/dist/esnext/framework/middleware.js +2 -2
  278. package/dist/esnext/framework/plugin.d.ts +1 -1
  279. package/dist/esnext/framework/plugin.js +17 -15
  280. package/dist/esnext/framework/plugins/vite-plugin-assets-version.d.ts +2 -0
  281. package/dist/esnext/framework/plugins/vite-plugin-assets-version.js +8 -0
  282. package/dist/esnext/framework/plugins/vite-plugin-css-modules-rsc.js +1 -1
  283. package/dist/esnext/framework/plugins/vite-plugin-css-rsc.d.ts +2 -0
  284. package/dist/esnext/framework/plugins/vite-plugin-css-rsc.js +108 -0
  285. package/dist/esnext/framework/plugins/vite-plugin-hydrogen-config.d.ts +2 -1
  286. package/dist/esnext/framework/plugins/vite-plugin-hydrogen-config.js +8 -4
  287. package/dist/esnext/framework/plugins/vite-plugin-hydrogen-middleware.d.ts +1 -1
  288. package/dist/esnext/framework/plugins/vite-plugin-hydrogen-middleware.js +3 -3
  289. package/dist/esnext/framework/plugins/vite-plugin-hydrogen-rsc.d.ts +1 -1
  290. package/dist/esnext/framework/plugins/vite-plugin-hydrogen-rsc.js +2 -2
  291. package/dist/esnext/framework/plugins/vite-plugin-hydrogen-virtual-files.d.ts +1 -1
  292. package/dist/esnext/framework/plugins/vite-plugin-hydrogen-virtual-files.js +35 -7
  293. package/dist/esnext/framework/plugins/vite-plugin-platform-entry.js +36 -7
  294. package/dist/esnext/framework/types.d.ts +14 -0
  295. package/dist/esnext/hooks/index.d.ts +6 -6
  296. package/dist/esnext/hooks/index.js +6 -6
  297. package/dist/esnext/hooks/useCart/index.d.ts +1 -1
  298. package/dist/esnext/hooks/useCart/index.js +1 -1
  299. package/dist/esnext/hooks/useCart/useCart.d.ts +1 -1
  300. package/dist/esnext/hooks/useCart/useCart.js +1 -1
  301. package/dist/esnext/hooks/useCartLine/index.d.ts +1 -1
  302. package/dist/esnext/hooks/useCartLine/index.js +1 -1
  303. package/dist/esnext/hooks/useCartLine/useCartLine.d.ts +13 -13
  304. package/dist/esnext/hooks/useCartLine/useCartLine.js +1 -1
  305. package/dist/esnext/hooks/useLoadScript/index.d.ts +1 -1
  306. package/dist/esnext/hooks/useLoadScript/index.js +1 -1
  307. package/dist/esnext/hooks/useLoadScript/useLoadScript.client.d.ts +1 -1
  308. package/dist/esnext/hooks/useLoadScript/useLoadScript.client.js +1 -1
  309. package/dist/esnext/hooks/useLocalization/useLocalization.d.ts +2 -3
  310. package/dist/esnext/hooks/useLocalization/useLocalization.js +2 -2
  311. package/dist/esnext/hooks/useMeasurement/hooks.d.ts +1 -1
  312. package/dist/esnext/hooks/useMeasurement/hooks.js +2 -2
  313. package/dist/esnext/hooks/useMeasurement/index.d.ts +1 -1
  314. package/dist/esnext/hooks/useMeasurement/index.js +1 -1
  315. package/dist/esnext/hooks/useMoney/hooks.d.ts +1 -1
  316. package/dist/esnext/hooks/useMoney/hooks.js +1 -1
  317. package/dist/esnext/hooks/useMoney/index.d.ts +1 -1
  318. package/dist/esnext/hooks/useMoney/index.js +1 -1
  319. package/dist/esnext/hooks/useProductOptions/helpers.d.ts +2 -2
  320. package/dist/esnext/hooks/useProductOptions/index.d.ts +2 -2
  321. package/dist/esnext/hooks/useProductOptions/index.js +2 -2
  322. package/dist/esnext/hooks/useProductOptions/types.d.ts +1 -1
  323. package/dist/esnext/hooks/useProductOptions/useProductOptions.client.d.ts +1 -1
  324. package/dist/esnext/hooks/useProductOptions/useProductOptions.client.js +1 -1
  325. package/dist/esnext/hooks/useShopQuery/hooks.d.ts +1 -1
  326. package/dist/esnext/hooks/useShopQuery/hooks.js +25 -17
  327. package/dist/esnext/hooks/useShopQuery/index.d.ts +1 -1
  328. package/dist/esnext/hooks/useShopQuery/index.js +1 -1
  329. package/dist/esnext/index.d.ts +26 -26
  330. package/dist/esnext/index.js +22 -22
  331. package/dist/esnext/node.d.ts +1 -1
  332. package/dist/esnext/node.js +1 -1
  333. package/dist/esnext/platforms/index.d.ts +1 -0
  334. package/dist/esnext/platforms/index.js +1 -0
  335. package/dist/esnext/platforms/node.d.ts +1 -1
  336. package/dist/esnext/platforms/node.js +5 -11
  337. package/dist/esnext/platforms/virtual.d.ts +8 -0
  338. package/dist/esnext/platforms/virtual.js +12 -0
  339. package/dist/esnext/platforms/worker-event.js +1 -1
  340. package/dist/esnext/platforms/worker.js +7 -7
  341. package/dist/esnext/shared-types.d.ts +3 -0
  342. package/dist/esnext/types.d.ts +8 -7
  343. package/dist/esnext/types.js +1 -1
  344. package/dist/esnext/utilities/apiRoutes.d.ts +4 -4
  345. package/dist/esnext/utilities/apiRoutes.js +51 -6
  346. package/dist/esnext/utilities/error.js +1 -1
  347. package/dist/esnext/utilities/fetch.js +1 -1
  348. package/dist/esnext/utilities/flattenConnection/flattenConnection.d.ts +1 -1
  349. package/dist/esnext/utilities/flattenConnection/index.d.ts +1 -1
  350. package/dist/esnext/utilities/flattenConnection/index.js +1 -1
  351. package/dist/esnext/utilities/hash.d.ts +1 -1
  352. package/dist/esnext/utilities/hash.js +1 -1
  353. package/dist/esnext/utilities/image_size.d.ts +1 -1
  354. package/dist/esnext/utilities/index.d.ts +12 -12
  355. package/dist/esnext/utilities/index.js +12 -12
  356. package/dist/esnext/utilities/isBrowser/index.d.ts +1 -1
  357. package/dist/esnext/utilities/isBrowser/index.js +1 -1
  358. package/dist/esnext/utilities/isServer/index.d.ts +1 -1
  359. package/dist/esnext/utilities/isServer/index.js +1 -1
  360. package/dist/esnext/utilities/isServer/isServer.js +1 -1
  361. package/dist/esnext/utilities/load_script.d.ts +1 -0
  362. package/dist/esnext/utilities/load_script.js +6 -1
  363. package/dist/esnext/utilities/locale/index.d.ts +1 -0
  364. package/dist/esnext/utilities/locale/index.js +1 -0
  365. package/dist/esnext/utilities/locale/locale.d.ts +7 -0
  366. package/dist/esnext/utilities/locale/locale.js +22 -0
  367. package/dist/esnext/utilities/log/index.d.ts +4 -4
  368. package/dist/esnext/utilities/log/index.js +4 -4
  369. package/dist/esnext/utilities/log/log-cache-api-status.js +1 -1
  370. package/dist/esnext/utilities/log/log-cache-header.d.ts +4 -4
  371. package/dist/esnext/utilities/log/log-cache-header.js +3 -3
  372. package/dist/esnext/utilities/log/log-query-timeline.d.ts +3 -3
  373. package/dist/esnext/utilities/log/log-query-timeline.js +13 -10
  374. package/dist/esnext/utilities/log/log.d.ts +1 -1
  375. package/dist/esnext/utilities/log/log.js +2 -2
  376. package/dist/esnext/utilities/log/utils.d.ts +1 -1
  377. package/dist/esnext/utilities/log/utils.js +1 -1
  378. package/dist/esnext/utilities/measurement.d.ts +1 -1
  379. package/dist/esnext/utilities/parseMetafield/index.d.ts +1 -1
  380. package/dist/esnext/utilities/parseMetafield/index.js +1 -1
  381. package/dist/esnext/utilities/parseMetafield/parseMetafield.d.ts +2 -2
  382. package/dist/esnext/utilities/parseMetafield/parseMetafield.js +1 -1
  383. package/dist/esnext/utilities/storefrontApi.js +1 -1
  384. package/dist/esnext/utilities/suspense.d.ts +1 -1
  385. package/dist/esnext/utilities/suspense.js +1 -1
  386. package/dist/esnext/version.d.ts +1 -1
  387. package/dist/esnext/version.js +1 -1
  388. package/dist/node/foundation/session/session-types.d.ts +15 -0
  389. package/dist/node/foundation/session/session-types.js +2 -0
  390. package/dist/node/framework/graphiql.js +26 -30
  391. package/dist/node/framework/load-config.js +3 -3
  392. package/dist/node/framework/middleware.d.ts +1 -1
  393. package/dist/node/framework/middleware.js +3 -3
  394. package/dist/node/framework/plugin.d.ts +1 -1
  395. package/dist/node/framework/plugin.js +26 -24
  396. package/dist/node/framework/plugins/vite-plugin-assets-version.d.ts +2 -0
  397. package/dist/node/framework/plugins/vite-plugin-assets-version.js +11 -0
  398. package/dist/node/framework/plugins/vite-plugin-css-modules-rsc.js +3 -3
  399. package/dist/node/framework/plugins/vite-plugin-css-rsc.d.ts +2 -0
  400. package/dist/node/framework/plugins/vite-plugin-css-rsc.js +114 -0
  401. package/dist/node/framework/plugins/vite-plugin-hydrogen-config.d.ts +2 -1
  402. package/dist/node/framework/plugins/vite-plugin-hydrogen-config.js +11 -4
  403. package/dist/node/framework/plugins/vite-plugin-hydrogen-middleware.d.ts +1 -1
  404. package/dist/node/framework/plugins/vite-plugin-hydrogen-middleware.js +7 -7
  405. package/dist/node/framework/plugins/vite-plugin-hydrogen-rsc.d.ts +1 -1
  406. package/dist/node/framework/plugins/vite-plugin-hydrogen-rsc.js +5 -5
  407. package/dist/node/framework/plugins/vite-plugin-hydrogen-virtual-files.d.ts +1 -1
  408. package/dist/node/framework/plugins/vite-plugin-hydrogen-virtual-files.js +35 -7
  409. package/dist/node/framework/plugins/vite-plugin-platform-entry.js +36 -7
  410. package/dist/node/framework/types.d.ts +14 -0
  411. package/dist/node/shared-types.d.ts +3 -0
  412. package/package.json +20 -3
  413. package/vendor/react-server-dom-vite/cjs/react-server-dom-vite-plugin.js +36 -14
  414. package/vendor/react-server-dom-vite/esm/react-server-dom-vite-plugin.js +36 -14
  415. package/dist/esnext/foundation/fetchSync/types.d.ts +0 -5
  416. package/dist/esnext/framework/plugins/vite-plugin-purge-query-cache.d.ts +0 -3
  417. package/dist/esnext/framework/plugins/vite-plugin-purge-query-cache.js +0 -11
  418. package/dist/node/framework/plugins/vite-plugin-purge-query-cache.d.ts +0 -3
  419. package/dist/node/framework/plugins/vite-plugin-purge-query-cache.js +0 -16
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const path_1 = __importDefault(require("path"));
7
+ const magic_string_1 = __importDefault(require("magic-string"));
8
+ const vite_1 = require("vite");
9
+ const VITE_CSS_CHUNK_NAME = 'style.css';
10
+ const INJECT_STYLES_COMMENT = '<!--__INJECT_STYLES__-->';
11
+ // Keep this in the outer scope to share it
12
+ // across client <> server builds.
13
+ let clientBuildPath;
14
+ function cssRsc() {
15
+ let config;
16
+ return {
17
+ name: 'hydrogen:css-rsc',
18
+ enforce: 'post',
19
+ config() {
20
+ // Disable CSS code split to avoid preloading styles
21
+ // that are already included in index.html
22
+ return { build: { cssCodeSplit: false } };
23
+ },
24
+ configResolved(_config) {
25
+ config = _config;
26
+ },
27
+ transform(code, id, options) {
28
+ if (options?.ssr && id.includes('index.html?raw')) {
29
+ // Mark the client build index.html to inject styles later
30
+ const s = new magic_string_1.default(code);
31
+ s.replace('</head>', INJECT_STYLES_COMMENT + '</head>');
32
+ return {
33
+ code: s.toString(),
34
+ map: s.generateMap({ file: id, source: id }),
35
+ };
36
+ }
37
+ },
38
+ transformIndexHtml(html, { server }) {
39
+ // Add discovered styles during dev
40
+ if (server) {
41
+ const tags = [];
42
+ const foundCssFiles = new Set();
43
+ for (const [key, value] of server.moduleGraph.idToModuleMap.entries()) {
44
+ if (
45
+ // Note: Some CSS-in-JS libraries use `.css.js`
46
+ // extension and we should match it here:
47
+ /\.(css|sass|scss|stylus|less)(\.|\?|$)/.test((0, vite_1.normalizePath)(key).split('/').pop())) {
48
+ let { url, file, lastHMRTimestamp, importers } = value;
49
+ if (!foundCssFiles.has(file) &&
50
+ !Array.from(importers).some((importer) => foundCssFiles.has(importer.file))) {
51
+ foundCssFiles.add(file);
52
+ // Vite is adding hash and timestamp to the CSS files downloaded
53
+ // from client components. Adding the same query string params
54
+ // here prevents this file from being downloaded twice.
55
+ if (lastHMRTimestamp) {
56
+ const timestampQuery = `?t=${lastHMRTimestamp}`;
57
+ // The timestamp needs to be the first query string param.
58
+ url = url.includes('?')
59
+ ? url.replace('?', timestampQuery + '&')
60
+ : url + timestampQuery;
61
+ }
62
+ tags.push(value.type === 'css'
63
+ ? { tag: 'link', attrs: { rel: 'stylesheet', href: url } }
64
+ : { tag: 'script', attrs: { type: 'module', src: url } });
65
+ }
66
+ }
67
+ }
68
+ return tags;
69
+ }
70
+ },
71
+ generateBundle(options, bundle, isWrite) {
72
+ if (config.build?.ssr) {
73
+ // -- Server build
74
+ if (!clientBuildPath) {
75
+ // Default value
76
+ clientBuildPath = (0, vite_1.normalizePath)(path_1.default.resolve(config.root, config.build.outDir, '..', 'client'));
77
+ }
78
+ const relativeClientPath = (0, vite_1.normalizePath)(path_1.default.relative((0, vite_1.normalizePath)(path_1.default.resolve(config.root, config.build.outDir)), clientBuildPath));
79
+ let cssAssetFileName = '';
80
+ const cssAsset = Object.values(bundle).find((file) => file.type === 'asset' && file.name === VITE_CSS_CHUNK_NAME);
81
+ const outputChunk = Object.values(bundle).find((file) => file.type === 'chunk' && file.isEntry);
82
+ if (cssAsset) {
83
+ cssAssetFileName = cssAsset.fileName;
84
+ // Move the CSS file to the client build assets
85
+ cssAsset.fileName = (0, vite_1.normalizePath)(path_1.default.join(relativeClientPath, cssAsset.fileName));
86
+ }
87
+ let assetPrefix = process.env.HYDROGEN_ASSET_BASE_URL || '/';
88
+ if (!assetPrefix.endsWith('/'))
89
+ assetPrefix += '/';
90
+ // Add a reference to the CSS file in indexTemplate
91
+ outputChunk.code = outputChunk.code.replace(INJECT_STYLES_COMMENT, cssAssetFileName &&
92
+ `<link rel="stylesheet" href="${assetPrefix + cssAssetFileName}">`);
93
+ }
94
+ else {
95
+ // -- Client build
96
+ // Save outDir from client build in the outer scope
97
+ // to read it during the server build. The CLI runs Vite in
98
+ // the same process so the scope is shared across builds.
99
+ clientBuildPath = (0, vite_1.normalizePath)(path_1.default.resolve(config.root, config.build.outDir));
100
+ const indexHtml = bundle['index.html'];
101
+ const cssAsset = Object.values(bundle).find((file) => file.type === 'asset' && file.name === VITE_CSS_CHUNK_NAME);
102
+ if (cssAsset) {
103
+ // The client build CSS is incomplete because it only includes
104
+ // CSS imported in client components (server components are not
105
+ // discovered in this build). Remove it from this build and
106
+ // let it be added by the server build after this.
107
+ delete bundle[cssAsset.fileName];
108
+ indexHtml.source = indexHtml.source.replace(new RegExp(`\\s*<link[^<>]+${cssAsset.fileName.replace('.', '\\.')}.*?>`, ''), '');
109
+ }
110
+ }
111
+ },
112
+ };
113
+ }
114
+ exports.default = cssRsc;
@@ -1,3 +1,4 @@
1
1
  import { Plugin } from 'vite';
2
- declare const _default: () => Plugin;
2
+ import type { HydrogenVitePluginOptions } from '../types.js';
3
+ declare const _default: (pluginOptions: HydrogenVitePluginOptions) => Plugin;
3
4
  export default _default;
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = () => {
6
+ const crypto_1 = __importDefault(require("crypto"));
7
+ exports.default = (pluginOptions) => {
4
8
  const rollupOptions = {
5
9
  output: {},
6
10
  };
@@ -25,7 +29,7 @@ exports.default = () => {
25
29
  };
26
30
  }
27
31
  return {
28
- name: 'vite-plugin-hydrogen-config',
32
+ name: 'hydrogen:config',
29
33
  config: async (config, env) => ({
30
34
  resolve: {
31
35
  alias: {
@@ -50,7 +54,7 @@ exports.default = () => {
50
54
  * Tell Vite to bundle everything when we're building for Workers.
51
55
  * Otherwise, bundle RSC plugin as a workaround to apply the vendor alias above.
52
56
  */
53
- noExternal: isWorker || [/react-server-dom-vite/],
57
+ noExternal: isWorker || [/react-server-dom-vite/, /@shopify\/hydrogen/],
54
58
  target: isWorker ? 'webworker' : 'node',
55
59
  },
56
60
  // Reload when updating local Hydrogen lib
@@ -95,7 +99,10 @@ exports.default = () => {
95
99
  define: {
96
100
  __HYDROGEN_DEV__: env.mode !== 'production',
97
101
  __HYDROGEN_WORKER__: isWorker,
98
- __HYDROGEN_TEST__: false, // Used in unit tests
102
+ __HYDROGEN_TEST__: false,
103
+ __HYDROGEN_CACHE_ID__: pluginOptions.purgeQueryCacheOnBuild
104
+ ? `"${crypto_1.default.randomBytes(8).toString('hex').slice(0, 8)}"`
105
+ : '"__QUERY_CACHE_ID__"',
99
106
  },
100
107
  envPrefix: ['VITE_', 'PUBLIC_'],
101
108
  base: process.env.HYDROGEN_ASSET_BASE_URL,
@@ -1,5 +1,5 @@
1
1
  import { Plugin } from 'vite';
2
- import type { HydrogenVitePluginOptions } from '../types';
2
+ import type { HydrogenVitePluginOptions } from '../types.js';
3
3
  export declare const HYDROGEN_DEFAULT_SERVER_ENTRY: string;
4
4
  declare const _default: (pluginOptions: HydrogenVitePluginOptions) => Plugin;
5
5
  export default _default;
@@ -8,9 +8,9 @@ const vite_1 = require("vite");
8
8
  const body_parser_1 = __importDefault(require("body-parser"));
9
9
  const path_1 = __importDefault(require("path"));
10
10
  const fs_1 = require("fs");
11
- const middleware_1 = require("../middleware");
12
- const in_memory_1 = require("../cache/in-memory");
13
- const vite_plugin_hydrogen_virtual_files_1 = require("./vite-plugin-hydrogen-virtual-files");
11
+ const middleware_js_1 = require("../middleware.js");
12
+ const in_memory_js_1 = require("../cache/in-memory.js");
13
+ const vite_plugin_hydrogen_virtual_files_js_1 = require("./vite-plugin-hydrogen-virtual-files.js");
14
14
  exports.HYDROGEN_DEFAULT_SERVER_ENTRY = process.env.HYDROGEN_SERVER_ENTRY || '/src/App.server';
15
15
  exports.default = (pluginOptions) => {
16
16
  return {
@@ -30,10 +30,10 @@ exports.default = (pluginOptions) => {
30
30
  await polyfillOxygenEnv(server.config);
31
31
  // The default vite middleware rewrites the URL `/graphqil` to `/index.html`
32
32
  // By running this middleware first, we avoid that.
33
- server.middlewares.use((0, middleware_1.graphiqlMiddleware)({
33
+ server.middlewares.use((0, middleware_js_1.graphiqlMiddleware)({
34
34
  dev: true,
35
35
  getShopifyConfig: async (incomingMessage) => {
36
- const { default: hydrogenConfig } = await server.ssrLoadModule(vite_plugin_hydrogen_virtual_files_1.VIRTUAL_PROXY_HYDROGEN_CONFIG_ID);
36
+ const { default: hydrogenConfig } = await server.ssrLoadModule(vite_plugin_hydrogen_virtual_files_js_1.VIRTUAL_PROXY_HYDROGEN_CONFIG_ID);
37
37
  // @ts-ignore
38
38
  const { address = 'localhost', port = '3000' } = server.httpServer?.address() || {};
39
39
  const url = new URL(`http://${address}:${port}${incomingMessage.url}`);
@@ -48,13 +48,13 @@ exports.default = (pluginOptions) => {
48
48
  },
49
49
  }));
50
50
  server.middlewares.use(body_parser_1.default.raw({ type: '*/*' }));
51
- return () => server.middlewares.use((0, middleware_1.hydrogenMiddleware)({
51
+ return () => server.middlewares.use((0, middleware_js_1.hydrogenMiddleware)({
52
52
  dev: true,
53
53
  indexTemplate: getIndexTemplate,
54
54
  getServerEntrypoint: () => server.ssrLoadModule(exports.HYDROGEN_DEFAULT_SERVER_ENTRY),
55
55
  devServer: server,
56
56
  cache: pluginOptions?.devCache
57
- ? new in_memory_1.InMemoryCache()
57
+ ? new in_memory_js_1.InMemoryCache()
58
58
  : undefined,
59
59
  }));
60
60
  },
@@ -1,2 +1,2 @@
1
- import { HydrogenVitePluginOptions } from '../types';
1
+ import { HydrogenVitePluginOptions } from '../types.js';
2
2
  export default function (options?: HydrogenVitePluginOptions): any;
@@ -5,19 +5,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  // @ts-ignore
7
7
  const plugin_js_1 = __importDefault(require("@shopify/hydrogen/vendor/react-server-dom-vite/plugin.js"));
8
- const vite_plugin_hydrogen_middleware_1 = require("./vite-plugin-hydrogen-middleware");
9
- const vite_plugin_hydrogen_virtual_files_1 = require("./vite-plugin-hydrogen-virtual-files");
8
+ const vite_plugin_hydrogen_middleware_js_1 = require("./vite-plugin-hydrogen-middleware.js");
9
+ const vite_plugin_hydrogen_virtual_files_js_1 = require("./vite-plugin-hydrogen-virtual-files.js");
10
10
  function default_1(options) {
11
11
  return (0, plugin_js_1.default)({
12
12
  serverBuildEntries: [
13
- vite_plugin_hydrogen_middleware_1.HYDROGEN_DEFAULT_SERVER_ENTRY,
14
- vite_plugin_hydrogen_virtual_files_1.VIRTUAL_PROXY_HYDROGEN_ROUTES_ID,
13
+ vite_plugin_hydrogen_middleware_js_1.HYDROGEN_DEFAULT_SERVER_ENTRY,
14
+ vite_plugin_hydrogen_virtual_files_js_1.VIRTUAL_PROXY_HYDROGEN_ROUTES_ID,
15
15
  ],
16
16
  isServerComponentImporterAllowed(importer, source) {
17
17
  return (
18
18
  // Always allow the entry server (e.g. App.server.jsx) to be imported
19
19
  // in other files such as worker.js or server.js.
20
- source.includes(vite_plugin_hydrogen_middleware_1.HYDROGEN_DEFAULT_SERVER_ENTRY) ||
20
+ source.includes(vite_plugin_hydrogen_middleware_js_1.HYDROGEN_DEFAULT_SERVER_ENTRY) ||
21
21
  /(index|entry-server|hydrogen\.config)\.[jt]s/.test(importer) ||
22
22
  // Support importing server components for testing
23
23
  // TODO: revisit this when RSC splits into two bundles
@@ -1,5 +1,5 @@
1
1
  import { Plugin } from 'vite';
2
- import type { HydrogenVitePluginOptions } from '../types';
2
+ import type { HydrogenVitePluginOptions } from '../types.js';
3
3
  export declare const HYDROGEN_DEFAULT_SERVER_ENTRY: string;
4
4
  export declare const VIRTUAL_PROXY_HYDROGEN_CONFIG_ID: string;
5
5
  export declare const VIRTUAL_PROXY_HYDROGEN_ROUTES_ID: string;
@@ -7,11 +7,14 @@ exports.VIRTUAL_PROXY_HYDROGEN_ROUTES_ID = exports.VIRTUAL_PROXY_HYDROGEN_CONFIG
7
7
  const vite_1 = require("vite");
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const fs_1 = require("fs");
10
- const viteception_1 = require("../viteception");
10
+ const viteception_js_1 = require("../viteception.js");
11
+ const magic_string_1 = __importDefault(require("magic-string"));
11
12
  exports.HYDROGEN_DEFAULT_SERVER_ENTRY = process.env.HYDROGEN_SERVER_ENTRY || '/src/App.server';
12
13
  // The character ":" breaks Vite with Node >= 16.15. Use "_" instead
13
14
  const VIRTUAL_PREFIX = 'virtual__';
14
15
  const PROXY_PREFIX = 'proxy__';
16
+ const ERROR_FILE = 'error.jsx';
17
+ const VIRTUAL_ERROR_FILE = VIRTUAL_PREFIX + ERROR_FILE;
15
18
  const HYDROGEN_CONFIG_ID = 'hydrogen.config.ts';
16
19
  const VIRTUAL_HYDROGEN_CONFIG_ID = VIRTUAL_PREFIX + HYDROGEN_CONFIG_ID;
17
20
  exports.VIRTUAL_PROXY_HYDROGEN_CONFIG_ID = VIRTUAL_PREFIX + PROXY_PREFIX + HYDROGEN_CONFIG_ID;
@@ -21,6 +24,7 @@ exports.VIRTUAL_PROXY_HYDROGEN_ROUTES_ID = VIRTUAL_PREFIX + PROXY_PREFIX + HYDRO
21
24
  exports.default = (pluginOptions) => {
22
25
  let config;
23
26
  let server;
27
+ let resolvedConfigPath;
24
28
  return {
25
29
  name: 'hydrogen:virtual-files',
26
30
  configResolved(_config) {
@@ -31,15 +35,18 @@ exports.default = (pluginOptions) => {
31
35
  },
32
36
  resolveId(source, importer) {
33
37
  if (source === VIRTUAL_HYDROGEN_CONFIG_ID) {
34
- return findHydrogenConfigPath(config.root, pluginOptions.configPath).then((hcPath) =>
35
- // This direct dependency on a real file
36
- // makes HMR work for the virtual module.
37
- this.resolve(hcPath, importer, { skipSelf: true }));
38
+ return findHydrogenConfigPath(config.root, pluginOptions.configPath).then((hcPath) => {
39
+ resolvedConfigPath = (0, vite_1.normalizePath)(hcPath);
40
+ // This direct dependency on a real file
41
+ // makes HMR work for the virtual module.
42
+ return this.resolve(hcPath, importer, { skipSelf: true });
43
+ });
38
44
  }
39
45
  if ([
40
46
  exports.VIRTUAL_PROXY_HYDROGEN_CONFIG_ID,
41
47
  exports.VIRTUAL_PROXY_HYDROGEN_ROUTES_ID,
42
48
  VIRTUAL_HYDROGEN_ROUTES_ID,
49
+ VIRTUAL_ERROR_FILE,
43
50
  ].includes(source)) {
44
51
  // Virtual modules convention
45
52
  // https://vitejs.dev/guide/api-plugin.html#virtual-modules-convention
@@ -50,7 +57,7 @@ exports.default = (pluginOptions) => {
50
57
  // Likely due to a bug in Vite, but virtual modules cannot be loaded
51
58
  // directly using ssrLoadModule from a Vite plugin. It needs to be proxied as follows:
52
59
  if (id === '\0' + exports.VIRTUAL_PROXY_HYDROGEN_CONFIG_ID) {
53
- return `import hc from '${VIRTUAL_HYDROGEN_CONFIG_ID}'; export default hc;`;
60
+ return `import hc from '${VIRTUAL_HYDROGEN_CONFIG_ID}'; export default typeof hc === 'function' ? hc() : hc;`;
54
61
  }
55
62
  if (id === '\0' + exports.VIRTUAL_PROXY_HYDROGEN_ROUTES_ID) {
56
63
  return `import hr from '${VIRTUAL_HYDROGEN_ROUTES_ID}'; export default hr;`;
@@ -77,6 +84,25 @@ exports.default = (pluginOptions) => {
77
84
  return { code };
78
85
  });
79
86
  }
87
+ if (id === '\0' + VIRTUAL_ERROR_FILE) {
88
+ return importHydrogenConfig().then((hc) => {
89
+ const errorPath = hc.serverErrorPage ?? '/src/Error.{jsx,tsx}';
90
+ const code = `const errorPage = import.meta.glob("${errorPath}");\n export default Object.values(errorPage)[0];`;
91
+ return { code };
92
+ });
93
+ }
94
+ },
95
+ transform(code, id) {
96
+ if (id === resolvedConfigPath) {
97
+ const s = new magic_string_1.default(code);
98
+ // Wrap in function to avoid evaluating `Oxygen.env`
99
+ // in the config until we have polyfilled it properly.
100
+ s.replace(/export\s+default\s+(\w+)\s*\(/g, (all, m1) => all.replace(m1, `() => ${m1}`));
101
+ return {
102
+ code: s.toString(),
103
+ map: s.generateMap({ file: id, source: id }),
104
+ };
105
+ }
80
106
  },
81
107
  };
82
108
  async function importHydrogenConfig() {
@@ -84,7 +110,9 @@ exports.default = (pluginOptions) => {
84
110
  const loaded = await server.ssrLoadModule(exports.VIRTUAL_PROXY_HYDROGEN_CONFIG_ID);
85
111
  return loaded.default;
86
112
  }
87
- const { loaded } = await (0, viteception_1.viteception)([exports.VIRTUAL_PROXY_HYDROGEN_CONFIG_ID]);
113
+ const { loaded } = await (0, viteception_js_1.viteception)([exports.VIRTUAL_PROXY_HYDROGEN_CONFIG_ID], {
114
+ root: config.root,
115
+ });
88
116
  return loaded[0].default;
89
117
  }
90
118
  };
@@ -4,16 +4,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const vite_1 = require("vite");
7
- const vite_plugin_hydrogen_middleware_1 = require("./vite-plugin-hydrogen-middleware");
7
+ const vite_plugin_hydrogen_middleware_js_1 = require("./vite-plugin-hydrogen-middleware.js");
8
8
  const magic_string_1 = __importDefault(require("magic-string"));
9
9
  const path_1 = __importDefault(require("path"));
10
10
  const fs_1 = __importDefault(require("fs"));
11
+ const fast_glob_1 = __importDefault(require("fast-glob"));
11
12
  const SSR_BUNDLE_NAME = 'index.js';
13
+ // Keep this in the outer scope to share it
14
+ // across client <> server builds.
15
+ let clientBuildPath;
12
16
  exports.default = () => {
13
17
  let config;
14
18
  let isESM;
15
19
  return {
16
- name: 'vite-plugin-platform-entry',
20
+ name: 'hydrogen:platform-entry',
17
21
  enforce: 'pre',
18
22
  configResolved(_config) {
19
23
  config = _config;
@@ -34,18 +38,43 @@ exports.default = () => {
34
38
  }
35
39
  return null;
36
40
  },
37
- transform(code, id) {
38
- if ((0, vite_1.normalizePath)(id).includes('/hydrogen/dist/esnext/platforms/')) {
41
+ async transform(code, id, options) {
42
+ if (config.command === 'build' &&
43
+ options?.ssr &&
44
+ /@shopify\/hydrogen\/.+platforms\/virtual\./.test((0, vite_1.normalizePath)(id))) {
39
45
  const ms = new magic_string_1.default(code);
40
- ms.replace('__SERVER_ENTRY__', vite_plugin_hydrogen_middleware_1.HYDROGEN_DEFAULT_SERVER_ENTRY);
41
- const indexTemplatePath = (0, vite_1.normalizePath)(path_1.default.resolve(config.root, config.build.outDir, '..', 'client', 'index.html'));
42
- ms.replace('__INDEX_TEMPLATE__', indexTemplatePath);
46
+ ms.replace('__HYDROGEN_ENTRY__', vite_plugin_hydrogen_middleware_js_1.HYDROGEN_DEFAULT_SERVER_ENTRY);
47
+ if (!clientBuildPath) {
48
+ // Default value
49
+ clientBuildPath = (0, vite_1.normalizePath)(path_1.default.resolve(config.root, config.build.outDir, '..', 'client'));
50
+ }
51
+ ms.replace('__HYDROGEN_HTML_TEMPLATE__', (0, vite_1.normalizePath)(path_1.default.resolve(clientBuildPath, 'index.html')));
52
+ ms.replace('__HYDROGEN_RELATIVE_CLIENT_BUILD__', (0, vite_1.normalizePath)(path_1.default.relative((0, vite_1.normalizePath)(path_1.default.resolve(config.root, config.build.outDir)), clientBuildPath)));
53
+ const files = clientBuildPath
54
+ ? (await (0, fast_glob_1.default)('**/*', {
55
+ cwd: clientBuildPath,
56
+ ignore: ['**/index.html', `**/${config.build.assetsDir}/**`],
57
+ })).map((file) => '/' + file)
58
+ : [];
59
+ ms.replace("\\['__HYDROGEN_ASSETS__'\\]", JSON.stringify(files));
60
+ ms.replace('__HYDROGEN_ASSETS_DIR__', config.build.assetsDir);
61
+ ms.replace('__HYDROGEN_ASSETS_BASE_URL__', (process.env.HYDROGEN_ASSET_BASE_URL || '').replace(/\/$/, ''));
62
+ // Remove the poison pill
63
+ ms.replace('throw', '//');
43
64
  return {
44
65
  code: ms.toString(),
45
66
  map: ms.generateMap({ file: id, source: id }),
46
67
  };
47
68
  }
48
69
  },
70
+ buildEnd(err) {
71
+ if (!err && !config.build.ssr && config.command === 'build') {
72
+ // Save outDir from client build in the outer scope in order
73
+ // to read it during the server build. The CLI runs Vite in
74
+ // the same process so the scope is shared across builds.
75
+ clientBuildPath = (0, vite_1.normalizePath)(path_1.default.resolve(config.root, config.build.outDir));
76
+ }
77
+ },
49
78
  generateBundle(options, bundle) {
50
79
  if (config.build.ssr) {
51
80
  const [key, value] = Object.entries(bundle).find(([, value]) => value.type === 'chunk' && value.isEntry);
@@ -3,4 +3,18 @@ export interface HydrogenVitePluginOptions {
3
3
  purgeQueryCacheOnBuild?: boolean;
4
4
  configPath?: string;
5
5
  optimizeBoundaries?: boolean | 'build';
6
+ assetHashVersion?: string;
7
+ /**
8
+ * Experimental features
9
+ */
10
+ experimental?: {
11
+ /**
12
+ * CSS compatibility with React Server Components.
13
+ * - `global` inlines all the styles in the DOM and works for all types of CSS.
14
+ * - `modules-only` inlines the styles in RSC responses and only works for CSS Modules.
15
+ * @defaultValue `modules-only`
16
+ * @experimental
17
+ */
18
+ css: 'global' | 'modules-only';
19
+ };
6
20
  }
@@ -1,5 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import type { IncomingMessage, ServerResponse } from 'http';
3
+ import type { SessionStorageAdapter } from './foundation/session/session-types';
3
4
  export interface RuntimeContext {
4
5
  waitUntil: (fn: Promise<any>) => void;
5
6
  }
@@ -13,6 +14,8 @@ export interface RequestHandlerOptions {
13
14
  context?: RuntimeContext;
14
15
  nonce?: string;
15
16
  buyerIpHeader?: string;
17
+ sessionApi?: SessionStorageAdapter;
18
+ headers?: Headers;
16
19
  }
17
20
  export interface RequestHandler {
18
21
  (request: Request | IncomingMessage, options: RequestHandlerOptions): Promise<Response | undefined>;
package/package.json CHANGED
@@ -7,12 +7,16 @@
7
7
  "engines": {
8
8
  "node": ">=14"
9
9
  },
10
- "version": "1.0.2",
10
+ "version": "1.3.0",
11
11
  "description": "Modern custom Shopify storefronts",
12
12
  "license": "MIT",
13
13
  "main": "dist/esnext/index.js",
14
14
  "exports": {
15
15
  ".": "./dist/esnext/index.js",
16
+ "./experimental": {
17
+ "import": "./dist/esnext/experimental.js",
18
+ "require": "./dist/node/experimental.js"
19
+ },
16
20
  "./plugin": {
17
21
  "import": "./dist/esnext/framework/plugin.js",
18
22
  "require": "./dist/node/framework/plugin.js"
@@ -35,6 +39,11 @@
35
39
  "import": "./dist/esnext/framework/cache/*.js",
36
40
  "require": "./dist/node/framework/cache/*.js"
37
41
  },
42
+ "./platforms": {
43
+ "types": "./dist/esnext/platforms/virtual.d.ts",
44
+ "import": "./dist/esnext/platforms/virtual.js",
45
+ "require": "./dist/node/platforms/virtual.js"
46
+ },
38
47
  "./package.json": "./package.json",
39
48
  "./*": "./dist/esnext/*.js"
40
49
  },
@@ -57,7 +66,9 @@
57
66
  "lint": "eslint --ext .ts src/** --no-error-on-unmatched-pattern",
58
67
  "format": "prettier --write --parser typescript \"src/**/*.ts\"",
59
68
  "graphql-types": "graphql-codegen --config codegen.yml && yarn format",
60
- "prepack": "yarn build"
69
+ "prepack": "yarn build",
70
+ "test:vitest": "vitest",
71
+ "test:vitest:ci": "vitest run --coverage"
61
72
  },
62
73
  "repository": {
63
74
  "type": "git",
@@ -78,6 +89,9 @@
78
89
  "@graphql-codegen/typescript-operations": "2.3.2",
79
90
  "@graphql-typed-document-node/core": "^3.1.0",
80
91
  "@rollup/plugin-graphql": "^1.0.0",
92
+ "@testing-library/jest-dom": "^5.16.4",
93
+ "@testing-library/react": "^13.3.0",
94
+ "@testing-library/user-event": "^14.3.0",
81
95
  "@types/body-parser": "^1.19.2",
82
96
  "@types/connect": "^3.4.34",
83
97
  "@types/graphql": "^14.5.0",
@@ -90,11 +104,14 @@
90
104
  "@types/ws": "^8.2.0",
91
105
  "babel-loader": "^8.2.2",
92
106
  "cpy-cli": "^3.1.0",
107
+ "eslint-plugin-import": "^2.26.0",
108
+ "happy-dom": "^6.0.4",
93
109
  "mkdirp": "^1.0.4",
94
110
  "npm-run-all": "^4.1.5",
95
111
  "postcss": "^8",
96
112
  "raw-loader": "^4.0.2",
97
- "rimraf": "^3.0.2"
113
+ "rimraf": "^3.0.2",
114
+ "vitest": "^0.22.0"
98
115
  },
99
116
  "peerDependencies": {
100
117
  "body-parser": "^1.20.0",
@@ -126,6 +126,13 @@ function ReactFlightVitePlugin() {
126
126
  return {
127
127
  name: 'vite-plugin-react-server-components',
128
128
  enforce: 'pre',
129
+ buildStart: function () {
130
+ // Let other plugins differentiate between pure SSR and RSC builds
131
+ if (config?.build?.ssr) process.env.VITE_RSC_BUILD = 'true';
132
+ },
133
+ buildEnd: function () {
134
+ if (config?.build?.ssr) delete process.env.VITE_RSC_BUILD;
135
+ },
129
136
  configureServer: function (_server) {
130
137
  server = _server;
131
138
  var seenModules = {};
@@ -295,8 +302,21 @@ function ReactFlightVitePlugin() {
295
302
  throw new Error('[react-server-dom-vite] Parameter serverBuildEntries is required for client build');
296
303
  }
297
304
 
298
- return findClientBoundariesForClientBuild(serverBuildEntries, optimizeBoundaries !== false).then(injectGlobs);
305
+ return findClientBoundariesForClientBuild(serverBuildEntries, optimizeBoundaries !== false, config.root).then(injectGlobs);
306
+ }
307
+ },
308
+ handleHotUpdate: function (_ref2) {
309
+ var modules = _ref2.modules;
310
+
311
+ if (modules.some(function (mod) {
312
+ return mod.meta && mod.meta.isClientComponent;
313
+ })) {
314
+ return modules.filter(function (mod) {
315
+ return !mod.meta || !mod.meta.ssr;
316
+ });
299
317
  }
318
+
319
+ return modules;
300
320
  }
301
321
  };
302
322
  }
@@ -385,9 +405,10 @@ function findClientBoundaries(moduleGraph) {
385
405
  return clientBoundaries;
386
406
  }
387
407
 
388
- async function findClientBoundariesForClientBuild(serverEntries, optimizeBoundaries) {
408
+ async function findClientBoundariesForClientBuild(serverEntries, optimizeBoundaries, root) {
389
409
  // Viteception
390
410
  var server = await vite.createServer({
411
+ root: root,
391
412
  clearScreen: false,
392
413
  server: {
393
414
  middlewareMode: 'ssr'
@@ -466,9 +487,9 @@ function isDirectImportInServer(originalMod, currentMod, accModInfo) {
466
487
  exports: []
467
488
  };
468
489
  lastModImports.forEach(function (mod) {
469
- mod.variables.forEach(function (_ref2) {
470
- var name = _ref2[0],
471
- alias = _ref2[1];
490
+ mod.variables.forEach(function (_ref3) {
491
+ var name = _ref3[0],
492
+ alias = _ref3[1];
472
493
 
473
494
  if (name === '*' && !alias) {
474
495
  var _accModInfo$exports;
@@ -501,8 +522,8 @@ function isDirectImportInServer(originalMod, currentMod, accModInfo) {
501
522
  // the original module before marking it as client boundary.
502
523
 
503
524
  return currentMod.meta.imports.some(function (imp) {
504
- return imp.from === accModInfo.file && (imp.variables || []).some(function (_ref3) {
505
- var name = _ref3[0];
525
+ return imp.from === accModInfo.file && (imp.variables || []).some(function (_ref4) {
526
+ var name = _ref4[0];
506
527
  return accModInfo.exports.includes(name);
507
528
  });
508
529
  });
@@ -540,12 +561,12 @@ function augmentModuleGraph(moduleGraph, id, code, root, resolveAlias) {
540
561
 
541
562
 
542
563
  var imports = [];
543
- rawImports.forEach(function (_ref4) {
544
- var startMod = _ref4.s,
545
- endMod = _ref4.e,
546
- dynamicImportIndex = _ref4.d,
547
- startStatement = _ref4.ss,
548
- endStatement = _ref4.se;
564
+ rawImports.forEach(function (_ref5) {
565
+ var startMod = _ref5.s,
566
+ endMod = _ref5.e,
567
+ dynamicImportIndex = _ref5.d,
568
+ startStatement = _ref5.ss,
569
+ endStatement = _ref5.se;
549
570
  if (dynamicImportIndex !== -1) return; // Skip dynamic imports for now
550
571
 
551
572
  var rawModPath = code.slice(startMod, endMod);
@@ -593,7 +614,8 @@ function augmentModuleGraph(moduleGraph, id, code, root, resolveAlias) {
593
614
  assign(currentModule.meta, {
594
615
  isFacade: isFacade,
595
616
  namedExports: namedExports,
596
- imports: imports
617
+ imports: imports,
618
+ ssr: true
597
619
  });
598
620
  }
599
621