@shopify/hydrogen 0.18.0 → 0.21.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 +200 -0
- package/config.d.ts +1 -0
- package/dist/esnext/components/CartEstimatedCost/CartEstimatedCost.client.d.ts +1 -1
- 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/CartLinePrice/CartLinePrice.client.d.ts +1 -1
- package/dist/esnext/components/CartProvider/CartProvider.client.d.ts +3 -1
- package/dist/esnext/components/CartProvider/CartProvider.client.js +22 -20
- 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.client.js +4 -2
- package/dist/esnext/components/CartProvider/types.d.ts +2 -0
- package/dist/esnext/components/Image/Image.d.ts +78 -34
- package/dist/esnext/components/Image/Image.js +54 -51
- package/dist/esnext/components/Image/index.d.ts +1 -0
- 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 +10 -4
- package/dist/esnext/components/MediaFile/MediaFile.d.ts +2 -2
- package/dist/esnext/components/MediaFile/MediaFile.js +2 -2
- package/dist/esnext/components/Money/Money.client.d.ts +11 -5
- package/dist/esnext/components/Money/Money.client.js +16 -3
- package/dist/esnext/components/ProductPrice/ProductPrice.client.d.ts +1 -2
- package/dist/esnext/components/ProductPrice/ProductPrice.client.js +1 -2
- package/dist/esnext/components/Video/Video.d.ts +3 -3
- package/dist/esnext/components/Video/Video.js +7 -4
- package/dist/esnext/components/index.d.ts +0 -3
- package/dist/esnext/components/index.js +0 -3
- package/dist/esnext/entry-server.d.ts +13 -1
- package/dist/esnext/entry-server.js +18 -51
- package/dist/esnext/foundation/ServerRequestProvider/ServerRequestProvider.js +18 -3
- package/dist/esnext/foundation/ServerStateProvider/ServerStateProvider.js +2 -0
- package/dist/esnext/foundation/fetchSync/server/fetchSync.d.ts +1 -1
- package/dist/esnext/foundation/fetchSync/server/fetchSync.js +1 -1
- package/dist/esnext/foundation/useQuery/hooks.js +8 -9
- package/dist/esnext/foundation/useSession/useSession.d.ts +1 -1
- package/dist/esnext/foundation/useSession/useSession.js +1 -1
- package/dist/esnext/framework/Hydration/Html.js +3 -1
- package/dist/esnext/framework/Hydration/ServerComponentResponse.server.d.ts +1 -1
- package/dist/esnext/framework/Hydration/ServerComponentResponse.server.js +2 -1
- package/dist/esnext/framework/Hydration/rsc.d.ts +0 -3
- package/dist/esnext/framework/Hydration/rsc.js +40 -12
- package/dist/esnext/framework/cache/in-memory.js +0 -6
- package/dist/esnext/framework/cache-sub-request.d.ts +17 -0
- package/dist/esnext/framework/cache-sub-request.js +64 -0
- package/dist/esnext/framework/cache.d.ts +6 -6
- package/dist/esnext/framework/cache.js +36 -33
- package/dist/esnext/framework/plugin.js +5 -30
- package/dist/esnext/framework/plugins/vite-plugin-client-imports.d.ts +2 -0
- package/dist/esnext/framework/plugins/vite-plugin-client-imports.js +25 -0
- 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 +73 -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 -4
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-middleware.d.ts +1 -1
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-middleware.js +2 -3
- 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/index.d.ts +4 -0
- package/dist/esnext/index.js +4 -0
- package/dist/esnext/node.d.ts +1 -0
- package/dist/esnext/node.js +1 -0
- package/dist/esnext/storefront-api-types.d.ts +5 -3
- package/dist/esnext/storefront-api-types.js +5 -3
- package/dist/esnext/types.d.ts +4 -3
- package/dist/esnext/utilities/bot-ua.js +4 -0
- package/dist/esnext/utilities/html-encoding.d.ts +2 -0
- package/dist/esnext/utilities/html-encoding.js +16 -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 +2 -1
- package/dist/esnext/utilities/index.js +2 -1
- package/dist/esnext/utilities/log/log-cache-api-status.js +5 -1
- 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/entry-server.d.ts +13 -1
- package/dist/node/entry-server.js +18 -51
- package/dist/node/foundation/ServerRequestProvider/ServerRequestProvider.js +18 -3
- package/dist/node/framework/Hydration/Html.js +3 -1
- package/dist/node/framework/Hydration/ServerComponentResponse.server.d.ts +1 -1
- package/dist/node/framework/Hydration/ServerComponentResponse.server.js +2 -1
- package/dist/node/framework/Hydration/rsc.d.ts +0 -3
- package/dist/node/framework/Hydration/rsc.js +40 -12
- package/dist/node/framework/cache/in-memory.js +0 -6
- package/dist/node/framework/cache-sub-request.d.ts +17 -0
- package/dist/node/framework/cache-sub-request.js +95 -0
- package/dist/node/framework/cache.d.ts +6 -6
- package/dist/node/framework/cache.js +38 -35
- package/dist/node/framework/plugin.js +5 -53
- package/dist/node/framework/plugins/vite-plugin-client-imports.d.ts +2 -0
- package/dist/node/framework/plugins/vite-plugin-client-imports.js +28 -0
- 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 +76 -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 -4
- package/dist/node/framework/plugins/vite-plugin-hydrogen-middleware.d.ts +1 -1
- package/dist/node/framework/plugins/vite-plugin-hydrogen-middleware.js +2 -3
- 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 +5 -3
- package/dist/node/storefront-api-types.js +5 -3
- package/dist/node/types.d.ts +4 -3
- package/dist/node/utilities/bot-ua.js +4 -0
- package/dist/node/utilities/html-encoding.d.ts +2 -0
- package/dist/node/utilities/html-encoding.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 +2 -1
- package/dist/node/utilities/index.js +4 -2
- package/dist/node/utilities/log/log-cache-api-status.js +5 -1
- 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 +3 -3
- package/vendor/react-server-dom-vite/cjs/react-server-dom-vite-plugin.js +200 -31
- 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 +200 -31
- package/vendor/react-server-dom-vite/package.json +2 -1
- package/dist/esnext/components/ProductDescription/ProductDescription.client.d.ts +0 -13
- package/dist/esnext/components/ProductDescription/ProductDescription.client.js +0 -16
- package/dist/esnext/components/ProductDescription/index.d.ts +0 -1
- package/dist/esnext/components/ProductDescription/index.js +0 -1
- package/dist/esnext/components/ProductMetafield/ProductMetafield.client.d.ts +0 -21
- package/dist/esnext/components/ProductMetafield/ProductMetafield.client.js +0 -42
- package/dist/esnext/components/ProductMetafield/index.d.ts +0 -2
- package/dist/esnext/components/ProductMetafield/index.js +0 -1
- package/dist/esnext/components/ProductTitle/ProductTitle.client.d.ts +0 -13
- package/dist/esnext/components/ProductTitle/ProductTitle.client.js +0 -16
- package/dist/esnext/components/ProductTitle/index.d.ts +0 -1
- package/dist/esnext/components/ProductTitle/index.js +0 -1
- package/dist/esnext/components/UnitPrice/UnitPrice.client.d.ts +0 -15
- package/dist/esnext/components/UnitPrice/UnitPrice.client.js +0 -22
- package/dist/esnext/components/UnitPrice/index.d.ts +0 -1
- package/dist/esnext/components/UnitPrice/index.js +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,205 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.21.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#1327](https://github.com/Shopify/hydrogen/pull/1327) [`ce56311f`](https://github.com/Shopify/hydrogen/commit/ce56311fc1b63df22f77b199980439548f76997a) Thanks [@frehner](https://github.com/frehner)! - **Breaking Change**: `<Money />` updates and `<UnitPrice />` Removed.
|
|
8
|
+
|
|
9
|
+
- `<UnitPrice/>` has been removed
|
|
10
|
+
- `<Money/>` has two new props: `measurement` and `measurementSeparator` which do the work that `UnitPrice` used to do
|
|
11
|
+
- The TypeScript types for `<Money/>` have been improved and should provide a better typed experience now
|
|
12
|
+
|
|
13
|
+
* [#1216](https://github.com/Shopify/hydrogen/pull/1216) [`771786a6`](https://github.com/Shopify/hydrogen/commit/771786a6475c4caadb1abe5f6644e2b5c2abc021) Thanks [@wizardlyhel](https://github.com/wizardlyhel)! - Fixes an issue where cached sub-requests were not revalidating properly.
|
|
14
|
+
|
|
15
|
+
- [#1304](https://github.com/Shopify/hydrogen/pull/1304) [`aa196150`](https://github.com/Shopify/hydrogen/commit/aa19615024de4fe16d548429665a863e9aae0248) Thanks [@frehner](https://github.com/frehner)! - Removed `<ProductTitle/>` and `<ProductDescription/>` components. To migrate, use `{product.title}` and `{product.description}` instead.
|
|
16
|
+
|
|
17
|
+
* [#1335](https://github.com/Shopify/hydrogen/pull/1335) [`0d90f92b`](https://github.com/Shopify/hydrogen/commit/0d90f92b448b0c4d99be3e5f5fa25d0b70a8315e) Thanks [@blittle](https://github.com/blittle)! - **Breaking Change**
|
|
18
|
+
|
|
19
|
+
The `<ProductMetafield />` component has been removed. Instead, directly use the `<Metafield>` component.
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- [#1311](https://github.com/Shopify/hydrogen/pull/1311) [`3e3fd72f`](https://github.com/Shopify/hydrogen/commit/3e3fd72f7016c0993deceefc121306cf957ef564) Thanks [@jplhomer](https://github.com/jplhomer)! - Client components no longer need to use `@shopify/hydrogen/client` as the import path. All Hydrogen components can now be imported from `@shopify/hydrogen` regardless of their context.
|
|
24
|
+
|
|
25
|
+
* [#1259](https://github.com/Shopify/hydrogen/pull/1259) [`110e9aca`](https://github.com/Shopify/hydrogen/commit/110e9aca385d553e3a87fea406f8bd8a43a0788f) Thanks [@blittle](https://github.com/blittle)! - You can now easily disable streaming on any page conditionally with the `enableStreaming` option inside `hydrogen.config.js`:
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import {CookieSessionStorage} from '@shopify/hydrogen';
|
|
29
|
+
import {defineConfig} from '@shopify/hydrogen/config';
|
|
30
|
+
|
|
31
|
+
export default defineConfig({
|
|
32
|
+
routes: import.meta.globEager('./src/routes/**/*.server.[jt](s|sx)'),
|
|
33
|
+
shopify: {
|
|
34
|
+
defaultLocale: 'en-us',
|
|
35
|
+
storeDomain: 'hydrogen-preview.myshopify.com',
|
|
36
|
+
storefrontToken: '3b580e70970c4528da70c98e097c2fa0',
|
|
37
|
+
storefrontApiVersion: '2022-07',
|
|
38
|
+
},
|
|
39
|
+
enableStreaming: (req) => req.headers.get('user-agent') !== 'custom bot',
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
By default all pages are stream rendered except for SEO bots. There shouldn't be many reasons to disable streaming, unless there is a custom bot not covered by Hydrogen's bot detection.
|
|
44
|
+
|
|
45
|
+
- [#1318](https://github.com/Shopify/hydrogen/pull/1318) [`668a24da`](https://github.com/Shopify/hydrogen/commit/668a24daebf180747a002c8020c2e712f5d9a458) Thanks [@blittle](https://github.com/blittle)! - Buffer RSC flight responses. There isn't any benefit to streaming them, because we start a transition on page navigation. Buffering also fixes caching problems on the flight response.
|
|
46
|
+
|
|
47
|
+
* [#1293](https://github.com/Shopify/hydrogen/pull/1293) [`e378ed61`](https://github.com/Shopify/hydrogen/commit/e378ed6199553f64d9e73ad27f9409ef501aa724) Thanks [@jplhomer](https://github.com/jplhomer)! - Reverts [#1272](https://github.com/Shopify/hydrogen/pull/1272) and properly escapes terminating script sequences
|
|
48
|
+
|
|
49
|
+
- [#1283](https://github.com/Shopify/hydrogen/pull/1283) [`eea82cb0`](https://github.com/Shopify/hydrogen/commit/eea82cb02064471d274e534c557caa5d3527bc93) Thanks [@jplhomer](https://github.com/jplhomer)! - Hydrogen has been updated to use the latest stable version of React.
|
|
50
|
+
|
|
51
|
+
To update an existing Hydrogen app:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
yarn add react@latest react-dom@latest
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## 0.20.0
|
|
58
|
+
|
|
59
|
+
### Minor Changes
|
|
60
|
+
|
|
61
|
+
- [#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.
|
|
62
|
+
|
|
63
|
+
Remove the `StyleTag` component that was needed before:
|
|
64
|
+
|
|
65
|
+
```diff
|
|
66
|
+
export default function MyComponent() {
|
|
67
|
+
return (
|
|
68
|
+
<div>
|
|
69
|
+
- <myStyles.StyleTag />
|
|
70
|
+
<h1>Title</h1>
|
|
71
|
+
</div>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Optionally, update your wildcard imports to default or named imports:
|
|
77
|
+
|
|
78
|
+
```diff
|
|
79
|
+
-import * as myStyles from './my.module.css';
|
|
80
|
+
+import myStyles from './my.module.css';
|
|
81
|
+
// Or
|
|
82
|
+
+import {red, green, blue} from './my.module.css';
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
* [#1271](https://github.com/Shopify/hydrogen/pull/1271) [`9d0359b8`](https://github.com/Shopify/hydrogen/commit/9d0359b87b0cfa04f12ffa9376e5b8ad72c560a3) Thanks [@frehner](https://github.com/frehner)! - ## `<Image/>`
|
|
86
|
+
|
|
87
|
+
The `<Image/>` component and related utility functions were reworked and the following changes apply:
|
|
88
|
+
|
|
89
|
+
- `useImageUrl` is no longer available; use `shopifyImageLoader` instead, which is available to run both server- and client-side.
|
|
90
|
+
- The TypeScript experience with `<Image/>` is improved; props will be validated better, and `loader` and `loaderOptions` will be better typed
|
|
91
|
+
- When using the `src` prop, `width` and `height` are now required
|
|
92
|
+
- When using the `data` prop, `data.width` and `data.height` or `width` and `height` props are required
|
|
93
|
+
- The `src` and `data` props are mutually exclusive
|
|
94
|
+
- The `loader` prop now receives a singular param as an object
|
|
95
|
+
- `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.
|
|
96
|
+
- The TypeScript type `ImageSizeOptions` is now named `ShopifyLoaderOptions`
|
|
97
|
+
- The TypeScript type `ImageLoaderOptions` is now named `ShopifyLoaderParams`
|
|
98
|
+
- The `priority` prop was removed; use the HTML-standard `loading` prop instead
|
|
99
|
+
|
|
100
|
+
## `<Video/>`
|
|
101
|
+
|
|
102
|
+
- The `<Video/>` component's `options` props was renamed to `imagePreviewOptions` to add clarity as to what the options were for.
|
|
103
|
+
- `imagePreviewOptions` matches the (newly updated) shape of `<Image/>`'s `loaderOptions`
|
|
104
|
+
|
|
105
|
+
- [#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).
|
|
106
|
+
|
|
107
|
+
### Patch Changes
|
|
108
|
+
|
|
109
|
+
- [#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.
|
|
110
|
+
|
|
111
|
+
* [#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)).
|
|
112
|
+
|
|
113
|
+
- [#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
|
|
114
|
+
|
|
115
|
+
## 0.19.0
|
|
116
|
+
|
|
117
|
+
### Minor Changes
|
|
118
|
+
|
|
119
|
+
- [#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:
|
|
120
|
+
|
|
121
|
+
1. `useCountry()` hook now only returns the currently selected country. The `setCountry()` method has been removed.
|
|
122
|
+
2. The `useCountry()` hook expects a `countryCode` and `countryName` to be a part of the user session.
|
|
123
|
+
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.
|
|
124
|
+
|
|
125
|
+
```diff
|
|
126
|
+
// src/routes/countries.server.jsx
|
|
127
|
+
|
|
128
|
+
-export async function api(request, {queryShop}) {
|
|
129
|
+
+export async function api(request, {queryShop, session}) {
|
|
130
|
+
+ if (request.method === 'POST') {
|
|
131
|
+
+ const {isoCode, name} = await request.json();
|
|
132
|
+
+
|
|
133
|
+
+ await session.set('countryCode', isoCode);
|
|
134
|
+
+ await session.set('countryName', name);
|
|
135
|
+
+
|
|
136
|
+
+ return 'success';
|
|
137
|
+
+ }
|
|
138
|
+
|
|
139
|
+
const {
|
|
140
|
+
data: {
|
|
141
|
+
localization: {availableCountries},
|
|
142
|
+
},
|
|
143
|
+
} = await queryShop({
|
|
144
|
+
query: QUERY,
|
|
145
|
+
});
|
|
146
|
+
return availableCountries.sort((a, b) => a.name.localeCompare(b.name));
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
```diff
|
|
151
|
+
// src/components/CountrySelector.client.jsx
|
|
152
|
+
|
|
153
|
+
export default function CountrySelector() {
|
|
154
|
+
const [listboxOpen, setListboxOpen] = useState(false);
|
|
155
|
+
|
|
156
|
+
- const [selectedCountry, setSelectedCountry] = useCountry();
|
|
157
|
+
+ const [selectedCountry] = useCountry();
|
|
158
|
+
|
|
159
|
+
+ const setSelectedCountry = useCallback(
|
|
160
|
+
+ ({isoCode, name}) => {
|
|
161
|
+
+ fetch(`/countries`, {
|
|
162
|
+
+ body: JSON.stringify({isoCode, name}),
|
|
163
|
+
+ method: 'POST',
|
|
164
|
+
+ })
|
|
165
|
+
+ .then(() => {
|
|
166
|
+
+ window.location.reload();
|
|
167
|
+
+ })
|
|
168
|
+
+ .catch((error) => {
|
|
169
|
+
+ console.error(error);
|
|
170
|
+
+ });
|
|
171
|
+
+ },
|
|
172
|
+
+ [],
|
|
173
|
+
+ );
|
|
174
|
+
|
|
175
|
+
return (
|
|
176
|
+
...
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
4. Each server component page that depends on the selected country pulls it from the session with `useSession()`, rather than `serverProps`.
|
|
182
|
+
|
|
183
|
+
```diff
|
|
184
|
+
// src/routes/products/[handle].server.jsx
|
|
185
|
+
+ import { useSession } from '@shopify/hydrogen';
|
|
186
|
+
|
|
187
|
+
- export default function Product({country = {isoCode: 'US'}}) {
|
|
188
|
+
+ export default function Product() {
|
|
189
|
+
const {handle} = useRouteParams();
|
|
190
|
+
+ const {countryCode = 'US'} = useSession();
|
|
191
|
+
...
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Patch Changes
|
|
196
|
+
|
|
197
|
+
- [#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
|
|
198
|
+
|
|
199
|
+
* [#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`.
|
|
200
|
+
|
|
201
|
+
- [#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
|
|
202
|
+
|
|
3
203
|
## 0.18.0
|
|
4
204
|
|
|
5
205
|
### Minor Changes
|
package/config.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/esnext/config';
|
|
@@ -11,4 +11,4 @@ export interface CartEstimatedCostProps {
|
|
|
11
11
|
* cost associated with the `amountType` prop. If no `amountType` prop is specified, then it defaults to `totalAmount`.
|
|
12
12
|
* If `children` is a function, then it will pass down the render props provided by the parent component.
|
|
13
13
|
*/
|
|
14
|
-
export declare function CartEstimatedCost
|
|
14
|
+
export declare function CartEstimatedCost(props: Omit<React.ComponentProps<typeof Money>, 'data'> & CartEstimatedCostProps): JSX.Element | null;
|
|
@@ -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
|
}
|
|
@@ -8,5 +8,5 @@ interface CartLinePriceProps {
|
|
|
8
8
|
* The `CartLinePrice` component renders a `Money` component for the cart line merchandise's price or
|
|
9
9
|
* compare at price. It must be a descendent of a `CartLineProvider` component.
|
|
10
10
|
*/
|
|
11
|
-
export declare function CartLinePrice
|
|
11
|
+
export declare function CartLinePrice(props: Omit<React.ComponentProps<typeof Money>, 'data'> & CartLinePriceProps): JSX.Element | null;
|
|
12
12
|
export {};
|
|
@@ -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,6 +1,6 @@
|
|
|
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';
|
|
3
|
+
import { CartLineAdd, CartCreate, CartLineRemove, CartLineUpdate, CartNoteUpdate, CartBuyerIdentityUpdate, CartAttributesUpdate, CartDiscountCodesUpdate, CartQuery, defaultCartFragment, } from './cart-queries';
|
|
4
4
|
import { useCartFetch } from './hooks.client';
|
|
5
5
|
import { CartContext } from './context';
|
|
6
6
|
import { CART_ID_STORAGE_KEY } from './constants';
|
|
@@ -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,
|
|
@@ -213,14 +213,14 @@ 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
226
|
lines,
|
|
@@ -245,14 +245,14 @@ 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
258
|
lines,
|
|
@@ -277,14 +277,14 @@ 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
290
|
lines,
|
|
@@ -309,14 +309,14 @@ 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
322
|
note,
|
|
@@ -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,
|
|
@@ -365,14 +365,14 @@ 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
378
|
attributes,
|
|
@@ -393,14 +393,14 @@ 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
406
|
discountCodes,
|
|
@@ -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) &&
|
|
@@ -485,11 +485,13 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
485
485
|
discountCodesUpdate(discountCodes) {
|
|
486
486
|
discountCodesUpdate(discountCodes, state);
|
|
487
487
|
},
|
|
488
|
+
cartFragment,
|
|
488
489
|
};
|
|
489
490
|
}, [
|
|
490
491
|
state,
|
|
491
492
|
cart,
|
|
492
493
|
cartCreate,
|
|
494
|
+
cartFragment,
|
|
493
495
|
addLineItem,
|
|
494
496
|
removeLineItem,
|
|
495
497
|
updateLineItem,
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
export declare const CartLineAdd
|
|
2
|
-
export declare const CartCreate
|
|
3
|
-
export declare const CartLineRemove
|
|
4
|
-
export declare const CartLineUpdate
|
|
5
|
-
export declare const CartNoteUpdate
|
|
6
|
-
export declare const CartBuyerIdentityUpdate
|
|
7
|
-
export declare const CartAttributesUpdate
|
|
8
|
-
export declare const CartDiscountCodesUpdate
|
|
9
|
-
export declare const CartQuery
|
|
1
|
+
export declare const CartLineAdd: (cartFragment: string) => string;
|
|
2
|
+
export declare const CartCreate: (cartFragment: string) => string;
|
|
3
|
+
export declare const CartLineRemove: (cartFragment: string) => string;
|
|
4
|
+
export declare const CartLineUpdate: (cartFragment: string) => string;
|
|
5
|
+
export declare const CartNoteUpdate: (cartFragment: string) => string;
|
|
6
|
+
export declare const CartBuyerIdentityUpdate: (cartFragment: string) => string;
|
|
7
|
+
export declare const CartAttributesUpdate: (cartFragment: string) => string;
|
|
8
|
+
export declare const CartDiscountCodesUpdate: (cartFragment: string) => string;
|
|
9
|
+
export declare const CartQuery: (cartFragment: string) => string;
|
|
10
|
+
export declare const defaultCartFragment = "\nfragment CartFragment on Cart {\n id\n checkoutUrl\n buyerIdentity {\n countryCode\n customer {\n id\n email\n firstName\n lastName\n displayName\n }\n email\n phone\n }\n lines(first: $numCartLines) {\n edges {\n node {\n id\n quantity\n attributes {\n key\n value\n }\n merchandise {\n ... on ProductVariant {\n id\n availableForSale\n compareAtPriceV2 {\n ...MoneyFragment\n }\n priceV2 {\n ...MoneyFragment\n }\n requiresShipping\n title\n image {\n ...ImageFragment\n }\n product {\n handle\n title\n }\n selectedOptions {\n name\n value\n }\n }\n }\n }\n }\n }\n estimatedCost {\n subtotalAmount {\n ...MoneyFragment\n }\n totalAmount {\n ...MoneyFragment\n }\n totalDutyAmount {\n ...MoneyFragment\n }\n totalTaxAmount {\n ...MoneyFragment\n }\n }\n note\n attributes {\n key\n value\n }\n discountCodes {\n code\n }\n}\n\nfragment MoneyFragment on MoneyV2 {\n currencyCode\n amount\n}\nfragment ImageFragment on Image {\n id\n url\n altText\n width\n height\n}\n";
|