@shopify/hydrogen 0.17.3 → 0.20.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 +259 -0
- package/config.d.ts +1 -0
- package/config.js +1 -0
- package/dist/esnext/components/AddToCartButton/AddToCartButton.client.js +2 -2
- package/dist/esnext/components/CartLineImage/CartLineImage.client.d.ts +4 -7
- package/dist/esnext/components/CartLineImage/CartLineImage.client.js +1 -2
- package/dist/esnext/components/CartProvider/CartProvider.client.d.ts +3 -1
- package/dist/esnext/components/CartProvider/CartProvider.client.js +37 -34
- package/dist/esnext/components/CartProvider/cart-queries.d.ts +10 -9
- package/dist/esnext/components/CartProvider/cart-queries.js +58 -743
- package/dist/esnext/components/CartProvider/{hooks.d.ts → hooks.client.d.ts} +0 -0
- package/dist/esnext/components/CartProvider/{hooks.js → hooks.client.js} +4 -2
- package/dist/esnext/components/CartProvider/index.d.ts +1 -1
- package/dist/esnext/components/CartProvider/index.js +1 -1
- package/dist/esnext/components/CartProvider/types.d.ts +2 -0
- package/dist/esnext/components/{DevTools.d.ts → DevTools.client.d.ts} +0 -0
- package/dist/esnext/components/{DevTools.js → DevTools.client.js} +3 -2
- package/dist/esnext/components/Image/Image.d.ts +78 -34
- package/dist/esnext/components/Image/Image.js +56 -51
- package/dist/esnext/components/Image/index.d.ts +1 -0
- package/dist/esnext/components/Link/Link.client.js +11 -2
- package/dist/esnext/components/LocalizationProvider/LocalizationClientProvider.client.js +2 -15
- package/dist/esnext/components/LocalizationProvider/LocalizationContext.client.d.ts +0 -1
- package/dist/esnext/components/LocalizationProvider/LocalizationProvider.server.d.ts +2 -6
- package/dist/esnext/components/LocalizationProvider/LocalizationProvider.server.js +11 -5
- package/dist/esnext/components/MediaFile/MediaFile.d.ts +2 -2
- package/dist/esnext/components/MediaFile/MediaFile.js +2 -2
- package/dist/esnext/components/Metafield/Metafield.client.js +4 -5
- package/dist/esnext/components/ModelViewer/ModelViewer.client.js +1 -1
- package/dist/esnext/components/Money/Money.client.d.ts +5 -1
- package/dist/esnext/components/Money/Money.client.js +16 -3
- package/dist/esnext/components/ProductMetafield/ProductMetafield.client.js +1 -1
- package/dist/esnext/components/ProductProvider/ProductOptionsProvider.client.js +1 -1
- package/dist/esnext/components/ProductProvider/ProductProvider.client.d.ts +7 -3
- package/dist/esnext/components/ShopPayButton/ShopPayButton.client.js +6 -2
- package/dist/esnext/components/Video/Video.d.ts +3 -3
- package/dist/esnext/components/Video/Video.js +10 -5
- package/dist/esnext/config.d.ts +3 -0
- package/dist/esnext/config.js +1 -0
- package/dist/esnext/constants.js +1 -1
- package/dist/esnext/entry-client.js +3 -1
- package/dist/esnext/entry-server.d.ts +14 -2
- package/dist/esnext/entry-server.js +56 -82
- package/dist/esnext/foundation/Cookie/Cookie.js +2 -1
- package/dist/esnext/foundation/FileRoutes/FileRoutes.server.d.ts +4 -4
- package/dist/esnext/foundation/FileRoutes/FileRoutes.server.js +17 -4
- package/dist/esnext/foundation/FileSessionStorage/FileSessionStorage.js +2 -1
- package/dist/esnext/foundation/Redirect/Redirect.client.js +1 -0
- package/dist/esnext/foundation/Router/BrowserRouter.client.js +10 -1
- package/dist/esnext/foundation/ServerPropsProvider/ServerPropsProvider.js +5 -3
- package/dist/esnext/foundation/ServerRequestProvider/ServerRequestProvider.d.ts +2 -2
- package/dist/esnext/foundation/ServerRequestProvider/ServerRequestProvider.js +7 -2
- package/dist/esnext/foundation/ServerStateProvider/ServerStateProvider.js +8 -1
- package/dist/esnext/foundation/ShopifyProvider/ShopifyProvider.server.d.ts +8 -1
- package/dist/esnext/foundation/ShopifyProvider/ShopifyProvider.server.js +31 -5
- package/dist/esnext/foundation/ShopifyProvider/types.d.ts +3 -4
- package/dist/esnext/foundation/fetchSync/client/fetchSync.js +2 -1
- package/dist/esnext/foundation/fetchSync/server/fetchSync.d.ts +1 -1
- package/dist/esnext/foundation/fetchSync/server/fetchSync.js +5 -3
- package/dist/esnext/foundation/ssr-interop.js +1 -1
- package/dist/esnext/foundation/useQuery/hooks.d.ts +1 -1
- package/dist/esnext/foundation/useQuery/hooks.js +2 -2
- package/dist/esnext/foundation/useSession/useSession.d.ts +1 -1
- package/dist/esnext/foundation/useSession/useSession.js +1 -1
- package/dist/esnext/foundation/useShop/use-shop.d.ts +3 -1
- package/dist/esnext/foundation/useShop/use-shop.js +3 -1
- package/dist/esnext/foundation/useUrl/useUrl.js +7 -4
- package/dist/esnext/framework/Hydration/Html.js +4 -2
- package/dist/esnext/framework/Hydration/ServerComponentRequest.server.d.ts +3 -2
- package/dist/esnext/framework/Hydration/ServerComponentRequest.server.js +16 -7
- package/dist/esnext/framework/Hydration/rsc.d.ts +0 -3
- package/dist/esnext/framework/Hydration/rsc.js +0 -20
- package/dist/esnext/framework/middleware.d.ts +3 -4
- package/dist/esnext/framework/middleware.js +4 -4
- package/dist/esnext/framework/plugin.d.ts +2 -2
- package/dist/esnext/framework/plugin.js +5 -32
- package/dist/esnext/framework/plugins/vite-plugin-css-modules-rsc.d.ts +1 -1
- package/dist/esnext/framework/plugins/vite-plugin-css-modules-rsc.js +68 -3
- package/dist/esnext/framework/plugins/vite-plugin-hydration-auto-import.js +1 -4
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-config.js +6 -5
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-middleware.d.ts +3 -3
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-middleware.js +61 -7
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-rsc.d.ts +1 -0
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-rsc.js +35 -0
- package/dist/esnext/framework/plugins/vite-plugin-platform-entry.js +1 -1
- package/dist/esnext/framework/plugins/vite-plugin-ssr-interop.js +6 -3
- package/dist/esnext/hooks/useCountry/useCountry.d.ts +1 -11
- package/dist/esnext/hooks/useCountry/useCountry.js +1 -1
- package/dist/esnext/hooks/useLoadScript/index.d.ts +1 -1
- package/dist/esnext/hooks/useLoadScript/index.js +1 -1
- package/dist/esnext/hooks/useLoadScript/{useLoadScript.d.ts → useLoadScript.client.d.ts} +0 -0
- package/dist/esnext/hooks/useLoadScript/{useLoadScript.js → useLoadScript.client.js} +2 -1
- package/dist/esnext/hooks/useMoney/hooks.d.ts +13 -1
- package/dist/esnext/hooks/useMoney/hooks.js +25 -1
- package/dist/esnext/hooks/useProduct/useProduct.js +1 -1
- package/dist/esnext/hooks/useProductOptions/index.d.ts +1 -1
- package/dist/esnext/hooks/useProductOptions/index.js +1 -1
- package/dist/esnext/hooks/useProductOptions/{useProductOptions.d.ts → useProductOptions.client.d.ts} +0 -0
- package/dist/esnext/hooks/useProductOptions/{useProductOptions.js → useProductOptions.client.js} +6 -23
- package/dist/esnext/hooks/useShopQuery/hooks.js +15 -4
- package/dist/esnext/node.d.ts +1 -0
- package/dist/esnext/node.js +1 -0
- package/dist/esnext/storefront-api-types.d.ts +65 -9
- package/dist/esnext/storefront-api-types.js +11 -5
- package/dist/esnext/types.d.ts +11 -4
- package/dist/esnext/utilities/apiRoutes.d.ts +4 -4
- package/dist/esnext/utilities/apiRoutes.js +29 -16
- package/dist/esnext/utilities/bot-ua.js +4 -0
- package/dist/esnext/utilities/empty-hydrogen-config.d.ts +2 -0
- package/dist/esnext/utilities/empty-hydrogen-config.js +2 -0
- package/dist/esnext/utilities/findRoutePrefix.d.ts +1 -0
- package/dist/esnext/utilities/findRoutePrefix.js +17 -0
- package/dist/esnext/utilities/image_size.d.ts +4 -22
- package/dist/esnext/utilities/image_size.js +15 -33
- package/dist/esnext/utilities/index.d.ts +1 -1
- package/dist/esnext/utilities/index.js +1 -1
- package/dist/esnext/utilities/log/utils.js +1 -1
- package/dist/esnext/utilities/parse.d.ts +1 -0
- package/dist/esnext/utilities/parse.js +9 -0
- package/dist/esnext/utilities/parseMetafieldValue/parseMetafieldValue.js +2 -1
- package/dist/esnext/utilities/storefrontApi.js +1 -0
- package/dist/esnext/version.d.ts +1 -1
- package/dist/esnext/version.js +1 -1
- package/dist/node/components/Image/Image.d.ts +84 -0
- package/dist/node/components/Image/Image.js +86 -0
- package/dist/node/components/Image/index.d.ts +2 -0
- package/dist/node/components/Image/index.js +5 -0
- package/dist/node/constants.js +1 -1
- package/dist/node/entry-server.d.ts +14 -2
- package/dist/node/entry-server.js +56 -82
- package/dist/node/foundation/Redirect/Redirect.client.js +1 -0
- package/dist/node/foundation/Router/BrowserRouter.client.js +10 -1
- package/dist/node/foundation/ServerPropsProvider/ServerPropsProvider.js +5 -3
- package/dist/node/foundation/ServerRequestProvider/ServerRequestProvider.d.ts +2 -2
- package/dist/node/foundation/ServerRequestProvider/ServerRequestProvider.js +7 -2
- package/dist/node/foundation/ShopifyProvider/types.d.ts +3 -4
- package/dist/node/foundation/ssr-interop.js +1 -1
- package/dist/node/framework/Hydration/Html.js +4 -2
- package/dist/node/framework/Hydration/ServerComponentRequest.server.d.ts +3 -2
- package/dist/node/framework/Hydration/ServerComponentRequest.server.js +16 -7
- package/dist/node/framework/Hydration/rsc.d.ts +0 -3
- package/dist/node/framework/Hydration/rsc.js +0 -20
- package/dist/node/framework/middleware.d.ts +3 -4
- package/dist/node/framework/middleware.js +4 -4
- package/dist/node/framework/plugin.d.ts +2 -2
- package/dist/node/framework/plugin.js +5 -55
- package/dist/node/framework/plugins/vite-plugin-css-modules-rsc.d.ts +1 -1
- package/dist/node/framework/plugins/vite-plugin-css-modules-rsc.js +71 -3
- package/dist/node/framework/plugins/vite-plugin-hydration-auto-import.js +1 -4
- package/dist/node/framework/plugins/vite-plugin-hydrogen-config.js +6 -5
- package/dist/node/framework/plugins/vite-plugin-hydrogen-middleware.d.ts +3 -3
- package/dist/node/framework/plugins/vite-plugin-hydrogen-middleware.js +60 -6
- package/dist/node/framework/plugins/vite-plugin-hydrogen-rsc.d.ts +1 -0
- package/dist/node/framework/plugins/vite-plugin-hydrogen-rsc.js +41 -0
- package/dist/node/framework/plugins/vite-plugin-platform-entry.js +1 -1
- package/dist/node/framework/plugins/vite-plugin-ssr-interop.js +6 -3
- package/dist/node/storefront-api-types.d.ts +65 -9
- package/dist/node/storefront-api-types.js +11 -5
- package/dist/node/types.d.ts +11 -4
- package/dist/node/utilities/apiRoutes.d.ts +4 -4
- package/dist/node/utilities/apiRoutes.js +29 -16
- package/dist/node/utilities/bot-ua.js +4 -0
- package/dist/node/utilities/findRoutePrefix.d.ts +1 -0
- package/dist/node/utilities/findRoutePrefix.js +21 -0
- package/dist/node/utilities/image_size.d.ts +4 -22
- package/dist/node/utilities/image_size.js +16 -58
- package/dist/node/utilities/index.d.ts +1 -1
- package/dist/node/utilities/index.js +1 -2
- package/dist/node/utilities/log/utils.js +1 -1
- package/dist/node/utilities/parse.d.ts +1 -0
- package/dist/node/utilities/parse.js +13 -0
- package/dist/node/utilities/parseMetafieldValue/parseMetafieldValue.js +2 -1
- package/dist/node/utilities/storefrontApi.js +1 -0
- package/dist/node/version.d.ts +1 -1
- package/dist/node/version.js +1 -1
- package/entry-server.d.ts +1 -1
- package/package.json +8 -6
- package/vendor/react-server-dom-vite/cjs/react-server-dom-vite-plugin.js +173 -29
- package/vendor/react-server-dom-vite/esm/react-server-dom-vite-client-proxy.js +2 -0
- package/vendor/react-server-dom-vite/esm/react-server-dom-vite-plugin.js +173 -29
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,264 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.20.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#1257](https://github.com/Shopify/hydrogen/pull/1257) [`5cd7a672`](https://github.com/Shopify/hydrogen/commit/5cd7a6727befe1e06f35b9ec68d4c81a8858d46f) Thanks [@frandiox](https://github.com/frandiox)! - Support for CSS Modules has been improved. It now behaves closer to the default behavior in Vite where styles are collected automatically.
|
|
8
|
+
|
|
9
|
+
Remove the `StyleTag` component that was needed before:
|
|
10
|
+
|
|
11
|
+
```diff
|
|
12
|
+
export default function MyComponent() {
|
|
13
|
+
return (
|
|
14
|
+
<div>
|
|
15
|
+
- <myStyles.StyleTag />
|
|
16
|
+
<h1>Title</h1>
|
|
17
|
+
</div>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Optionally, update your wildcard imports to default or named imports:
|
|
23
|
+
|
|
24
|
+
```diff
|
|
25
|
+
-import * as myStyles from './my.module.css';
|
|
26
|
+
+import myStyles from './my.module.css';
|
|
27
|
+
// Or
|
|
28
|
+
+import {red, green, blue} from './my.module.css';
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
* [#1271](https://github.com/Shopify/hydrogen/pull/1271) [`9d0359b8`](https://github.com/Shopify/hydrogen/commit/9d0359b87b0cfa04f12ffa9376e5b8ad72c560a3) Thanks [@frehner](https://github.com/frehner)! - ## `<Image/>`
|
|
32
|
+
|
|
33
|
+
The `<Image/>` component and related utility functions were reworked and the following changes apply:
|
|
34
|
+
|
|
35
|
+
- `useImageUrl` is no longer available; use `shopifyImageLoader` instead, which is available to run both server- and client-side.
|
|
36
|
+
- The TypeScript experience with `<Image/>` is improved; props will be validated better, and `loader` and `loaderOptions` will be better typed
|
|
37
|
+
- When using the `src` prop, `width` and `height` are now required
|
|
38
|
+
- When using the `data` prop, `data.width` and `data.height` or `width` and `height` props are required
|
|
39
|
+
- The `src` and `data` props are mutually exclusive
|
|
40
|
+
- The `loader` prop now receives a singular param as an object
|
|
41
|
+
- `options` has been merged with `loaderOptions`. When using the `data` prop, `loaderOptions` will be the options for Shopify CDN images. When using the `src` prop, `loaderOptions` will be whatever you define them to be.
|
|
42
|
+
- The TypeScript type `ImageSizeOptions` is now named `ShopifyLoaderOptions`
|
|
43
|
+
- The TypeScript type `ImageLoaderOptions` is now named `ShopifyLoaderParams`
|
|
44
|
+
- The `priority` prop was removed; use the HTML-standard `loading` prop instead
|
|
45
|
+
|
|
46
|
+
## `<Video/>`
|
|
47
|
+
|
|
48
|
+
- The `<Video/>` component's `options` props was renamed to `imagePreviewOptions` to add clarity as to what the options were for.
|
|
49
|
+
- `imagePreviewOptions` matches the (newly updated) shape of `<Image/>`'s `loaderOptions`
|
|
50
|
+
|
|
51
|
+
- [#1290](https://github.com/Shopify/hydrogen/pull/1290) [`437b1616`](https://github.com/Shopify/hydrogen/commit/437b1616fcfa15d8b4b2c033b364b2f74b99d6e4) Thanks [@jplhomer](https://github.com/jplhomer)! - Allow cart queries to be customized by adding a new `cartFragment` prop to `CartProvider`. [Learn more](https://shopify.dev/api/hydrogen/components/cart/cartprovider#cart-fragment).
|
|
52
|
+
|
|
53
|
+
### Patch Changes
|
|
54
|
+
|
|
55
|
+
- [#1247](https://github.com/Shopify/hydrogen/pull/1247) [`ee64873e`](https://github.com/Shopify/hydrogen/commit/ee64873ece372f9be2d6eb08b0594a91f4ed135a) Thanks [@frandiox](https://github.com/frandiox)! - Improve the way client components are discovered in order to reduce bundle sizes.
|
|
56
|
+
|
|
57
|
+
* [#1276](https://github.com/Shopify/hydrogen/pull/1276) [`c6ce6a43`](https://github.com/Shopify/hydrogen/commit/c6ce6a43bbb944b67aec5fdc7e5566768846dac5) Thanks [@frandiox](https://github.com/frandiox)! - Fix page loading in Firefox during development ([known bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1737882)).
|
|
58
|
+
|
|
59
|
+
- [#1286](https://github.com/Shopify/hydrogen/pull/1286) [`53270249`](https://github.com/Shopify/hydrogen/commit/5327024995ff7b8823ddb8ea835b3a5b95175841) Thanks [@jplhomer](https://github.com/jplhomer)! - Fix some sourcemap warnings in server console
|
|
60
|
+
|
|
61
|
+
## 0.19.0
|
|
62
|
+
|
|
63
|
+
### Minor Changes
|
|
64
|
+
|
|
65
|
+
- [#1053](https://github.com/Shopify/hydrogen/pull/1053) [`c407f304`](https://github.com/Shopify/hydrogen/commit/c407f304352e0b781fa8a729674153ee9b971977) Thanks [@blittle](https://github.com/blittle)! - The selected country is now persisted a part of the session. This means that the page can be refreshed and the country will still be selected. There are a few breaking changes:
|
|
66
|
+
|
|
67
|
+
1. `useCountry()` hook now only returns the currently selected country. The `setCountry()` method has been removed.
|
|
68
|
+
2. The `useCountry()` hook expects a `countryCode` and `countryName` to be a part of the user session.
|
|
69
|
+
3. The example `/countries` API route has been updated to accept a `POST` request to update the selected country. The CountrySelector components need to be updated to use that route.
|
|
70
|
+
|
|
71
|
+
```diff
|
|
72
|
+
// src/routes/countries.server.jsx
|
|
73
|
+
|
|
74
|
+
-export async function api(request, {queryShop}) {
|
|
75
|
+
+export async function api(request, {queryShop, session}) {
|
|
76
|
+
+ if (request.method === 'POST') {
|
|
77
|
+
+ const {isoCode, name} = await request.json();
|
|
78
|
+
+
|
|
79
|
+
+ await session.set('countryCode', isoCode);
|
|
80
|
+
+ await session.set('countryName', name);
|
|
81
|
+
+
|
|
82
|
+
+ return 'success';
|
|
83
|
+
+ }
|
|
84
|
+
|
|
85
|
+
const {
|
|
86
|
+
data: {
|
|
87
|
+
localization: {availableCountries},
|
|
88
|
+
},
|
|
89
|
+
} = await queryShop({
|
|
90
|
+
query: QUERY,
|
|
91
|
+
});
|
|
92
|
+
return availableCountries.sort((a, b) => a.name.localeCompare(b.name));
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
```diff
|
|
97
|
+
// src/components/CountrySelector.client.jsx
|
|
98
|
+
|
|
99
|
+
export default function CountrySelector() {
|
|
100
|
+
const [listboxOpen, setListboxOpen] = useState(false);
|
|
101
|
+
|
|
102
|
+
- const [selectedCountry, setSelectedCountry] = useCountry();
|
|
103
|
+
+ const [selectedCountry] = useCountry();
|
|
104
|
+
|
|
105
|
+
+ const setSelectedCountry = useCallback(
|
|
106
|
+
+ ({isoCode, name}) => {
|
|
107
|
+
+ fetch(`/countries`, {
|
|
108
|
+
+ body: JSON.stringify({isoCode, name}),
|
|
109
|
+
+ method: 'POST',
|
|
110
|
+
+ })
|
|
111
|
+
+ .then(() => {
|
|
112
|
+
+ window.location.reload();
|
|
113
|
+
+ })
|
|
114
|
+
+ .catch((error) => {
|
|
115
|
+
+ console.error(error);
|
|
116
|
+
+ });
|
|
117
|
+
+ },
|
|
118
|
+
+ [],
|
|
119
|
+
+ );
|
|
120
|
+
|
|
121
|
+
return (
|
|
122
|
+
...
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
4. Each server component page that depends on the selected country pulls it from the session with `useSession()`, rather than `serverProps`.
|
|
128
|
+
|
|
129
|
+
```diff
|
|
130
|
+
// src/routes/products/[handle].server.jsx
|
|
131
|
+
+ import { useSession } from '@shopify/hydrogen';
|
|
132
|
+
|
|
133
|
+
- export default function Product({country = {isoCode: 'US'}}) {
|
|
134
|
+
+ export default function Product() {
|
|
135
|
+
const {handle} = useRouteParams();
|
|
136
|
+
+ const {countryCode = 'US'} = useSession();
|
|
137
|
+
...
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Patch Changes
|
|
142
|
+
|
|
143
|
+
- [#1264](https://github.com/Shopify/hydrogen/pull/1264) [`dc966e86`](https://github.com/Shopify/hydrogen/commit/dc966e86b35ffc8a41d8d62e129884926b8db8bc) Thanks [@arlyxiao](https://github.com/arlyxiao)! - Add more bots into user agents
|
|
144
|
+
|
|
145
|
+
* [#1245](https://github.com/Shopify/hydrogen/pull/1245) [`07866e82`](https://github.com/Shopify/hydrogen/commit/07866e8277dfa3195ef1896b16a58df495a9155f) Thanks [@0x15f](https://github.com/0x15f)! - [#1245](https://github.com/Shopify/hydrogen/pull/1245) - Support optional `priority` prop on Image component. When `true`, the image will be eagerly loaded. Defaults to `false`.
|
|
146
|
+
|
|
147
|
+
- [#1272](https://github.com/Shopify/hydrogen/pull/1272) [`c1888652`](https://github.com/Shopify/hydrogen/commit/c188865255c5f20d9db285e375c57127030e23e6) Thanks [@wizardlyhel](https://github.com/wizardlyhel)! - Remove flight chunk
|
|
148
|
+
|
|
149
|
+
## 0.18.0
|
|
150
|
+
|
|
151
|
+
### Minor Changes
|
|
152
|
+
|
|
153
|
+
- [#1065](https://github.com/Shopify/hydrogen/pull/1065) [`81ae47fd`](https://github.com/Shopify/hydrogen/commit/81ae47fdb01be06af155a61e574d43c73122c414) Thanks [@frandiox](https://github.com/frandiox)! - A new config file `hydrogen.config.js` replaces the existing `shopify.config.js` in your Hydrogen app.
|
|
154
|
+
|
|
155
|
+
## Introducing `hydrogen.config.js`
|
|
156
|
+
|
|
157
|
+
Hydrogen apps now expect a `hydrogen.config.js` in the root folder. This config file accepts Shopify storefront credentials, routes, session configuration, and more.
|
|
158
|
+
|
|
159
|
+
To migrate existing apps, you should create a `hydrogen.config.js` (or `hydrogen.config.ts`) file in your Hydrogen app:
|
|
160
|
+
|
|
161
|
+
```js
|
|
162
|
+
import {defineConfig} from '@shopify/hydrogen/config';
|
|
163
|
+
import {
|
|
164
|
+
CookieSessionStorage,
|
|
165
|
+
PerformanceMetricsServerAnalyticsConnector,
|
|
166
|
+
} from '@shopify/hydrogen';
|
|
167
|
+
|
|
168
|
+
export default defineConfig({
|
|
169
|
+
routes: import.meta.globEager('./src/routes/**/*.server.[jt](s|sx)'),
|
|
170
|
+
shopify: {
|
|
171
|
+
storeDomain: 'YOUR_STORE.myshopify.com',
|
|
172
|
+
storefrontToken: 'YOUR_STOREFRONT_TOKEN',
|
|
173
|
+
storefrontApiVersion: '2022-07',
|
|
174
|
+
},
|
|
175
|
+
session: CookieSessionStorage('__session', {
|
|
176
|
+
path: '/',
|
|
177
|
+
httpOnly: true,
|
|
178
|
+
secure: process.env.NODE_ENV === 'production',
|
|
179
|
+
sameSite: 'strict',
|
|
180
|
+
maxAge: 60 * 60 * 24 * 30,
|
|
181
|
+
}),
|
|
182
|
+
serverAnalyticsConnectors: [PerformanceMetricsServerAnalyticsConnector],
|
|
183
|
+
});
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Then, update your `App.server.jsx` to remove previous arguments from `renderHydrogen()`:
|
|
187
|
+
|
|
188
|
+
```diff
|
|
189
|
+
import renderHydrogen from '@shopify/hydrogen/entry-server';
|
|
190
|
+
|
|
191
|
+
-function App({routes}) {
|
|
192
|
+
+function App() {
|
|
193
|
+
return (
|
|
194
|
+
<Suspense fallback={<LoadingFallback />}>
|
|
195
|
+
- <ShopifyProvider shopifyConfig={shopifyConfig}>
|
|
196
|
+
+ <ShopifyProvider>
|
|
197
|
+
<CartProvider>
|
|
198
|
+
<DefaultSeo />
|
|
199
|
+
<Router>
|
|
200
|
+
- <FileRoutes routes={routes} />
|
|
201
|
+
+ <FileRoutes />
|
|
202
|
+
<Route path="*" page={<NotFound />} />
|
|
203
|
+
</Router>
|
|
204
|
+
</CartProvider>
|
|
205
|
+
<PerformanceMetrics />
|
|
206
|
+
{process.env.LOCAL_DEV && <PerformanceMetricsDebug />}
|
|
207
|
+
</ShopifyProvider>
|
|
208
|
+
</Suspense>
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
-const routes = import.meta.globEager('./routes/**/*.server.[jt](s|sx)');
|
|
213
|
+
-
|
|
214
|
+
-export default renderHydrogen(App, {
|
|
215
|
+
- routes,
|
|
216
|
+
- shopifyConfig,
|
|
217
|
+
- session: CookieSessionStorage('__session', {
|
|
218
|
+
- path: '/',
|
|
219
|
+
- httpOnly: true,
|
|
220
|
+
- secure: process.env.NODE_ENV === 'production',
|
|
221
|
+
- sameSite: 'strict',
|
|
222
|
+
- maxAge: 60 * 60 * 24 * 30,
|
|
223
|
+
- }),
|
|
224
|
+
- serverAnalyticsConnectors: [PerformanceMetricsServerAnalyticsConnector],
|
|
225
|
+
-});
|
|
226
|
+
+export default renderHydrogen(App);
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
Next, update `vite.config.js` in your app to remove references to `shopifyConfig`:
|
|
230
|
+
|
|
231
|
+
```diff
|
|
232
|
+
import {defineConfig} from 'vite';
|
|
233
|
+
import hydrogen from '@shopify/hydrogen/plugin';
|
|
234
|
+
-import shopifyConfig from './shopify.config';
|
|
235
|
+
|
|
236
|
+
// https://vitejs.dev/config/
|
|
237
|
+
export default defineConfig({
|
|
238
|
+
- plugins: [hydrogen(shopifyConfig)],
|
|
239
|
+
+ plugins: [hydrogen()],
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
Finally, delete `shopify.config.js` from your app.
|
|
243
|
+
|
|
244
|
+
[Read more about the `hydrogen.config.js` file](https://shopify.dev/custom-storefronts/hydrogen/framework/hydrogen-config)
|
|
245
|
+
|
|
246
|
+
* [#1214](https://github.com/Shopify/hydrogen/pull/1214) [`58ef6d69`](https://github.com/Shopify/hydrogen/commit/58ef6d69f1148e7bc8452fa77e7e8f54396c6105) Thanks [@frehner](https://github.com/frehner)! - Upgraded SFAPI version to 2022-07
|
|
247
|
+
|
|
248
|
+
- [#1232](https://github.com/Shopify/hydrogen/pull/1232) [`d3956d62`](https://github.com/Shopify/hydrogen/commit/d3956d623adb86371ab214b102b53c62ea9ce26c) Thanks [@arlyxiao](https://github.com/arlyxiao)! - Upgrade body-parser in hydrogen package
|
|
249
|
+
|
|
250
|
+
### Patch Changes
|
|
251
|
+
|
|
252
|
+
- [#1211](https://github.com/Shopify/hydrogen/pull/1211) [`f3d26511`](https://github.com/Shopify/hydrogen/commit/f3d26511b1b0b94de1a43f76a0be9d99b5f2a8f7) Thanks [@wizardlyhel](https://github.com/wizardlyhel)! - Build chunks are inside assets folder
|
|
253
|
+
|
|
254
|
+
* [#1215](https://github.com/Shopify/hydrogen/pull/1215) [`a0ed7c06`](https://github.com/Shopify/hydrogen/commit/a0ed7c06d045a0063a356097dafcc25e5361aad1) Thanks [@frehner](https://github.com/frehner)! - `useMoney` now returns two additional properties: `withoutTrailingZeros` and `withoutTrailingZerosAndCurrency`
|
|
255
|
+
|
|
256
|
+
`<Money />` now has two additional and optional props: `withoutMoney` and `withoutCurrency`.
|
|
257
|
+
|
|
258
|
+
- [#1242](https://github.com/Shopify/hydrogen/pull/1242) [`c277c688`](https://github.com/Shopify/hydrogen/commit/c277c68836d6d75d509cc68c74e3ccd33706a0c7) Thanks [@blittle](https://github.com/blittle)! - Prevent JSON parsing from prototype poisoning vulnerabilities
|
|
259
|
+
|
|
260
|
+
* [#1210](https://github.com/Shopify/hydrogen/pull/1210) [`a844d26e`](https://github.com/Shopify/hydrogen/commit/a844d26ef258c28fded5293054389b719f0b86f4) Thanks [@blittle](https://github.com/blittle)! - Add eslint back and fix stale product options
|
|
261
|
+
|
|
3
262
|
## 0.17.3
|
|
4
263
|
|
|
5
264
|
### Patch Changes
|
package/config.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/esnext/config';
|
package/config.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/esnext/config';
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
declare type PropsWeControl = 'data' | 'options';
|
|
1
|
+
import { type ShopifyImageProps } from '../Image';
|
|
2
|
+
import type { Simplify } from 'type-fest';
|
|
3
|
+
declare type PropsWeControl = 'data';
|
|
5
4
|
/**
|
|
6
5
|
* The `CartLineImage` component renders an `Image` component for the cart line merchandise's image.
|
|
7
6
|
* It must be a descendent of a `CartLineProvider` component.
|
|
8
7
|
*/
|
|
9
|
-
export declare function CartLineImage(props: Omit<
|
|
10
|
-
options?: ImageSizeOptions;
|
|
11
|
-
}): JSX.Element | null;
|
|
8
|
+
export declare function CartLineImage(props: Simplify<Omit<ShopifyImageProps, PropsWeControl>>): JSX.Element | null;
|
|
12
9
|
export {};
|
|
@@ -7,6 +7,5 @@ import { Image } from '../Image';
|
|
|
7
7
|
*/
|
|
8
8
|
export function CartLineImage(props) {
|
|
9
9
|
const cartLine = useCartLine();
|
|
10
|
-
|
|
11
|
-
return cartLine.merchandise.image ? (React.createElement(Image, { ...passthroughProps, data: cartLine.merchandise.image, options: options })) : null;
|
|
10
|
+
return cartLine.merchandise.image ? (React.createElement(Image, { ...props, data: cartLine.merchandise.image })) : null;
|
|
12
11
|
}
|
|
@@ -9,7 +9,7 @@ import { CartFragmentFragment } from './graphql/CartFragment';
|
|
|
9
9
|
* The `CartProvider` component must be a descendent of the `ShopifyProvider` component.
|
|
10
10
|
* You must use this component if you want to use the `useCart` hook or related hooks, or if you would like to use the `AddToCartButton` component.
|
|
11
11
|
*/
|
|
12
|
-
export declare function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLineRemove, onLineUpdate, onNoteUpdate, onBuyerIdentityUpdate, onAttributesUpdate, onDiscountCodesUpdate, data: cart, }: {
|
|
12
|
+
export declare function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLineRemove, onLineUpdate, onNoteUpdate, onBuyerIdentityUpdate, onAttributesUpdate, onDiscountCodesUpdate, data: cart, cartFragment, }: {
|
|
13
13
|
/** Any `ReactNode` elements. */
|
|
14
14
|
children: React.ReactNode;
|
|
15
15
|
numCartLines?: number;
|
|
@@ -33,4 +33,6 @@ export declare function CartProvider({ children, numCartLines, onCreate, onLineA
|
|
|
33
33
|
* An object with fields that correspond to the Storefront API's [Cart object](https://shopify.dev/api/storefront/latest/objects/cart).
|
|
34
34
|
*/
|
|
35
35
|
data?: CartFragmentFragment;
|
|
36
|
+
/** A fragment used to query the Storefront API's [Cart object](https://shopify.dev/api/storefront/latest/objects/cart) for all queries and mutations. A default value is used if no argument is provided. */
|
|
37
|
+
cartFragment?: string;
|
|
36
38
|
}): JSX.Element;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useEffect, useCallback, useReducer, useMemo, useRef, } from 'react';
|
|
2
2
|
import { flattenConnection } from '../../utilities';
|
|
3
|
-
import { CartLineAdd, CartCreate, CartLineRemove, CartLineUpdate, CartNoteUpdate, CartBuyerIdentityUpdate, CartAttributesUpdate, CartDiscountCodesUpdate, CartQuery, } from './cart-queries';
|
|
4
|
-
import { useCartFetch } from './hooks';
|
|
3
|
+
import { CartLineAdd, CartCreate, CartLineRemove, CartLineUpdate, CartNoteUpdate, CartBuyerIdentityUpdate, CartAttributesUpdate, CartDiscountCodesUpdate, CartQuery, defaultCartFragment, } from './cart-queries';
|
|
4
|
+
import { useCartFetch } from './hooks.client';
|
|
5
5
|
import { CartContext } from './context';
|
|
6
6
|
import { CART_ID_STORAGE_KEY } from './constants';
|
|
7
7
|
import { useServerProps } from '../../foundation/useServerProps';
|
|
@@ -150,7 +150,7 @@ function cartReducer(state, action) {
|
|
|
150
150
|
* The `CartProvider` component must be a descendent of the `ShopifyProvider` component.
|
|
151
151
|
* You must use this component if you want to use the `useCart` hook or related hooks, or if you would like to use the `AddToCartButton` component.
|
|
152
152
|
*/
|
|
153
|
-
export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLineRemove, onLineUpdate, onNoteUpdate, onBuyerIdentityUpdate, onAttributesUpdate, onDiscountCodesUpdate, data: cart, }) {
|
|
153
|
+
export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLineRemove, onLineUpdate, onNoteUpdate, onBuyerIdentityUpdate, onAttributesUpdate, onDiscountCodesUpdate, data: cart, cartFragment = defaultCartFragment, }) {
|
|
154
154
|
var _a;
|
|
155
155
|
const { serverProps } = useServerProps();
|
|
156
156
|
const countryCode = (_a = serverProps === null || serverProps === void 0 ? void 0 : serverProps.country) === null || _a === void 0 ? void 0 : _a.isoCode;
|
|
@@ -162,7 +162,7 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
162
162
|
const cartFetch = useCallback(async (cartId) => {
|
|
163
163
|
dispatch({ type: 'cartFetch' });
|
|
164
164
|
const { data } = await fetchCart({
|
|
165
|
-
query: CartQuery,
|
|
165
|
+
query: CartQuery(cartFragment),
|
|
166
166
|
variables: {
|
|
167
167
|
id: cartId,
|
|
168
168
|
numCartLines,
|
|
@@ -175,7 +175,7 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
175
175
|
return;
|
|
176
176
|
}
|
|
177
177
|
dispatch({ type: 'resolve', cart: cartFromGraphQL(data.cart) });
|
|
178
|
-
}, [fetchCart, numCartLines, countryCode]);
|
|
178
|
+
}, [fetchCart, cartFragment, numCartLines, countryCode]);
|
|
179
179
|
const cartCreate = useCallback(async (cart) => {
|
|
180
180
|
var _a, _b;
|
|
181
181
|
dispatch({ type: 'cartCreate' });
|
|
@@ -187,7 +187,7 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
187
187
|
cart.buyerIdentity.countryCode = countryCode;
|
|
188
188
|
}
|
|
189
189
|
const { data, error } = await fetchCart({
|
|
190
|
-
query: CartCreate,
|
|
190
|
+
query: CartCreate(cartFragment),
|
|
191
191
|
variables: {
|
|
192
192
|
input: cart,
|
|
193
193
|
numCartLines,
|
|
@@ -197,7 +197,7 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
197
197
|
if (error) {
|
|
198
198
|
dispatch({
|
|
199
199
|
type: 'reject',
|
|
200
|
-
error
|
|
200
|
+
error,
|
|
201
201
|
});
|
|
202
202
|
}
|
|
203
203
|
if ((_b = data === null || data === void 0 ? void 0 : data.cartCreate) === null || _b === void 0 ? void 0 : _b.cart) {
|
|
@@ -213,17 +213,17 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
213
213
|
});
|
|
214
214
|
window.localStorage.setItem(CART_ID_STORAGE_KEY, data.cartCreate.cart.id);
|
|
215
215
|
}
|
|
216
|
-
}, [onCreate, fetchCart,
|
|
216
|
+
}, [onCreate, countryCode, fetchCart, cartFragment, numCartLines]);
|
|
217
217
|
const addLineItem = useCallback(async (lines, state) => {
|
|
218
218
|
var _a;
|
|
219
219
|
if (state.status === 'idle') {
|
|
220
220
|
dispatch({ type: 'addLineItem' });
|
|
221
221
|
onLineAdd === null || onLineAdd === void 0 ? void 0 : onLineAdd();
|
|
222
222
|
const { data, error } = await fetchCart({
|
|
223
|
-
query: CartLineAdd,
|
|
223
|
+
query: CartLineAdd(cartFragment),
|
|
224
224
|
variables: {
|
|
225
225
|
cartId: state.cart.id,
|
|
226
|
-
lines
|
|
226
|
+
lines,
|
|
227
227
|
numCartLines,
|
|
228
228
|
country: countryCode,
|
|
229
229
|
},
|
|
@@ -231,7 +231,7 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
231
231
|
if (error) {
|
|
232
232
|
dispatch({
|
|
233
233
|
type: 'reject',
|
|
234
|
-
error
|
|
234
|
+
error,
|
|
235
235
|
});
|
|
236
236
|
}
|
|
237
237
|
if ((_a = data === null || data === void 0 ? void 0 : data.cartLinesAdd) === null || _a === void 0 ? void 0 : _a.cart) {
|
|
@@ -245,17 +245,17 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
245
245
|
});
|
|
246
246
|
}
|
|
247
247
|
}
|
|
248
|
-
}, [fetchCart,
|
|
248
|
+
}, [onLineAdd, fetchCart, cartFragment, numCartLines, countryCode]);
|
|
249
249
|
const removeLineItem = useCallback(async (lines, state) => {
|
|
250
250
|
var _a;
|
|
251
251
|
if (state.status === 'idle') {
|
|
252
252
|
dispatch({ type: 'removeLineItem', lines });
|
|
253
253
|
onLineRemove === null || onLineRemove === void 0 ? void 0 : onLineRemove();
|
|
254
254
|
const { data, error } = await fetchCart({
|
|
255
|
-
query: CartLineRemove,
|
|
255
|
+
query: CartLineRemove(cartFragment),
|
|
256
256
|
variables: {
|
|
257
257
|
cartId: state.cart.id,
|
|
258
|
-
lines
|
|
258
|
+
lines,
|
|
259
259
|
numCartLines,
|
|
260
260
|
country: countryCode,
|
|
261
261
|
},
|
|
@@ -277,17 +277,17 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
277
277
|
});
|
|
278
278
|
}
|
|
279
279
|
}
|
|
280
|
-
}, [fetchCart,
|
|
280
|
+
}, [onLineRemove, fetchCart, cartFragment, numCartLines, countryCode]);
|
|
281
281
|
const updateLineItem = useCallback(async (lines, state) => {
|
|
282
282
|
var _a;
|
|
283
283
|
if (state.status === 'idle') {
|
|
284
284
|
dispatch({ type: 'updateLineItem', lines });
|
|
285
285
|
onLineUpdate === null || onLineUpdate === void 0 ? void 0 : onLineUpdate();
|
|
286
286
|
const { data, error } = await fetchCart({
|
|
287
|
-
query: CartLineUpdate,
|
|
287
|
+
query: CartLineUpdate(cartFragment),
|
|
288
288
|
variables: {
|
|
289
289
|
cartId: state.cart.id,
|
|
290
|
-
lines
|
|
290
|
+
lines,
|
|
291
291
|
numCartLines,
|
|
292
292
|
country: countryCode,
|
|
293
293
|
},
|
|
@@ -295,7 +295,7 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
295
295
|
if (error) {
|
|
296
296
|
dispatch({
|
|
297
297
|
type: 'reject',
|
|
298
|
-
error
|
|
298
|
+
error,
|
|
299
299
|
});
|
|
300
300
|
}
|
|
301
301
|
if ((_a = data === null || data === void 0 ? void 0 : data.cartLinesUpdate) === null || _a === void 0 ? void 0 : _a.cart) {
|
|
@@ -309,17 +309,17 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
309
309
|
});
|
|
310
310
|
}
|
|
311
311
|
}
|
|
312
|
-
}, [fetchCart,
|
|
312
|
+
}, [onLineUpdate, fetchCart, cartFragment, numCartLines, countryCode]);
|
|
313
313
|
const noteUpdate = useCallback(async (note, state) => {
|
|
314
314
|
var _a;
|
|
315
315
|
if (state.status === 'idle') {
|
|
316
316
|
dispatch({ type: 'noteUpdate' });
|
|
317
317
|
onNoteUpdate === null || onNoteUpdate === void 0 ? void 0 : onNoteUpdate();
|
|
318
318
|
const { data, error } = await fetchCart({
|
|
319
|
-
query: CartNoteUpdate,
|
|
319
|
+
query: CartNoteUpdate(cartFragment),
|
|
320
320
|
variables: {
|
|
321
321
|
cartId: state.cart.id,
|
|
322
|
-
note
|
|
322
|
+
note,
|
|
323
323
|
numCartLines,
|
|
324
324
|
country: countryCode,
|
|
325
325
|
},
|
|
@@ -327,7 +327,7 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
327
327
|
if (error) {
|
|
328
328
|
dispatch({
|
|
329
329
|
type: 'reject',
|
|
330
|
-
error
|
|
330
|
+
error,
|
|
331
331
|
});
|
|
332
332
|
}
|
|
333
333
|
if ((_a = data === null || data === void 0 ? void 0 : data.cartNoteUpdate) === null || _a === void 0 ? void 0 : _a.cart) {
|
|
@@ -337,14 +337,14 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
337
337
|
});
|
|
338
338
|
}
|
|
339
339
|
}
|
|
340
|
-
}, [fetchCart,
|
|
340
|
+
}, [onNoteUpdate, fetchCart, cartFragment, numCartLines, countryCode]);
|
|
341
341
|
const buyerIdentityUpdate = useCallback(async (buyerIdentity, state) => {
|
|
342
342
|
var _a;
|
|
343
343
|
if (state.status === 'idle') {
|
|
344
344
|
dispatch({ type: 'buyerIdentityUpdate' });
|
|
345
345
|
onBuyerIdentityUpdate === null || onBuyerIdentityUpdate === void 0 ? void 0 : onBuyerIdentityUpdate();
|
|
346
346
|
const { data, error } = await fetchCart({
|
|
347
|
-
query: CartBuyerIdentityUpdate,
|
|
347
|
+
query: CartBuyerIdentityUpdate(cartFragment),
|
|
348
348
|
variables: {
|
|
349
349
|
cartId: state.cart.id,
|
|
350
350
|
buyerIdentity,
|
|
@@ -355,7 +355,7 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
355
355
|
if (error) {
|
|
356
356
|
dispatch({
|
|
357
357
|
type: 'reject',
|
|
358
|
-
error
|
|
358
|
+
error,
|
|
359
359
|
});
|
|
360
360
|
}
|
|
361
361
|
if ((_a = data === null || data === void 0 ? void 0 : data.cartBuyerIdentityUpdate) === null || _a === void 0 ? void 0 : _a.cart) {
|
|
@@ -365,17 +365,17 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
365
365
|
});
|
|
366
366
|
}
|
|
367
367
|
}
|
|
368
|
-
}, [fetchCart,
|
|
368
|
+
}, [onBuyerIdentityUpdate, fetchCart, cartFragment, numCartLines, countryCode]);
|
|
369
369
|
const cartAttributesUpdate = useCallback(async (attributes, state) => {
|
|
370
370
|
var _a;
|
|
371
371
|
if (state.status === 'idle') {
|
|
372
372
|
dispatch({ type: 'cartAttributesUpdate' });
|
|
373
373
|
onAttributesUpdate === null || onAttributesUpdate === void 0 ? void 0 : onAttributesUpdate();
|
|
374
374
|
const { data, error } = await fetchCart({
|
|
375
|
-
query: CartAttributesUpdate,
|
|
375
|
+
query: CartAttributesUpdate(cartFragment),
|
|
376
376
|
variables: {
|
|
377
377
|
cartId: state.cart.id,
|
|
378
|
-
attributes
|
|
378
|
+
attributes,
|
|
379
379
|
numCartLines,
|
|
380
380
|
country: countryCode,
|
|
381
381
|
},
|
|
@@ -383,7 +383,7 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
383
383
|
if (error) {
|
|
384
384
|
dispatch({
|
|
385
385
|
type: 'reject',
|
|
386
|
-
error
|
|
386
|
+
error,
|
|
387
387
|
});
|
|
388
388
|
}
|
|
389
389
|
if ((_a = data === null || data === void 0 ? void 0 : data.cartAttributesUpdate) === null || _a === void 0 ? void 0 : _a.cart) {
|
|
@@ -393,17 +393,17 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
393
393
|
});
|
|
394
394
|
}
|
|
395
395
|
}
|
|
396
|
-
}, [fetchCart,
|
|
396
|
+
}, [onAttributesUpdate, fetchCart, cartFragment, numCartLines, countryCode]);
|
|
397
397
|
const discountCodesUpdate = useCallback(async (discountCodes, state) => {
|
|
398
398
|
var _a;
|
|
399
399
|
if (state.status === 'idle') {
|
|
400
400
|
dispatch({ type: 'discountCodesUpdate' });
|
|
401
401
|
onDiscountCodesUpdate === null || onDiscountCodesUpdate === void 0 ? void 0 : onDiscountCodesUpdate();
|
|
402
402
|
const { data, error } = await fetchCart({
|
|
403
|
-
query: CartDiscountCodesUpdate,
|
|
403
|
+
query: CartDiscountCodesUpdate(cartFragment),
|
|
404
404
|
variables: {
|
|
405
405
|
cartId: state.cart.id,
|
|
406
|
-
discountCodes
|
|
406
|
+
discountCodes,
|
|
407
407
|
numCartLines,
|
|
408
408
|
country: countryCode,
|
|
409
409
|
},
|
|
@@ -411,7 +411,7 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
411
411
|
if (error) {
|
|
412
412
|
dispatch({
|
|
413
413
|
type: 'reject',
|
|
414
|
-
error
|
|
414
|
+
error,
|
|
415
415
|
});
|
|
416
416
|
}
|
|
417
417
|
if ((_a = data === null || data === void 0 ? void 0 : data.cartDiscountCodesUpdate) === null || _a === void 0 ? void 0 : _a.cart) {
|
|
@@ -425,7 +425,7 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
425
425
|
});
|
|
426
426
|
}
|
|
427
427
|
}
|
|
428
|
-
}, [fetchCart,
|
|
428
|
+
}, [onDiscountCodesUpdate, fetchCart, cartFragment, numCartLines, countryCode]);
|
|
429
429
|
const didFetchCart = useRef(false);
|
|
430
430
|
useEffect(() => {
|
|
431
431
|
if (localStorage.getItem(CART_ID_STORAGE_KEY) &&
|
|
@@ -440,6 +440,7 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
440
440
|
return;
|
|
441
441
|
}
|
|
442
442
|
buyerIdentityUpdate({ countryCode }, state);
|
|
443
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
443
444
|
}, [countryCode]);
|
|
444
445
|
const cartContextValue = useMemo(() => {
|
|
445
446
|
return {
|
|
@@ -484,11 +485,13 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
484
485
|
discountCodesUpdate(discountCodes) {
|
|
485
486
|
discountCodesUpdate(discountCodes, state);
|
|
486
487
|
},
|
|
488
|
+
cartFragment,
|
|
487
489
|
};
|
|
488
490
|
}, [
|
|
489
491
|
state,
|
|
490
492
|
cart,
|
|
491
493
|
cartCreate,
|
|
494
|
+
cartFragment,
|
|
492
495
|
addLineItem,
|
|
493
496
|
removeLineItem,
|
|
494
497
|
updateLineItem,
|