@shopify/hydrogen 0.22.1 → 0.23.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.
- package/CHANGELOG.md +207 -0
- package/dist/esnext/components/AddToCartButton/AddToCartButton.client.js +5 -5
- package/dist/esnext/components/CartLines/{CartLines.d.ts → CartLines.client.d.ts} +0 -0
- package/dist/esnext/components/CartLines/{CartLines.js → CartLines.client.js} +0 -0
- package/dist/esnext/components/CartLines/index.d.ts +1 -1
- package/dist/esnext/components/CartLines/index.js +1 -1
- package/dist/esnext/components/DevTools.client.js +1 -1
- package/dist/esnext/components/Image/Image.d.ts +8 -0
- package/dist/esnext/components/Image/Image.js +58 -10
- package/dist/esnext/components/Link/Link.client.d.ts +2 -0
- package/dist/esnext/components/Link/Link.client.js +7 -4
- package/dist/esnext/components/LocalizationProvider/LocalizationProvider.server.js +1 -1
- package/dist/esnext/components/ProductOptionsProvider/ProductOptionsProvider.client.d.ts +21 -0
- package/dist/esnext/components/ProductOptionsProvider/ProductOptionsProvider.client.js +140 -0
- package/dist/esnext/components/ProductOptionsProvider/context.d.ts +2 -0
- package/dist/esnext/components/{ProductProvider → ProductOptionsProvider}/context.js +0 -1
- package/dist/esnext/components/ProductOptionsProvider/index.d.ts +2 -0
- package/dist/esnext/components/ProductOptionsProvider/index.js +2 -0
- package/dist/esnext/components/ProductPrice/ProductPrice.client.d.ts +5 -2
- package/dist/esnext/components/ProductPrice/ProductPrice.client.js +10 -12
- package/dist/esnext/components/index.d.ts +1 -1
- package/dist/esnext/components/index.js +1 -1
- package/dist/esnext/entry-client.js +106 -6
- package/dist/esnext/entry-server.d.ts +2 -15
- package/dist/esnext/entry-server.js +245 -321
- package/dist/esnext/foundation/Analytics/Analytics.client.js +15 -13
- package/dist/esnext/foundation/Analytics/Analytics.server.js +27 -20
- package/dist/esnext/foundation/Analytics/ClientAnalytics.d.ts +4 -2
- package/dist/esnext/foundation/Analytics/ClientAnalytics.js +15 -13
- package/dist/esnext/foundation/Analytics/ServerAnalyticsRoute.server.js +7 -5
- package/dist/esnext/foundation/Analytics/connectors/PerformanceMetrics/ServerAnalyticsConnector.server.d.ts +1 -0
- package/dist/esnext/foundation/Analytics/connectors/PerformanceMetrics/{PerformanceMetrics.server.js → ServerAnalyticsConnector.server.js} +7 -6
- package/dist/esnext/foundation/Analytics/connectors/Shopify/ServerAnalyticsConnector.server.d.ts +1 -0
- package/dist/esnext/foundation/Analytics/connectors/Shopify/ServerAnalyticsConnector.server.js +19 -0
- package/dist/esnext/foundation/Analytics/connectors/Shopify/ShopifyAnalytics.client.d.ts +3 -0
- package/dist/esnext/foundation/Analytics/connectors/Shopify/ShopifyAnalytics.client.js +190 -0
- package/dist/esnext/foundation/Analytics/connectors/Shopify/ShopifyAnalytics.server.d.ts +3 -0
- package/dist/esnext/foundation/Analytics/connectors/Shopify/ShopifyAnalytics.server.js +24 -0
- package/dist/esnext/foundation/Analytics/connectors/Shopify/const.d.ts +28 -0
- package/dist/esnext/foundation/Analytics/connectors/Shopify/const.js +51 -0
- package/dist/esnext/foundation/Analytics/connectors/Shopify/utils.d.ts +3 -0
- package/dist/esnext/foundation/Analytics/connectors/Shopify/utils.js +56 -0
- package/dist/esnext/foundation/Analytics/hook.js +4 -2
- package/dist/esnext/foundation/Analytics/utils.d.ts +2 -0
- package/dist/esnext/foundation/Analytics/utils.js +21 -0
- package/dist/{node/framework → esnext/foundation/Cache}/cache-sub-request.d.ts +1 -1
- package/dist/esnext/{framework → foundation/Cache}/cache-sub-request.js +3 -3
- package/dist/esnext/{framework → foundation/Cache}/cache.d.ts +1 -1
- package/dist/esnext/{framework → foundation/Cache}/cache.js +3 -3
- package/dist/{node/framework/CachingStrategy → esnext/foundation/Cache/strategies}/index.d.ts +1 -1
- package/dist/esnext/{framework/CachingStrategy → foundation/Cache/strategies}/index.js +0 -0
- package/dist/esnext/foundation/Cookie/Cookie.d.ts +3 -3
- package/dist/{node/framework/Hydration → esnext/foundation/Html}/Html.d.ts +3 -1
- package/dist/esnext/{framework/Hydration → foundation/Html}/Html.js +15 -2
- package/dist/{node/framework/Hydration/ServerComponentRequest.server.d.ts → esnext/foundation/HydrogenRequest/HydrogenRequest.server.d.ts} +7 -3
- package/dist/esnext/{framework/Hydration/ServerComponentRequest.server.js → foundation/HydrogenRequest/HydrogenRequest.server.js} +1 -1
- package/dist/{node/framework/Hydration/ServerComponentResponse.server.d.ts → esnext/foundation/HydrogenResponse/HydrogenResponse.server.d.ts} +7 -10
- package/dist/esnext/{framework/Hydration/ServerComponentResponse.server.js → foundation/HydrogenResponse/HydrogenResponse.server.js} +19 -15
- package/dist/esnext/foundation/Router/BrowserRouter.client.js +16 -9
- package/dist/esnext/foundation/ServerPropsProvider/ServerPropsProvider.d.ts +2 -1
- package/dist/esnext/foundation/ServerPropsProvider/ServerPropsProvider.js +1 -1
- package/dist/esnext/foundation/ServerRequestProvider/ServerRequestProvider.d.ts +4 -4
- package/dist/esnext/foundation/ServerRequestProvider/ServerRequestProvider.js +2 -2
- package/dist/esnext/foundation/ServerStateProvider/ServerStateProvider.d.ts +1 -1
- package/dist/esnext/foundation/ServerStateProvider/ServerStateProvider.js +1 -1
- package/dist/esnext/foundation/ShopifyProvider/ShopifyProvider.server.js +1 -0
- package/dist/esnext/foundation/index.d.ts +1 -1
- package/dist/esnext/foundation/index.js +1 -1
- package/dist/esnext/foundation/runtime.d.ts +2 -0
- package/dist/esnext/foundation/runtime.js +6 -0
- package/dist/esnext/foundation/session/session.d.ts +3 -3
- package/dist/esnext/foundation/ssr-interop.d.ts +2 -2
- package/dist/esnext/foundation/useNavigate/useNavigate.d.ts +2 -0
- package/dist/esnext/foundation/useNavigate/useNavigate.js +11 -4
- package/dist/esnext/foundation/useQuery/hooks.js +9 -6
- package/dist/esnext/framework/Hydration/rsc.js +2 -0
- package/dist/esnext/framework/plugin.js +2 -0
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-config.js +5 -2
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-middleware.js +1 -1
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-rsc.js +4 -12
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-suppress-warnings.d.ts +3 -0
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-suppress-warnings.js +19 -0
- package/dist/esnext/hooks/useParsedMetafields/useParsedMetafields.d.ts +2 -2
- package/dist/esnext/hooks/useProductOptions/types.d.ts +16 -14
- package/dist/esnext/hooks/useProductOptions/useProductOptions.client.d.ts +1 -15
- package/dist/esnext/hooks/useProductOptions/useProductOptions.client.js +8 -107
- package/dist/esnext/hooks/useShopQuery/hooks.js +12 -6
- package/dist/esnext/index.d.ts +6 -3
- package/dist/esnext/index.js +6 -3
- package/dist/esnext/streaming.server.d.ts +0 -1
- package/dist/esnext/streaming.server.js +0 -4
- package/dist/esnext/types.d.ts +32 -23
- package/dist/esnext/utilities/apiRoutes.d.ts +2 -2
- package/dist/esnext/utilities/graphql-tracker.js +1 -1
- package/dist/esnext/utilities/index.d.ts +1 -1
- package/dist/esnext/utilities/index.js +1 -1
- package/dist/esnext/utilities/isBrowser/index.d.ts +1 -0
- package/dist/esnext/utilities/isBrowser/index.js +1 -0
- package/dist/esnext/utilities/isBrowser/isBrowser.d.ts +4 -0
- package/dist/esnext/utilities/isBrowser/isBrowser.js +6 -0
- package/dist/esnext/utilities/isServer/isServer.js +2 -2
- package/dist/esnext/utilities/log/index.d.ts +1 -1
- package/dist/esnext/utilities/log/index.js +1 -1
- package/dist/esnext/utilities/log/log-cache-header.d.ts +4 -4
- package/dist/esnext/utilities/log/log-query-timeline.d.ts +3 -3
- package/dist/esnext/utilities/log/log.d.ts +17 -11
- package/dist/esnext/utilities/log/log.js +29 -20
- package/dist/esnext/version.d.ts +1 -1
- package/dist/esnext/version.js +1 -1
- package/dist/node/client.d.ts +16 -0
- package/dist/node/client.js +43 -0
- package/dist/node/components/AddToCartButton/AddToCartButton.client.d.ts +23 -0
- package/dist/node/components/AddToCartButton/AddToCartButton.client.js +74 -0
- package/dist/node/components/AddToCartButton/index.d.ts +1 -0
- package/dist/node/components/AddToCartButton/index.js +5 -0
- package/dist/node/components/BuyNowButton/BuyNowButton.client.d.ts +18 -0
- package/dist/node/components/BuyNowButton/BuyNowButton.client.js +53 -0
- package/dist/node/components/BuyNowButton/index.d.ts +1 -0
- package/dist/node/components/BuyNowButton/index.js +5 -0
- package/dist/node/components/CartCheckoutButton/CartCheckoutButton.client.d.ts +11 -0
- package/dist/node/components/CartCheckoutButton/CartCheckoutButton.client.js +44 -0
- package/dist/node/components/CartCheckoutButton/index.d.ts +1 -0
- package/dist/node/components/CartCheckoutButton/index.js +5 -0
- package/dist/node/components/CartEstimatedCost/CartEstimatedCost.client.d.ts +14 -0
- package/dist/node/components/CartEstimatedCost/CartEstimatedCost.client.js +36 -0
- package/dist/node/components/CartEstimatedCost/index.d.ts +1 -0
- package/dist/node/components/CartEstimatedCost/index.js +5 -0
- package/dist/node/components/CartLineImage/CartLineImage.client.d.ts +9 -0
- package/dist/node/components/CartLineImage/CartLineImage.client.js +18 -0
- package/dist/node/components/CartLineImage/index.d.ts +1 -0
- package/dist/node/components/CartLineImage/index.js +5 -0
- package/dist/node/components/CartLinePrice/CartLinePrice.client.d.ts +12 -0
- package/dist/node/components/CartLinePrice/CartLinePrice.client.js +28 -0
- package/dist/node/components/CartLinePrice/index.d.ts +1 -0
- package/dist/node/components/CartLinePrice/index.js +5 -0
- package/dist/node/components/CartLineProductTitle/CartLineProductTitle.client.d.ts +8 -0
- package/dist/node/components/CartLineProductTitle/CartLineProductTitle.client.js +19 -0
- package/dist/node/components/CartLineProductTitle/index.d.ts +1 -0
- package/dist/node/components/CartLineProductTitle/index.js +5 -0
- package/dist/node/components/CartLineProvider/CartLineProvider.client.d.ts +11 -0
- package/dist/node/components/CartLineProvider/CartLineProvider.client.js +15 -0
- package/dist/node/components/CartLineProvider/context.d.ts +26 -0
- package/dist/node/components/CartLineProvider/context.js +5 -0
- package/dist/node/components/CartLineProvider/index.d.ts +2 -0
- package/dist/node/components/CartLineProvider/index.js +7 -0
- package/dist/node/components/CartLineQuantity/CartLineQuantity.client.d.ts +8 -0
- package/dist/node/components/CartLineQuantity/CartLineQuantity.client.js +19 -0
- package/dist/node/components/CartLineQuantity/index.d.ts +1 -0
- package/dist/node/components/CartLineQuantity/index.js +5 -0
- package/dist/node/components/CartLineQuantityAdjustButton/CartLineQuantityAdjustButton.d.ts +14 -0
- package/dist/node/components/CartLineQuantityAdjustButton/CartLineQuantityAdjustButton.js +31 -0
- package/dist/node/components/CartLineQuantityAdjustButton/index.d.ts +1 -0
- package/dist/node/components/CartLineQuantityAdjustButton/index.js +5 -0
- package/dist/node/components/CartLines/CartLines.client.d.ts +15 -0
- package/dist/node/components/CartLines/CartLines.client.js +44 -0
- package/dist/node/components/CartLines/index.d.ts +1 -0
- package/dist/node/components/CartLines/index.js +5 -0
- package/dist/node/components/CartProvider/CartProvider.client.d.ts +41 -0
- package/dist/node/components/CartProvider/CartProvider.client.js +550 -0
- package/dist/node/components/CartProvider/cart-queries.d.ts +10 -0
- package/dist/node/components/CartProvider/cart-queries.js +203 -0
- package/dist/node/components/CartProvider/constants.d.ts +2 -0
- package/dist/node/components/CartProvider/constants.js +5 -0
- package/dist/node/components/CartProvider/context.d.ts +2 -0
- package/dist/node/components/CartProvider/context.js +5 -0
- package/dist/node/components/CartProvider/graphql/CartAttributesUpdateMutation.d.ts +86 -0
- package/dist/node/components/CartProvider/graphql/CartAttributesUpdateMutation.js +2 -0
- package/dist/node/components/CartProvider/graphql/CartBuyerIdentityUpdateMutation.d.ts +86 -0
- package/dist/node/components/CartProvider/graphql/CartBuyerIdentityUpdateMutation.js +2 -0
- package/dist/node/components/CartProvider/graphql/CartCreateMutation.d.ts +85 -0
- package/dist/node/components/CartProvider/graphql/CartCreateMutation.js +2 -0
- package/dist/node/components/CartProvider/graphql/CartDiscountCodesUpdateMutation.d.ts +86 -0
- package/dist/node/components/CartProvider/graphql/CartDiscountCodesUpdateMutation.js +2 -0
- package/dist/node/components/CartProvider/graphql/CartFragment.d.ts +72 -0
- package/dist/node/components/CartProvider/graphql/CartFragment.js +2 -0
- package/dist/node/components/CartProvider/graphql/CartLineAddMutation.d.ts +86 -0
- package/dist/node/components/CartProvider/graphql/CartLineAddMutation.js +2 -0
- package/dist/node/components/CartProvider/graphql/CartLineRemoveMutation.d.ts +86 -0
- package/dist/node/components/CartProvider/graphql/CartLineRemoveMutation.js +2 -0
- package/dist/node/components/CartProvider/graphql/CartLineUpdateMutation.d.ts +86 -0
- package/dist/node/components/CartProvider/graphql/CartLineUpdateMutation.js +2 -0
- package/dist/node/components/CartProvider/graphql/CartNoteUpdateMutation.d.ts +86 -0
- package/dist/node/components/CartProvider/graphql/CartNoteUpdateMutation.js +2 -0
- package/dist/node/components/CartProvider/graphql/CartQuery.d.ts +81 -0
- package/dist/node/components/CartProvider/graphql/CartQuery.js +2 -0
- package/dist/node/components/CartProvider/hooks.client.d.ts +15 -0
- package/dist/node/components/CartProvider/hooks.client.js +90 -0
- package/dist/node/components/CartProvider/index.d.ts +4 -0
- package/dist/node/components/CartProvider/index.js +10 -0
- package/dist/node/components/CartProvider/types.d.ts +102 -0
- package/dist/node/components/CartProvider/types.js +2 -0
- package/dist/node/components/CartShopPayButton/CartShopPayButton.client.d.ts +9 -0
- package/dist/node/components/CartShopPayButton/CartShopPayButton.client.js +46 -0
- package/dist/node/components/CartShopPayButton/index.d.ts +1 -0
- package/dist/node/components/CartShopPayButton/index.js +5 -0
- package/dist/node/components/ExternalVideo/ExternalVideo.d.ts +21 -0
- package/dist/node/components/ExternalVideo/ExternalVideo.js +21 -0
- package/dist/node/components/ExternalVideo/index.d.ts +1 -0
- package/dist/node/components/ExternalVideo/index.js +5 -0
- package/dist/node/components/Image/Image.d.ts +8 -0
- package/dist/node/components/Image/Image.js +57 -9
- package/dist/node/components/Link/Link.client.d.ts +25 -0
- package/dist/node/components/Link/Link.client.js +165 -0
- package/dist/node/components/Link/index.d.ts +1 -0
- package/dist/node/components/Link/index.js +5 -0
- package/dist/node/components/LocalizationProvider/LocalizationClientProvider.client.d.ts +6 -0
- package/dist/node/components/LocalizationProvider/LocalizationClientProvider.client.js +11 -0
- package/dist/node/components/LocalizationProvider/LocalizationContext.client.d.ts +6 -0
- package/dist/node/components/LocalizationProvider/LocalizationContext.client.js +5 -0
- package/dist/node/components/LocalizationProvider/LocalizationProvider.server.d.ts +33 -0
- package/dist/node/components/LocalizationProvider/LocalizationProvider.server.js +51 -0
- package/dist/node/components/MediaFile/MediaFile.d.ts +19 -0
- package/dist/node/components/MediaFile/MediaFile.js +39 -0
- package/dist/node/components/MediaFile/index.d.ts +1 -0
- package/dist/node/components/MediaFile/index.js +5 -0
- package/dist/node/components/Metafield/Metafield.client.d.ts +21 -0
- package/dist/node/components/Metafield/Metafield.client.js +75 -0
- package/dist/node/components/Metafield/index.d.ts +2 -0
- package/dist/node/components/Metafield/index.js +5 -0
- package/dist/node/components/Metafield/types.d.ts +4 -0
- package/dist/node/components/Metafield/types.js +2 -0
- package/dist/node/components/ModelViewer/ModelViewer.client.d.ts +128 -0
- package/dist/node/components/ModelViewer/ModelViewer.client.js +132 -0
- package/dist/node/components/ModelViewer/index.d.ts +1 -0
- package/dist/node/components/ModelViewer/index.js +5 -0
- package/dist/node/components/Money/Money.client.d.ts +25 -0
- package/dist/node/components/Money/Money.client.js +46 -0
- package/dist/node/components/Money/index.d.ts +1 -0
- package/dist/node/components/Money/index.js +5 -0
- package/dist/node/components/ProductOptionsProvider/ProductOptionsProvider.client.d.ts +21 -0
- package/dist/node/components/ProductOptionsProvider/ProductOptionsProvider.client.js +167 -0
- package/dist/node/components/ProductOptionsProvider/context.d.ts +2 -0
- package/dist/node/components/ProductOptionsProvider/context.js +5 -0
- package/dist/node/components/ProductOptionsProvider/index.d.ts +2 -0
- package/dist/node/components/ProductOptionsProvider/index.js +7 -0
- package/dist/node/components/ProductPrice/ProductPrice.client.d.ts +18 -0
- package/dist/node/components/ProductPrice/ProductPrice.client.js +61 -0
- package/dist/node/components/ProductPrice/index.d.ts +1 -0
- package/dist/node/components/ProductPrice/index.js +5 -0
- package/dist/node/components/Seo/CollectionSeo.client.d.ts +3 -0
- package/dist/node/components/Seo/CollectionSeo.client.js +22 -0
- package/dist/node/components/Seo/DefaultPageSeo.client.d.ts +3 -0
- package/dist/node/components/Seo/DefaultPageSeo.client.js +25 -0
- package/dist/node/components/Seo/DescriptionSeo.client.d.ts +4 -0
- package/dist/node/components/Seo/DescriptionSeo.client.js +17 -0
- package/dist/node/components/Seo/HomePageSeo.client.d.ts +2 -0
- package/dist/node/components/Seo/HomePageSeo.client.js +32 -0
- package/dist/node/components/Seo/ImageSeo.client.d.ts +3 -0
- package/dist/node/components/Seo/ImageSeo.client.js +17 -0
- package/dist/node/components/Seo/NoIndexSeo.client.d.ts +3 -0
- package/dist/node/components/Seo/NoIndexSeo.client.js +17 -0
- package/dist/node/components/Seo/PageSeo.client.d.ts +3 -0
- package/dist/node/components/Seo/PageSeo.client.js +20 -0
- package/dist/node/components/Seo/ProductSeo.client.d.ts +5 -0
- package/dist/node/components/Seo/ProductSeo.client.js +70 -0
- package/dist/node/components/Seo/Seo.client.d.ts +30 -0
- package/dist/node/components/Seo/Seo.client.js +38 -0
- package/dist/node/components/Seo/TitleSeo.client.d.ts +3 -0
- package/dist/node/components/Seo/TitleSeo.client.js +17 -0
- package/dist/node/components/Seo/TwitterSeo.client.d.ts +2 -0
- package/dist/node/components/Seo/TwitterSeo.client.js +16 -0
- package/dist/node/components/Seo/index.d.ts +1 -0
- package/dist/node/components/Seo/index.js +5 -0
- package/dist/node/components/Seo/seo-types.d.ts +17 -0
- package/dist/node/components/Seo/seo-types.js +2 -0
- package/dist/node/components/ShopPayButton/ShopPayButton.client.d.ts +38 -0
- package/dist/node/components/ShopPayButton/ShopPayButton.client.js +60 -0
- package/dist/node/components/ShopPayButton/index.d.ts +1 -0
- package/dist/node/components/ShopPayButton/index.js +5 -0
- package/dist/node/components/Video/Video.d.ts +14 -0
- package/dist/node/components/Video/Video.js +31 -0
- package/dist/node/components/Video/index.d.ts +1 -0
- package/dist/node/components/Video/index.js +5 -0
- package/dist/node/components/index.d.ts +28 -0
- package/dist/node/components/index.js +59 -0
- package/dist/node/components/types.d.ts +71 -0
- package/dist/node/components/types.js +11 -0
- package/dist/node/entry-server.d.ts +2 -15
- package/dist/node/entry-server.js +244 -320
- package/dist/node/foundation/Analytics/Analytics.client.js +15 -13
- package/dist/node/foundation/Analytics/Analytics.server.js +27 -20
- package/dist/node/foundation/Analytics/ClientAnalytics.d.ts +4 -2
- package/dist/node/foundation/Analytics/ClientAnalytics.js +14 -12
- package/dist/node/foundation/Analytics/ServerAnalyticsRoute.server.js +7 -5
- package/dist/node/foundation/Analytics/connectors/PerformanceMetrics/PerformanceMetrics.client.d.ts +7 -0
- package/dist/node/foundation/Analytics/connectors/PerformanceMetrics/PerformanceMetrics.client.js +68 -0
- package/dist/node/foundation/Analytics/connectors/PerformanceMetrics/PerformanceMetricsDebug.client.d.ts +1 -0
- package/dist/node/foundation/Analytics/connectors/PerformanceMetrics/PerformanceMetricsDebug.client.js +27 -0
- package/dist/node/foundation/Analytics/hook.js +4 -2
- package/dist/node/foundation/Analytics/index.d.ts +1 -0
- package/dist/node/foundation/Analytics/index.js +5 -0
- package/dist/node/foundation/Analytics/utils.d.ts +2 -0
- package/dist/node/foundation/Analytics/utils.js +24 -1
- package/dist/{esnext/framework → node/foundation/Cache}/cache-sub-request.d.ts +1 -1
- package/dist/node/{framework → foundation/Cache}/cache-sub-request.js +4 -4
- package/dist/node/{framework → foundation/Cache}/cache.d.ts +1 -1
- package/dist/node/{framework → foundation/Cache}/cache.js +5 -5
- package/dist/{esnext/framework/CachingStrategy → node/foundation/Cache/strategies}/index.d.ts +1 -1
- package/dist/node/{framework/CachingStrategy → foundation/Cache/strategies}/index.js +0 -0
- package/dist/node/foundation/Head/Head.client.d.ts +5 -0
- package/dist/node/foundation/Head/Head.client.js +17 -0
- package/dist/node/foundation/Head/index.d.ts +1 -0
- package/dist/node/foundation/Head/index.js +5 -0
- package/dist/{esnext/framework/Hydration → node/foundation/Html}/Html.d.ts +3 -1
- package/dist/node/{framework/Hydration → foundation/Html}/Html.js +15 -2
- package/dist/{esnext/framework/Hydration/ServerComponentRequest.server.d.ts → node/foundation/HydrogenRequest/HydrogenRequest.server.d.ts} +7 -3
- package/dist/node/{framework/Hydration/ServerComponentRequest.server.js → foundation/HydrogenRequest/HydrogenRequest.server.js} +3 -3
- package/dist/{esnext/framework/Hydration/ServerComponentResponse.server.d.ts → node/foundation/HydrogenResponse/HydrogenResponse.server.d.ts} +7 -10
- package/dist/node/{framework/Hydration/ServerComponentResponse.server.js → foundation/HydrogenResponse/HydrogenResponse.server.js} +23 -19
- package/dist/node/foundation/Router/BrowserRouter.client.js +16 -9
- package/dist/node/foundation/ServerPropsProvider/ServerPropsProvider.d.ts +2 -1
- package/dist/node/foundation/ServerPropsProvider/ServerPropsProvider.js +1 -1
- package/dist/node/foundation/ServerRequestProvider/ServerRequestProvider.d.ts +4 -4
- package/dist/node/foundation/ServerRequestProvider/ServerRequestProvider.js +2 -2
- package/dist/node/foundation/ShopifyProvider/ShopifyProvider.client.d.ts +7 -0
- package/dist/node/foundation/ShopifyProvider/ShopifyProvider.client.js +35 -0
- package/dist/node/foundation/ShopifyProvider/index.d.ts +1 -0
- package/dist/node/foundation/ShopifyProvider/index.js +5 -0
- package/dist/node/foundation/fetchSync/client/fetchSync.d.ts +10 -0
- package/dist/node/foundation/fetchSync/client/fetchSync.js +33 -0
- package/dist/node/foundation/fetchSync/server/fetchSync.d.ts +8 -0
- package/dist/node/foundation/fetchSync/server/fetchSync.js +33 -0
- package/dist/node/foundation/fetchSync/types.d.ts +5 -0
- package/dist/node/foundation/fetchSync/types.js +2 -0
- package/dist/node/foundation/index.d.ts +3 -0
- package/dist/node/foundation/index.js +10 -0
- package/dist/node/foundation/runtime.d.ts +2 -0
- package/dist/node/foundation/runtime.js +11 -0
- package/dist/node/foundation/session/session.d.ts +3 -3
- package/dist/node/foundation/ssr-interop.d.ts +2 -2
- package/dist/node/foundation/useNavigate/useNavigate.d.ts +2 -0
- package/dist/node/foundation/useNavigate/useNavigate.js +11 -4
- package/dist/node/foundation/useQuery/hooks.d.ts +36 -0
- package/dist/node/foundation/useQuery/hooks.js +104 -0
- package/dist/node/foundation/useRouteParams/RouteParamsProvider.client.d.ts +10 -0
- package/dist/node/foundation/useRouteParams/RouteParamsProvider.client.js +34 -0
- package/dist/node/foundation/useRouteParams/useRouteParams.d.ts +4 -0
- package/dist/node/foundation/useRouteParams/useRouteParams.js +13 -0
- package/dist/node/foundation/useServerProps/index.d.ts +1 -0
- package/dist/node/foundation/useServerProps/index.js +5 -0
- package/dist/node/foundation/useSession/useSession.d.ts +2 -0
- package/dist/node/foundation/useSession/useSession.js +12 -0
- package/dist/node/foundation/useShop/index.d.ts +1 -0
- package/dist/node/foundation/useShop/index.js +5 -0
- package/dist/node/foundation/useShop/use-shop.d.ts +6 -0
- package/dist/node/foundation/useShop/use-shop.js +18 -0
- package/dist/node/foundation/useUrl/index.d.ts +1 -0
- package/dist/node/foundation/useUrl/index.js +5 -0
- package/dist/node/foundation/useUrl/useUrl.d.ts +4 -0
- package/dist/node/foundation/useUrl/useUrl.js +32 -0
- package/dist/node/framework/Hydration/rsc.js +2 -0
- package/dist/node/framework/plugin.js +2 -0
- package/dist/node/framework/plugins/vite-plugin-hydrogen-config.js +5 -2
- package/dist/node/framework/plugins/vite-plugin-hydrogen-middleware.js +1 -1
- package/dist/node/framework/plugins/vite-plugin-hydrogen-rsc.js +4 -12
- package/dist/node/framework/plugins/vite-plugin-hydrogen-suppress-warnings.d.ts +3 -0
- package/dist/node/framework/plugins/vite-plugin-hydrogen-suppress-warnings.js +21 -0
- package/dist/node/hooks/index.d.ts +6 -0
- package/dist/node/hooks/index.js +28 -0
- package/dist/node/hooks/useCart/index.d.ts +1 -0
- package/dist/node/hooks/useCart/index.js +5 -0
- package/dist/node/hooks/useCart/useCart.d.ts +4 -0
- package/dist/node/hooks/useCart/useCart.js +19 -0
- package/dist/node/hooks/useCartLine/index.d.ts +1 -0
- package/dist/node/hooks/useCartLine/index.js +5 -0
- package/dist/node/hooks/useCartLine/useCartLine.d.ts +29 -0
- package/dist/node/hooks/useCartLine/useCartLine.js +16 -0
- package/dist/node/hooks/useCountry/index.d.ts +1 -0
- package/dist/node/hooks/useCountry/index.js +5 -0
- package/dist/node/hooks/useCountry/useCountry.d.ts +7 -0
- package/dist/node/hooks/useCountry/useCountry.js +21 -0
- package/dist/node/hooks/useLoadScript/index.d.ts +1 -0
- package/dist/node/hooks/useLoadScript/index.js +5 -0
- package/dist/node/hooks/useLoadScript/useLoadScript.client.d.ts +8 -0
- package/dist/node/hooks/useLoadScript/useLoadScript.client.js +27 -0
- package/dist/node/hooks/useMeasurement/hooks.d.ts +9 -0
- package/dist/node/hooks/useMeasurement/hooks.js +17 -0
- package/dist/node/hooks/useMeasurement/index.d.ts +1 -0
- package/dist/node/hooks/useMeasurement/index.js +5 -0
- package/dist/node/hooks/useMoney/hooks.d.ts +54 -0
- package/dist/node/hooks/useMoney/hooks.js +70 -0
- package/dist/node/hooks/useMoney/index.d.ts +1 -0
- package/dist/node/hooks/useMoney/index.js +5 -0
- package/dist/node/hooks/useParsedMetafields/index.d.ts +1 -0
- package/dist/node/hooks/useParsedMetafields/index.js +5 -0
- package/dist/node/hooks/useParsedMetafields/useParsedMetafields.d.ts +21 -0
- package/dist/node/hooks/useParsedMetafields/useParsedMetafields.js +25 -0
- package/dist/node/hooks/useProductOptions/helpers.d.ts +6 -0
- package/dist/node/hooks/useProductOptions/helpers.js +46 -0
- package/dist/node/hooks/useProductOptions/index.d.ts +2 -0
- package/dist/node/hooks/useProductOptions/index.js +20 -0
- package/dist/node/hooks/useProductOptions/types.d.ts +44 -0
- package/dist/node/hooks/useProductOptions/types.js +2 -0
- package/dist/node/hooks/useProductOptions/useProductOptions.client.d.ts +1 -0
- package/dist/node/hooks/useProductOptions/useProductOptions.client.js +13 -0
- package/dist/node/hooks/useShopQuery/hooks.d.ts +28 -0
- package/dist/node/hooks/useShopQuery/hooks.js +171 -0
- package/dist/node/hooks/useShopQuery/index.d.ts +1 -0
- package/dist/node/hooks/useShopQuery/index.js +5 -0
- package/dist/node/streaming.server.d.ts +0 -1
- package/dist/node/streaming.server.js +1 -6
- package/dist/node/types.d.ts +32 -23
- package/dist/node/utilities/apiRoutes.d.ts +2 -2
- package/dist/node/utilities/devtools.d.ts +11 -0
- package/dist/node/utilities/devtools.js +15 -0
- package/dist/node/utilities/graphql-tag.d.ts +1 -0
- package/dist/node/utilities/graphql-tag.js +10 -0
- package/dist/node/utilities/graphql-tracker.d.ts +17 -0
- package/dist/node/utilities/graphql-tracker.js +130 -0
- package/dist/node/utilities/index.d.ts +1 -1
- package/dist/node/utilities/index.js +3 -3
- package/dist/node/utilities/isBrowser/index.d.ts +1 -0
- package/dist/node/utilities/isBrowser/index.js +5 -0
- package/dist/node/utilities/isBrowser/isBrowser.d.ts +4 -0
- package/dist/node/utilities/isBrowser/isBrowser.js +10 -0
- package/dist/node/utilities/isServer/isServer.js +2 -2
- package/dist/node/utilities/log/index.d.ts +1 -1
- package/dist/node/utilities/log/index.js +1 -3
- package/dist/node/utilities/log/log-cache-header.d.ts +4 -4
- package/dist/node/utilities/log/log-query-timeline.d.ts +3 -3
- package/dist/node/utilities/log/log.d.ts +17 -11
- package/dist/node/utilities/log/log.js +30 -23
- package/dist/node/version.d.ts +1 -1
- package/dist/node/version.js +1 -1
- package/package.json +3 -1
- package/vendor/react-server-dom-vite/cjs/react-server-dom-vite-plugin.js +203 -52
- package/vendor/react-server-dom-vite/cjs/react-server-dom-vite-writer.browser.development.server.js +77 -59
- package/vendor/react-server-dom-vite/cjs/react-server-dom-vite-writer.browser.production.min.server.js +30 -30
- package/vendor/react-server-dom-vite/cjs/react-server-dom-vite-writer.node.development.server.js +199 -70
- package/vendor/react-server-dom-vite/cjs/react-server-dom-vite-writer.node.production.min.server.js +38 -35
- package/vendor/react-server-dom-vite/cjs/react-server-dom-vite.development.js +9 -8
- package/vendor/react-server-dom-vite/cjs/react-server-dom-vite.production.min.js +3 -3
- package/vendor/react-server-dom-vite/esm/react-server-dom-vite-client-proxy.js +3 -7
- package/vendor/react-server-dom-vite/esm/react-server-dom-vite-plugin.js +204 -53
- package/vendor/react-server-dom-vite/esm/react-server-dom-vite-writer.browser.server.js +77 -59
- package/vendor/react-server-dom-vite/esm/react-server-dom-vite-writer.node.server.js +199 -70
- package/vendor/react-server-dom-vite/esm/react-server-dom-vite.js +9 -8
- package/vendor/react-server-dom-vite/package.json +1 -1
- package/dist/esnext/components/ProductProvider/ProductOptionsProvider.client.d.ts +0 -8
- package/dist/esnext/components/ProductProvider/ProductOptionsProvider.client.js +0 -12
- package/dist/esnext/components/ProductProvider/ProductProvider.client.d.ts +0 -24
- package/dist/esnext/components/ProductProvider/ProductProvider.client.js +0 -34
- package/dist/esnext/components/ProductProvider/context.d.ts +0 -29
- package/dist/esnext/components/ProductProvider/index.d.ts +0 -2
- package/dist/esnext/components/ProductProvider/index.js +0 -2
- package/dist/esnext/foundation/Analytics/connectors/PerformanceMetrics/PerformanceMetrics.server.d.ts +0 -1
- package/dist/esnext/framework/config.d.ts +0 -6
- package/dist/esnext/framework/config.js +0 -6
- package/dist/esnext/framework/runtime.d.ts +0 -13
- package/dist/esnext/framework/runtime.js +0 -27
- package/dist/esnext/hooks/useProduct/index.d.ts +0 -1
- package/dist/esnext/hooks/useProduct/index.js +0 -1
- package/dist/esnext/hooks/useProduct/useProduct.d.ts +0 -52
- package/dist/esnext/hooks/useProduct/useProduct.js +0 -43
- package/dist/esnext/utilities/isClient/index.d.ts +0 -1
- package/dist/esnext/utilities/isClient/index.js +0 -1
- package/dist/esnext/utilities/isClient/isClient.d.ts +0 -4
- package/dist/esnext/utilities/isClient/isClient.js +0 -6
- package/dist/node/framework/config.d.ts +0 -6
- package/dist/node/framework/config.js +0 -11
- package/dist/node/framework/runtime.d.ts +0 -13
- package/dist/node/framework/runtime.js +0 -35
- package/dist/node/utilities/defer.d.ts +0 -6
- package/dist/node/utilities/defer.js +0 -18
- package/dist/node/utilities/isClient/index.d.ts +0 -1
- package/dist/node/utilities/isClient/index.js +0 -5
- package/dist/node/utilities/isClient/isClient.d.ts +0 -4
- package/dist/node/utilities/isClient/isClient.js +0 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,212 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.23.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#1389](https://github.com/Shopify/hydrogen/pull/1389) [`9a21108f`](https://github.com/Shopify/hydrogen/commit/9a21108f6ff89474db9ff8bec26733fcbe744bdc) Thanks [@blittle](https://github.com/blittle)! - **Breaking change**
|
|
8
|
+
|
|
9
|
+
The utility `isClient` has been renamed to `isBrowser`. This is because the utility really checks if the running context is a browser, _not_ if the context is a client component.
|
|
10
|
+
|
|
11
|
+
All client components by default also run on the server when they are server rendered. If you don't want that to happen, use the `isBrowser()` hook. Remember that anything not server rendered will be unavailable for SEO bots.
|
|
12
|
+
|
|
13
|
+
* [#1431](https://github.com/Shopify/hydrogen/pull/1431) [`6975bdb9`](https://github.com/Shopify/hydrogen/commit/6975bdb90cfdc03562d21cec09150c52ff31ff78) Thanks [@jplhomer](https://github.com/jplhomer)! - Add `scroll` prop to `Link` and `navigate` to allow the scroll restoration behavior to be disabled.
|
|
14
|
+
|
|
15
|
+
By default, when a `<Link>` component is clicked, Hydrogen emulates default browser behavior and attempts to restore the scroll position previously used in the visitor's session. For new pages, this defaults to scrolling to the top of the page.
|
|
16
|
+
|
|
17
|
+
However, if you are building a user interface that should fetch a new server components request and update the URL but not modify scroll position, then you can disable scroll restoration using the `scroll` prop:
|
|
18
|
+
|
|
19
|
+
```jsx
|
|
20
|
+
import {Link} from '@shopify/hydrogen';
|
|
21
|
+
export default function Index({request}) {
|
|
22
|
+
const url = new URL(request.normalizedUrl);
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<>
|
|
26
|
+
<p>Current param is: {url.searchParams.get('param')}</p>
|
|
27
|
+
<Link to="/?param=foo" scroll={false}>
|
|
28
|
+
Update param to foo
|
|
29
|
+
</Link>
|
|
30
|
+
</>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
- [#1325](https://github.com/Shopify/hydrogen/pull/1325) [`572c18d1`](https://github.com/Shopify/hydrogen/commit/572c18d1893b212cfc3f1be3043a67dcca251629) Thanks [@wizardlyhel](https://github.com/wizardlyhel)! - - Fix clientAnalytics not waiting for all server analytics data before sending page view event
|
|
36
|
+
|
|
37
|
+
- Fix server analytics connector erroring out after more than 1 server analytics connectors are attached
|
|
38
|
+
- Shopify analytics components
|
|
39
|
+
|
|
40
|
+
# Updates to server analytics connectors
|
|
41
|
+
|
|
42
|
+
The server analytics connector interface has updated to
|
|
43
|
+
|
|
44
|
+
```jsx
|
|
45
|
+
export function request(
|
|
46
|
+
requestUrl: string,
|
|
47
|
+
requestHeader: Headers,
|
|
48
|
+
data?: any,
|
|
49
|
+
contentType?: string
|
|
50
|
+
): void {
|
|
51
|
+
// Do something with the analytic event.
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
# Introducing Shopify analytics
|
|
56
|
+
|
|
57
|
+
Optional analytics components that allows you to send ecommerce related analytics to
|
|
58
|
+
Shopify. Adding the Shopify analytics components will allow the Shopify admin - Analytics
|
|
59
|
+
dashboard to work.
|
|
60
|
+
|
|
61
|
+
For information, see [Shopify Analytics](https://shopify.dev/api/hydrogen/components/framework/shopifyanalytics)
|
|
62
|
+
|
|
63
|
+
* [#1334](https://github.com/Shopify/hydrogen/pull/1334) [`58e039d4`](https://github.com/Shopify/hydrogen/commit/58e039d45cf69b670628f9f7ea62cb7c2d8425d9) Thanks [@blittle](https://github.com/blittle)! - With the introduction of authenticated pages, we also now provide the ability to prevent pages from being indexed by bots. You can do so by passing `noindex` to the `Seo` component:
|
|
64
|
+
|
|
65
|
+
```jsx
|
|
66
|
+
<Seo type="noindex" data={{title: 'Login'}} />
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
- [#1397](https://github.com/Shopify/hydrogen/pull/1397) [`fbd185ab`](https://github.com/Shopify/hydrogen/commit/fbd185ab47e7335992b7844af0ef0b0aea6d70a5) Thanks [@frehner](https://github.com/frehner)! - ## `<ProductProvider/>` and `<ProductOptionsProvider/>`
|
|
70
|
+
|
|
71
|
+
- `<ProductProvider/>` has been removed
|
|
72
|
+
- `<ProductPrice/>` was the only component left that used it; now it requires a `data` prop that takes in the product object
|
|
73
|
+
- `<ProductOptionsProvider/>` now maintains and provides the state that `useProductOptions` used to keep track of by itself. This change enables you to use multiple `useProductOptions` hook calls and have them share the same state (such as selected variant, options, etc.)
|
|
74
|
+
|
|
75
|
+
* [#1403](https://github.com/Shopify/hydrogen/pull/1403) [`979f8177`](https://github.com/Shopify/hydrogen/commit/979f81775a4bfa83276030da07cb012e6cb08e2f) Thanks [@frandiox](https://github.com/frandiox)! - **Breaking change**: The `setLogger` and `setLoggerOptions` utilities have been removed. The same information can now be passed under the `logger` property in Hydrogen config:
|
|
76
|
+
|
|
77
|
+
```diff
|
|
78
|
+
// App.server.jsx
|
|
79
|
+
|
|
80
|
+
-import {setLogger, setLoggerOptions} from '@shopify/hydrogen';
|
|
81
|
+
|
|
82
|
+
-setLogger({
|
|
83
|
+
- trace() {},
|
|
84
|
+
- error() {},
|
|
85
|
+
- // ...
|
|
86
|
+
-});
|
|
87
|
+
|
|
88
|
+
-setLoggerOptions({
|
|
89
|
+
- showQueryTiming: true,
|
|
90
|
+
- showCacheControlHeader: true,
|
|
91
|
+
- // ...
|
|
92
|
+
-});
|
|
93
|
+
|
|
94
|
+
function App() {
|
|
95
|
+
// ...
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export default renderHydrogen(App);
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
```diff
|
|
102
|
+
// hydrogen.config.js
|
|
103
|
+
|
|
104
|
+
export default defineConfig({
|
|
105
|
+
// ...
|
|
106
|
+
+ logger: {
|
|
107
|
+
+ trace() {},
|
|
108
|
+
+ error() {},
|
|
109
|
+
+ showQueryTiming: true,
|
|
110
|
+
+ showCacheControlHeader: true,
|
|
111
|
+
+ // ...
|
|
112
|
+
+ },
|
|
113
|
+
});
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
- [#1433](https://github.com/Shopify/hydrogen/pull/1433) [`cd354d3a`](https://github.com/Shopify/hydrogen/commit/cd354d3a6205b5a8ef14426040121ac620c8c158) Thanks [@frandiox](https://github.com/frandiox)! - The `response.writeHead` method has been removed, while `response.status` and `response.statusText` are now writable.
|
|
117
|
+
|
|
118
|
+
```diff
|
|
119
|
+
function App({response}) {
|
|
120
|
+
- response.writeHead({
|
|
121
|
+
- headers: {'custom-header': 'value'},
|
|
122
|
+
- status: 404,
|
|
123
|
+
- });
|
|
124
|
+
+ response.headers.set('custom-header', 'value');
|
|
125
|
+
+ response.status = 404;
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
* [#1418](https://github.com/Shopify/hydrogen/pull/1418) [`512cb009`](https://github.com/Shopify/hydrogen/commit/512cb009fadeb1907fafa2cef8b568081799335f) Thanks [@frandiox](https://github.com/frandiox)! - **Breaking change**: The client configuration, including the `strictMode` option, has been moved from custom client entry handlers to the Hydrogen configuration file. If you had a custom client entry file just to pass client options, you can remove it and do the same in `hydrogen.config.js`:
|
|
130
|
+
|
|
131
|
+
```diff
|
|
132
|
+
// Custom client entry handler
|
|
133
|
+
|
|
134
|
+
-renderHydrogen(ClientWrapper, {strictMode: false});
|
|
135
|
+
+renderHydrogen(ClientWrapper);
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
```diff
|
|
139
|
+
// hydrogen.config.jsx
|
|
140
|
+
|
|
141
|
+
export default defineConfig({
|
|
142
|
+
+ strictMode: false,
|
|
143
|
+
});
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
To remove a custom client entry handler in case it's not needed anymore, delete the custom file and change `index.html`:
|
|
147
|
+
|
|
148
|
+
```diff
|
|
149
|
+
<body>
|
|
150
|
+
<div id="root"></div>
|
|
151
|
+
- <script type="module" src="/src/custom-client-entry"></script>
|
|
152
|
+
+ <script type="module" src="/@shopify/hydrogen/entry-client"></script>
|
|
153
|
+
</body>
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
- [#1401](https://github.com/Shopify/hydrogen/pull/1401) [`335b70ce`](https://github.com/Shopify/hydrogen/commit/335b70ce67f9f137875fcd18f32e00c1b1b4c533) Thanks [@frandiox](https://github.com/frandiox)! - **Breaking change**: The `enableStreaming` config option has been deprecated. The same feature can be done directly in the app:
|
|
157
|
+
|
|
158
|
+
```diff
|
|
159
|
+
// hydrogen.config.js
|
|
160
|
+
|
|
161
|
+
export default defineConfig({
|
|
162
|
+
shopify: {
|
|
163
|
+
// ...
|
|
164
|
+
},
|
|
165
|
+
- enableStreaming: (req) => {
|
|
166
|
+
- return req.headers.get('user-agent') !== 'custom bot';
|
|
167
|
+
- },
|
|
168
|
+
});
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
```diff
|
|
172
|
+
// App.server.jsx
|
|
173
|
+
|
|
174
|
+
-function App() {
|
|
175
|
+
+function App({request, response}) {
|
|
176
|
+
+ if (request.headers.get('user-agent') === 'custom bot') {
|
|
177
|
+
+ response.doNotStream();
|
|
178
|
+
+ }
|
|
179
|
+
|
|
180
|
+
return <Suspense fallback={'Loading...'}>{/*...*/}</Suspense>;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export default renderHydrogen(App);
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Patch Changes
|
|
187
|
+
|
|
188
|
+
- [#1425](https://github.com/Shopify/hydrogen/pull/1425) [`e213aa86`](https://github.com/Shopify/hydrogen/commit/e213aa8656b17bf649fef714befa99b9618aae45) Thanks [@frandiox](https://github.com/frandiox)! - Rename internal Hydrogen global variables that could conflict with third party libraries that use the same names.
|
|
189
|
+
|
|
190
|
+
* [#1361](https://github.com/Shopify/hydrogen/pull/1361) [`cf2ef664`](https://github.com/Shopify/hydrogen/commit/cf2ef664cd1e91bc53fc34698ac23797c398e74f) Thanks [@frandiox](https://github.com/frandiox)! - Improve component bundling to reduce the total amount of JS files downloaded in the browser.
|
|
191
|
+
|
|
192
|
+
- [#1452](https://github.com/Shopify/hydrogen/pull/1452) [`ed1586a7`](https://github.com/Shopify/hydrogen/commit/ed1586a758fd36bddcc422a75db8a7971ce946d5) Thanks [@frandiox](https://github.com/frandiox)! - Reduce CPU consumption when rendering React Server Components.
|
|
193
|
+
|
|
194
|
+
* [#1399](https://github.com/Shopify/hydrogen/pull/1399) [`583ce40c`](https://github.com/Shopify/hydrogen/commit/583ce40c97391bb22e6e15e736e6237e9a1ea085) Thanks [@frandiox](https://github.com/frandiox)! - Confusing warnings that are not actionable have been removed.
|
|
195
|
+
|
|
196
|
+
- [#1460](https://github.com/Shopify/hydrogen/pull/1460) [`18056879`](https://github.com/Shopify/hydrogen/commit/18056879f1ea1dc54f146184bfdd4f01f24df636) Thanks [@wizardlyhel](https://github.com/wizardlyhel)! - Fix doc links
|
|
197
|
+
|
|
198
|
+
* [#1444](https://github.com/Shopify/hydrogen/pull/1444) [`0b4ee487`](https://github.com/Shopify/hydrogen/commit/0b4ee4876998923f206f6d28b1a3ef95c9616e59) Thanks [@blittle](https://github.com/blittle)! - Propagate a better error message when the response from the storefront API is not JSON parseable
|
|
199
|
+
|
|
200
|
+
- [#1227](https://github.com/Shopify/hydrogen/pull/1227) [`8eae0a07`](https://github.com/Shopify/hydrogen/commit/8eae0a07ab02e61ac8742e42488825090ca0aa37) Thanks [@jplhomer](https://github.com/jplhomer)! - Enable streaming by default for all platforms
|
|
201
|
+
|
|
202
|
+
* [#1427](https://github.com/Shopify/hydrogen/pull/1427) [`7115d7d8`](https://github.com/Shopify/hydrogen/commit/7115d7d8dc291b7e5b4dda200baf8a906a005cc8) Thanks [@jplhomer](https://github.com/jplhomer)! - Properly support Node v18
|
|
203
|
+
|
|
204
|
+
- [#1424](https://github.com/Shopify/hydrogen/pull/1424) [`446c12bf`](https://github.com/Shopify/hydrogen/commit/446c12bffa08eadccfd27afe8b5f34c77a61d134) Thanks [@frandiox](https://github.com/frandiox)! - Custom loggers can return promises from their methods. Hydrogen will await for them after the current request is over but before the runtime instance ends.
|
|
205
|
+
|
|
206
|
+
* [#1423](https://github.com/Shopify/hydrogen/pull/1423) [`aaf9efa4`](https://github.com/Shopify/hydrogen/commit/aaf9efa45dc9453e95be8e3020c259368ac5f4d0) Thanks [@frandiox](https://github.com/frandiox)! - Workers context (e.g. `waitUntil`) is now scoped to the current request instead of globally available.
|
|
207
|
+
|
|
208
|
+
- [#1330](https://github.com/Shopify/hydrogen/pull/1330) [`c7dc6440`](https://github.com/Shopify/hydrogen/commit/c7dc644059206e7080c33d9f7e0096c168ae593e) Thanks [@ejfranco06](https://github.com/ejfranco06)! - [#1245] - Generate a default srcset for an image returned by the Shopify CDN on the Image component and allow using a custom set of `widths.`
|
|
209
|
+
|
|
3
210
|
## 0.22.1
|
|
4
211
|
|
|
5
212
|
### Patch Changes
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import React, { useEffect, useState } from 'react';
|
|
2
2
|
import { useCart } from '../CartProvider';
|
|
3
|
-
import {
|
|
3
|
+
import { useProductOptions } from '../ProductOptionsProvider';
|
|
4
4
|
/**
|
|
5
5
|
* The `AddToCartButton` component renders a button that adds an item to the cart when pressed.
|
|
6
6
|
* It must be a descendent of the `CartProvider` component.
|
|
7
7
|
*/
|
|
8
8
|
export function AddToCartButton(props) {
|
|
9
|
-
var _a
|
|
9
|
+
var _a;
|
|
10
10
|
const [addingItem, setAddingItem] = useState(false);
|
|
11
11
|
const { variantId: explicitVariantId, quantity = 1, attributes, children, accessibleAddingToCartLabel, ...passthroughProps } = props;
|
|
12
12
|
const { status, linesAdd } = useCart();
|
|
13
|
-
const
|
|
14
|
-
const variantId = (
|
|
13
|
+
const { selectedVariant } = useProductOptions();
|
|
14
|
+
const variantId = (_a = explicitVariantId !== null && explicitVariantId !== void 0 ? explicitVariantId : selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.id) !== null && _a !== void 0 ? _a : '';
|
|
15
15
|
const disabled = explicitVariantId === null ||
|
|
16
16
|
variantId === '' ||
|
|
17
|
-
|
|
17
|
+
selectedVariant === null ||
|
|
18
18
|
addingItem ||
|
|
19
19
|
passthroughProps.disabled;
|
|
20
20
|
useEffect(() => {
|
|
File without changes
|
|
File without changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { CartLines } from './CartLines';
|
|
1
|
+
export { CartLines } from './CartLines.client';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { CartLines } from './CartLines';
|
|
1
|
+
export { CartLines } from './CartLines.client';
|
|
@@ -55,7 +55,7 @@ export default function DevTools() {
|
|
|
55
55
|
React.createElement("path", { d: "M64.9548 106.281L27.1377 86.1894L40.0714 79.3723L54.6329 87.1049L66.851 80.6638L52.2895 72.9313L65.2231 66.0979L103.04 86.1894L90.1065 93.0064L76.35 85.6989L64.114 92.1563L77.8884 99.4638L64.9548 106.281Z", fill: "white" }),
|
|
56
56
|
React.createElement("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M65.2247 25L105.178 46.2267L90.105 54.1716L76.3488 46.8642L66.2525 52.1924L80.028 59.5005L64.9532 67.446L25 46.2196L40.0734 38.2748L54.6349 46.0073L64.713 40.6944L50.1533 32.9628L65.2247 25ZM54.4262 32.9673L68.9896 40.7008L54.6315 48.27L40.0699 40.5374L29.276 46.2267L64.9569 65.1833L75.7495 59.4947L61.9761 52.1878L76.3518 44.6012L90.1087 51.9088L100.902 46.2196L65.2221 27.2634L54.4262 32.9673Z", fill: "white" })));
|
|
57
57
|
if (import.meta.env.DEV && hasMounted) {
|
|
58
|
-
return (React.createElement("div", { style: {
|
|
58
|
+
return (React.createElement("div", { id: "hydrogen-dev-tools", style: {
|
|
59
59
|
position: 'fixed',
|
|
60
60
|
right: open ? 0 : '2em',
|
|
61
61
|
left: open ? 0 : '2em',
|
|
@@ -37,6 +37,10 @@ export declare type ShopifyImageProps = Omit<HtmlImageProps, 'src'> & {
|
|
|
37
37
|
* 'src' shouldn't be passed when 'data' is used.
|
|
38
38
|
*/
|
|
39
39
|
src?: never;
|
|
40
|
+
/**
|
|
41
|
+
* An array of pixel widths to overwrite the default generated srcset. For example, `[300, 600, 800]`.
|
|
42
|
+
*/
|
|
43
|
+
widths?: (HtmlImageProps['width'] | ImageType['width'])[];
|
|
40
44
|
};
|
|
41
45
|
declare type LoaderProps<GenericLoaderOpts> = {
|
|
42
46
|
/** A URL string. This string can be an absolute path or a relative path depending
|
|
@@ -80,5 +84,9 @@ declare type ExternalImageProps<GenericLoaderOpts> = SetRequired<HtmlImageProps,
|
|
|
80
84
|
* 'data' shouldn't be passed when 'src' is used.
|
|
81
85
|
*/
|
|
82
86
|
data?: never;
|
|
87
|
+
/**
|
|
88
|
+
* An array of pixel widths to generate a srcset. For example, `[300, 600, 800]`.
|
|
89
|
+
*/
|
|
90
|
+
widths?: HtmlImageProps['width'][];
|
|
83
91
|
};
|
|
84
92
|
export {};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { getShopifyImageDimensions, shopifyImageLoader } from '../../utilities';
|
|
2
|
+
import { getShopifyImageDimensions, shopifyImageLoader, addImageSizeParametersToUrl, } from '../../utilities';
|
|
3
3
|
export function Image(props) {
|
|
4
4
|
if (!props.data && !props.src) {
|
|
5
5
|
throw new Error(`<Image/>: requires either a 'data' or 'src' prop.`);
|
|
6
6
|
}
|
|
7
|
-
if (
|
|
7
|
+
if (__HYDROGEN_DEV__ && props.data && props.src) {
|
|
8
8
|
console.warn(`<Image/>: using both 'data' and 'src' props is not supported; using the 'data' prop by default`);
|
|
9
9
|
}
|
|
10
10
|
if (props.data) {
|
|
@@ -14,16 +14,16 @@ export function Image(props) {
|
|
|
14
14
|
return React.createElement(ExternalImage, { ...props });
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
function ShopifyImage({ data, width, height, loading, loader = shopifyImageLoader, loaderOptions, ...rest }) {
|
|
18
|
-
var _a, _b, _c, _d, _e, _f;
|
|
17
|
+
function ShopifyImage({ data, width, height, loading, loader = shopifyImageLoader, loaderOptions, widths, ...rest }) {
|
|
18
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
19
19
|
if (!data.url) {
|
|
20
20
|
throw new Error(`<Image/>: the 'data' prop requires the 'url' property`);
|
|
21
21
|
}
|
|
22
|
-
if (
|
|
22
|
+
if (__HYDROGEN_DEV__ && !data.altText && !rest.alt) {
|
|
23
23
|
console.warn(`<Image/>: the 'data' prop should have the 'altText' property, or the 'alt' prop, and one of them should not be empty. ${`Image: ${(_a = data.id) !== null && _a !== void 0 ? _a : data.url}`}`);
|
|
24
24
|
}
|
|
25
25
|
const { width: finalWidth, height: finalHeight } = getShopifyImageDimensions(data, loaderOptions);
|
|
26
|
-
if ((
|
|
26
|
+
if ((__HYDROGEN_DEV__ && !finalWidth) || !finalHeight) {
|
|
27
27
|
console.warn(`<Image/>: the 'data' prop requires either 'width' or 'data.width', and 'height' or 'data.height' properties. ${`Image: ${(_b = data.id) !== null && _b !== void 0 ? _b : data.url}`}`);
|
|
28
28
|
}
|
|
29
29
|
let finalSrc = data.url;
|
|
@@ -38,17 +38,32 @@ function ShopifyImage({ data, width, height, loading, loader = shopifyImageLoade
|
|
|
38
38
|
throw new Error(`<Image/>: 'loader' did not return a valid string. ${`Image: ${(_c = data.id) !== null && _c !== void 0 ? _c : data.url}`}`);
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
+
// determining what the intended width of the image is. For example, if the width is specified and lower than the image width, then that is the maximum image width
|
|
42
|
+
// to prevent generating a srcset with widths bigger than needed or to generate images that would distort because of being larger than original
|
|
43
|
+
const maxWidth = width && finalWidth && width < finalWidth ? width : finalWidth;
|
|
44
|
+
const finalSrcset = (_d = rest.srcSet) !== null && _d !== void 0 ? _d : internalImageSrcSet({
|
|
45
|
+
...loaderOptions,
|
|
46
|
+
widths,
|
|
47
|
+
src: data.url,
|
|
48
|
+
width: maxWidth,
|
|
49
|
+
loader,
|
|
50
|
+
});
|
|
41
51
|
/* eslint-disable hydrogen/prefer-image-component */
|
|
42
|
-
return (React.createElement("img", { id: (
|
|
52
|
+
return (React.createElement("img", { id: (_e = data.id) !== null && _e !== void 0 ? _e : '', alt: (_g = (_f = data.altText) !== null && _f !== void 0 ? _f : rest.alt) !== null && _g !== void 0 ? _g : '', loading: loading !== null && loading !== void 0 ? loading : 'lazy', ...rest, src: finalSrc, width: finalWidth !== null && finalWidth !== void 0 ? finalWidth : undefined, height: finalHeight !== null && finalHeight !== void 0 ? finalHeight : undefined, srcSet: finalSrcset }));
|
|
43
53
|
/* eslint-enable hydrogen/prefer-image-component */
|
|
44
54
|
}
|
|
45
|
-
function ExternalImage({ src, width, height, alt, loader, loaderOptions, loading, ...rest }) {
|
|
55
|
+
function ExternalImage({ src, width, height, alt, loader, loaderOptions, widths, loading, ...rest }) {
|
|
56
|
+
var _a, _b;
|
|
46
57
|
if (!width || !height) {
|
|
47
58
|
throw new Error(`<Image/>: when 'src' is provided, 'width' and 'height' are required and need to be valid values (i.e. greater than zero). Provided values: 'src': ${src}, 'width': ${width}, 'height': ${height}`);
|
|
48
59
|
}
|
|
49
|
-
if (
|
|
60
|
+
if (__HYDROGEN_DEV__ && !alt) {
|
|
50
61
|
console.warn(`<Image/>: when 'src' is provided, 'alt' should also be provided. ${`Image: ${src}`}`);
|
|
51
62
|
}
|
|
63
|
+
if (widths &&
|
|
64
|
+
Array.isArray(widths) &&
|
|
65
|
+
widths.some((size) => isNaN(size)))
|
|
66
|
+
throw new Error(`<Image/>: the 'widths' property must be an array of numbers`);
|
|
52
67
|
let finalSrc = src;
|
|
53
68
|
if (loader) {
|
|
54
69
|
finalSrc = loader({ src, width, height, ...loaderOptions });
|
|
@@ -56,7 +71,40 @@ function ExternalImage({ src, width, height, alt, loader, loaderOptions, loading
|
|
|
56
71
|
throw new Error(`<Image/>: 'loader' did not return a valid string`);
|
|
57
72
|
}
|
|
58
73
|
}
|
|
74
|
+
let finalSrcset = (_a = rest.srcSet) !== null && _a !== void 0 ? _a : undefined;
|
|
75
|
+
if (!finalSrcset && loader && widths) {
|
|
76
|
+
// Height is a requirement in the LoaderProps, so to keep the aspect ratio, we must determine the height based on the default values
|
|
77
|
+
const heightToWidthRatio = parseInt(height) / parseInt(width);
|
|
78
|
+
finalSrcset = (_b = widths === null || widths === void 0 ? void 0 : widths.map((width) => parseInt(width, 10))) === null || _b === void 0 ? void 0 : _b.map((width) => `${loader({
|
|
79
|
+
...loaderOptions,
|
|
80
|
+
src,
|
|
81
|
+
width,
|
|
82
|
+
height: Math.floor(width * heightToWidthRatio),
|
|
83
|
+
})} ${width}w`).join(', ');
|
|
84
|
+
}
|
|
59
85
|
/* eslint-disable hydrogen/prefer-image-component */
|
|
60
|
-
return (React.createElement("img", { ...rest, src: finalSrc, width: width, height: height, alt: alt !== null && alt !== void 0 ? alt : '', loading: loading !== null && loading !== void 0 ? loading : 'lazy' }));
|
|
86
|
+
return (React.createElement("img", { ...rest, src: finalSrc, width: width, height: height, alt: alt !== null && alt !== void 0 ? alt : '', loading: loading !== null && loading !== void 0 ? loading : 'lazy', srcSet: finalSrcset }));
|
|
61
87
|
/* eslint-enable hydrogen/prefer-image-component */
|
|
62
88
|
}
|
|
89
|
+
// based on the default width sizes used by the Shopify liquid HTML tag img_tag plus a 2560 width to account for 2k resolutions
|
|
90
|
+
// reference: https://shopify.dev/api/liquid/filters/html-filters#image_tag
|
|
91
|
+
const IMG_SRC_SET_SIZES = [352, 832, 1200, 1920, 2560];
|
|
92
|
+
function internalImageSrcSet({ src, width, crop, scale, widths, loader, }) {
|
|
93
|
+
const hasCustomWidths = widths && Array.isArray(widths);
|
|
94
|
+
if (hasCustomWidths && widths.some((size) => isNaN(size)))
|
|
95
|
+
throw new Error(`<Image/>: the 'widths' must be an array of numbers`);
|
|
96
|
+
let setSizes = hasCustomWidths ? widths : IMG_SRC_SET_SIZES;
|
|
97
|
+
if (!hasCustomWidths &&
|
|
98
|
+
width &&
|
|
99
|
+
width < IMG_SRC_SET_SIZES[IMG_SRC_SET_SIZES.length - 1])
|
|
100
|
+
setSizes = IMG_SRC_SET_SIZES.filter((size) => size <= width);
|
|
101
|
+
const srcGenerator = loader ? loader : addImageSizeParametersToUrl;
|
|
102
|
+
return setSizes
|
|
103
|
+
.map((size) => `${srcGenerator({
|
|
104
|
+
src,
|
|
105
|
+
width: size,
|
|
106
|
+
crop,
|
|
107
|
+
scale,
|
|
108
|
+
})} ${size}w`)
|
|
109
|
+
.join(', ');
|
|
110
|
+
}
|
|
@@ -10,6 +10,8 @@ export interface LinkProps extends Omit<React.AnchorHTMLAttributes<HTMLAnchorEle
|
|
|
10
10
|
reloadDocument?: boolean;
|
|
11
11
|
/** Whether to prefetch the link source when the user signals intent. Defaults to `true`. For more information, refer to [Prefetching a link source](https://shopify.dev/custom-storefronts/hydrogen/framework/routes#prefetching-a-link-source). */
|
|
12
12
|
prefetch?: boolean;
|
|
13
|
+
/** Whether to emulate natural browser behavior and restore scroll position on navigation. Defaults to `true`. */
|
|
14
|
+
scroll?: boolean;
|
|
13
15
|
}
|
|
14
16
|
/**
|
|
15
17
|
* The `Link` component is used to navigate between routes. Because it renders an underlying `<a>` element, all
|
|
@@ -18,7 +18,7 @@ export const Link = React.forwardRef(function Link(props, ref) {
|
|
|
18
18
|
*/
|
|
19
19
|
const [shouldPrefetch, setShouldPrefetch] = useState(false);
|
|
20
20
|
const [maybePrefetch, setMaybePrefetch] = useState(false);
|
|
21
|
-
const { reloadDocument, target, replace: _replace, to, onClick, clientState, prefetch = true, } = props;
|
|
21
|
+
const { reloadDocument, target, replace: _replace, to, onClick, clientState, prefetch = true, scroll = true, } = props;
|
|
22
22
|
const internalClick = useCallback((e) => {
|
|
23
23
|
if (onClick)
|
|
24
24
|
onClick(e);
|
|
@@ -32,18 +32,20 @@ export const Link = React.forwardRef(function Link(props, ref) {
|
|
|
32
32
|
const replace = !!_replace || createPath(location) === createPath({ pathname: to });
|
|
33
33
|
navigate(to, {
|
|
34
34
|
replace,
|
|
35
|
+
scroll,
|
|
35
36
|
clientState,
|
|
36
37
|
});
|
|
37
38
|
}
|
|
38
39
|
}, [
|
|
40
|
+
onClick,
|
|
39
41
|
reloadDocument,
|
|
40
42
|
target,
|
|
41
43
|
_replace,
|
|
42
|
-
to,
|
|
43
|
-
clientState,
|
|
44
|
-
onClick,
|
|
45
44
|
location,
|
|
45
|
+
to,
|
|
46
46
|
navigate,
|
|
47
|
+
clientState,
|
|
48
|
+
scroll,
|
|
47
49
|
]);
|
|
48
50
|
const signalPrefetchIntent = () => {
|
|
49
51
|
/**
|
|
@@ -91,6 +93,7 @@ export const Link = React.forwardRef(function Link(props, ref) {
|
|
|
91
93
|
'clientState',
|
|
92
94
|
'reloadDocument',
|
|
93
95
|
'prefetch',
|
|
96
|
+
'scroll',
|
|
94
97
|
]), ref: ref, onClick: internalClick, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, onFocus: onFocus, onBlur: onBlur, onTouchStart: onTouchStart, href: props.to }, props.children),
|
|
95
98
|
shouldPrefetch && React.createElement(Prefetch, { pathname: to })));
|
|
96
99
|
});
|
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import LocalizationClientProvider from './LocalizationClientProvider.client';
|
|
3
3
|
import { useShop } from '../../foundation/useShop';
|
|
4
4
|
import { useShopQuery } from '../../hooks/useShopQuery';
|
|
5
|
-
import { CacheDays } from '../../
|
|
5
|
+
import { CacheDays } from '../../foundation/Cache/strategies';
|
|
6
6
|
import { useSession } from '../../foundation/useSession/useSession';
|
|
7
7
|
/**
|
|
8
8
|
* The `LocalizationProvider` component automatically queries the Storefront API's
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { Product, ProductVariant as ProductVariantType } from '../../storefront-api-types';
|
|
3
|
+
import type { PartialDeep } from 'type-fest';
|
|
4
|
+
declare type InitialVariantId = ProductVariantType['id'] | null;
|
|
5
|
+
interface ProductOptionsProviderProps {
|
|
6
|
+
/** A [Product object](https://shopify.dev/api/storefront/reference/products/product). */
|
|
7
|
+
data: PartialDeep<Product>;
|
|
8
|
+
/** A `ReactNode` element. */
|
|
9
|
+
children: React.ReactNode;
|
|
10
|
+
/**
|
|
11
|
+
* The initially selected variant.
|
|
12
|
+
* The following logic applies to `initialVariantId`:
|
|
13
|
+
* 1. If `initialVariantId` is provided, then it's used even if it's out of stock.
|
|
14
|
+
* 2. If `initialVariantId` is provided but is `null`, then no variant is used.
|
|
15
|
+
* 3. If nothing is passed to `initialVariantId` then the first available / in-stock variant is used.
|
|
16
|
+
* 4. If nothing is passed to `initialVariantId` and no variants are in stock, then the first variant is used.
|
|
17
|
+
*/
|
|
18
|
+
initialVariantId?: InitialVariantId;
|
|
19
|
+
}
|
|
20
|
+
export declare function ProductOptionsProvider({ children, data: product, initialVariantId: explicitVariantId, }: ProductOptionsProviderProps): JSX.Element;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import React, { useMemo, useState, useEffect, useCallback } from 'react';
|
|
2
|
+
import { ProductOptionsContext } from './context';
|
|
3
|
+
import { getSelectedVariant, getOptions, } from '../../hooks/useProductOptions/helpers';
|
|
4
|
+
export function ProductOptionsProvider({ children, data: product, initialVariantId: explicitVariantId, }) {
|
|
5
|
+
var _a, _b;
|
|
6
|
+
// The flattened variants
|
|
7
|
+
const variants = useMemo(() => { var _a; return (_a = product.variants) === null || _a === void 0 ? void 0 : _a.nodes; }, [(_a = product.variants) === null || _a === void 0 ? void 0 : _a.nodes]);
|
|
8
|
+
if (!isProductVariantArray(variants)) {
|
|
9
|
+
throw new Error(`<ProductOptionsProvider/> requires product.variants.nodes`);
|
|
10
|
+
}
|
|
11
|
+
// All the options available for a product, based on all the variants
|
|
12
|
+
const options = useMemo(() => getOptions(variants), [variants]);
|
|
13
|
+
/**
|
|
14
|
+
* Track the selectedVariant within the provider.
|
|
15
|
+
*/
|
|
16
|
+
const [selectedVariant, setSelectedVariant] = useState(() => getVariantBasedOnIdProp(explicitVariantId, variants));
|
|
17
|
+
/**
|
|
18
|
+
* Track the selectedOptions within the provider. If a `initialVariantId`
|
|
19
|
+
* is passed, use that to select initial options.
|
|
20
|
+
*/
|
|
21
|
+
const [selectedOptions, setSelectedOptions] = useState(() => getSelectedOptions(selectedVariant));
|
|
22
|
+
/**
|
|
23
|
+
* When the initialVariantId changes, we need to make sure we
|
|
24
|
+
* update the selected variant and selected options. If not,
|
|
25
|
+
* then the selected variant and options will reference incorrect
|
|
26
|
+
* values.
|
|
27
|
+
*/
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
const newSelectedVariant = getVariantBasedOnIdProp(explicitVariantId, variants);
|
|
30
|
+
setSelectedVariant(newSelectedVariant);
|
|
31
|
+
setSelectedOptions(getSelectedOptions(newSelectedVariant));
|
|
32
|
+
}, [explicitVariantId, variants]);
|
|
33
|
+
/**
|
|
34
|
+
* Allow the developer to select an option.
|
|
35
|
+
*/
|
|
36
|
+
const setSelectedOption = useCallback((name, value) => {
|
|
37
|
+
setSelectedOptions((selectedOptions) => ({
|
|
38
|
+
...selectedOptions,
|
|
39
|
+
[name]: value,
|
|
40
|
+
}));
|
|
41
|
+
}, [setSelectedOptions]);
|
|
42
|
+
const isOptionInStock = useCallback((option, value) => {
|
|
43
|
+
var _a;
|
|
44
|
+
const proposedVariant = getSelectedVariant(variants, {
|
|
45
|
+
...selectedOptions,
|
|
46
|
+
...{ [option]: value },
|
|
47
|
+
});
|
|
48
|
+
return (_a = proposedVariant === null || proposedVariant === void 0 ? void 0 : proposedVariant.availableForSale) !== null && _a !== void 0 ? _a : true;
|
|
49
|
+
}, [selectedOptions, variants]);
|
|
50
|
+
const sellingPlanGroups = useMemo(() => {
|
|
51
|
+
var _a, _b;
|
|
52
|
+
return (_b = (_a = product.sellingPlanGroups) === null || _a === void 0 ? void 0 : _a.nodes) === null || _b === void 0 ? void 0 : _b.map((sellingPlanGroup) => {
|
|
53
|
+
var _a, _b;
|
|
54
|
+
return ({
|
|
55
|
+
...sellingPlanGroup,
|
|
56
|
+
sellingPlans: (_b = (_a = sellingPlanGroup === null || sellingPlanGroup === void 0 ? void 0 : sellingPlanGroup.sellingPlans) === null || _a === void 0 ? void 0 : _a.nodes) !== null && _b !== void 0 ? _b : [],
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}, [(_b = product.sellingPlanGroups) === null || _b === void 0 ? void 0 : _b.nodes]);
|
|
60
|
+
/**
|
|
61
|
+
* Track the selectedSellingPlan within the hook. If `initialSellingPlanId`
|
|
62
|
+
* is passed, use that as an initial value. Look it up from the `selectedVariant`, since
|
|
63
|
+
* that is also a requirement.
|
|
64
|
+
*/
|
|
65
|
+
const [selectedSellingPlan, setSelectedSellingPlan] = useState(undefined);
|
|
66
|
+
const selectedSellingPlanAllocation = useMemo(() => {
|
|
67
|
+
var _a, _b;
|
|
68
|
+
if (!selectedVariant || !selectedSellingPlan) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (!((_a = selectedVariant.sellingPlanAllocations) === null || _a === void 0 ? void 0 : _a.nodes)) {
|
|
72
|
+
throw new Error(`<ProductOptionsProvider/>: You must include 'sellingPlanAllocations.nodes' in your variants in order to calculate selectedSellingPlanAllocation`);
|
|
73
|
+
}
|
|
74
|
+
return (_b = selectedVariant.sellingPlanAllocations.nodes) === null || _b === void 0 ? void 0 : _b.find((allocation) => { var _a; return ((_a = allocation === null || allocation === void 0 ? void 0 : allocation.sellingPlan) === null || _a === void 0 ? void 0 : _a.id) === selectedSellingPlan.id; });
|
|
75
|
+
}, [selectedVariant, selectedSellingPlan]);
|
|
76
|
+
const value = useMemo(() => ({
|
|
77
|
+
variants,
|
|
78
|
+
variantsConnection: product.variants,
|
|
79
|
+
options,
|
|
80
|
+
selectedVariant,
|
|
81
|
+
setSelectedVariant,
|
|
82
|
+
selectedOptions,
|
|
83
|
+
setSelectedOption,
|
|
84
|
+
setSelectedOptions,
|
|
85
|
+
isOptionInStock,
|
|
86
|
+
selectedSellingPlan,
|
|
87
|
+
setSelectedSellingPlan,
|
|
88
|
+
selectedSellingPlanAllocation,
|
|
89
|
+
sellingPlanGroups,
|
|
90
|
+
sellingPlanGroupsConnection: product.sellingPlanGroups,
|
|
91
|
+
}), [
|
|
92
|
+
isOptionInStock,
|
|
93
|
+
options,
|
|
94
|
+
product.sellingPlanGroups,
|
|
95
|
+
product.variants,
|
|
96
|
+
selectedOptions,
|
|
97
|
+
selectedSellingPlan,
|
|
98
|
+
selectedSellingPlanAllocation,
|
|
99
|
+
selectedVariant,
|
|
100
|
+
sellingPlanGroups,
|
|
101
|
+
setSelectedOption,
|
|
102
|
+
variants,
|
|
103
|
+
]);
|
|
104
|
+
return (React.createElement(ProductOptionsContext.Provider, { value: value }, children));
|
|
105
|
+
}
|
|
106
|
+
function getVariantBasedOnIdProp(explicitVariantId, variants) {
|
|
107
|
+
// get the initial variant based on the logic outlined in the comments for 'initialVariantId' above
|
|
108
|
+
// * 1. If `initialVariantId` is provided, then it's used even if it's out of stock.
|
|
109
|
+
if (explicitVariantId) {
|
|
110
|
+
const foundVariant = variants.find((variant) => (variant === null || variant === void 0 ? void 0 : variant.id) === explicitVariantId);
|
|
111
|
+
if (!foundVariant) {
|
|
112
|
+
console.warn(`<ProductOptionsProvider/> received a 'initialVariantId' prop, but could not actually find a variant with that ID`);
|
|
113
|
+
}
|
|
114
|
+
return foundVariant;
|
|
115
|
+
}
|
|
116
|
+
// * 2. If `initialVariantId` is provided but is `null`, then no variant is used.
|
|
117
|
+
if (explicitVariantId === null) {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
// * 3. If nothing is passed to `initialVariantId` then the first available / in-stock variant is used.
|
|
121
|
+
// * 4. If nothing is passed to `initialVariantId` and no variants are in stock, then the first variant is used.
|
|
122
|
+
if (explicitVariantId === undefined) {
|
|
123
|
+
return variants.find((variant) => variant === null || variant === void 0 ? void 0 : variant.availableForSale) || variants[0];
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function getSelectedOptions(selectedVariant) {
|
|
127
|
+
return (selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.selectedOptions)
|
|
128
|
+
? selectedVariant.selectedOptions.reduce((memo, optionSet) => {
|
|
129
|
+
var _a, _b;
|
|
130
|
+
memo[(_a = optionSet === null || optionSet === void 0 ? void 0 : optionSet.name) !== null && _a !== void 0 ? _a : ''] = (_b = optionSet === null || optionSet === void 0 ? void 0 : optionSet.value) !== null && _b !== void 0 ? _b : '';
|
|
131
|
+
return memo;
|
|
132
|
+
}, {})
|
|
133
|
+
: {};
|
|
134
|
+
}
|
|
135
|
+
function isProductVariantArray(maybeVariantArray) {
|
|
136
|
+
if (!maybeVariantArray || !Array.isArray(maybeVariantArray)) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
return true;
|
|
140
|
+
}
|