Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.

Commit 9bff83c

Browse files
committed
Update to shopifyDomain to only provide exactly what is passed in
1 parent 8ee1ffb commit 9bff83c

7 files changed

Lines changed: 29 additions & 113 deletions

File tree

.changeset/wet-hounds-add.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@shopify/hydrogen-react': patch
3+
---
4+
5+
Updated to Storefront API version `2023-01`
6+
7+
## Storefront API Changes
8+
9+
The Storefront API changelog can be viewed [here](https://shopify.dev/api/release-notes/2023-01#graphql-storefront-api-changes). There are not any breaking changes in the Storefront API itself.
10+
11+
## Storefront Kit changes
12+
13+
### Breaking Changes
14+
15+
- The default Cart query no longer uses `compareAtPriceV2` and `priceV2`; use `compareAtPrice` and `price` instead. The `V2` fields will be removed in an upcoming version of the Storefront API.
16+
- The storefront client and ShopifyProvider now provide the `storeDomain` exactly as it is received; it's recommended that you pass the domain with the protocol and the fully-qualified domain name for your Storefront. For example: `https://hydrogen-test.myshopify.com`

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Processes that need to happen:
4949

5050
- Create a new branch for the version, e.g. `2022-10`.
5151
- Comment out the "Create release pull request or publish" job in `releases.yml` so that it won't auto-publish a new version of the branch until you're ready
52+
- Create a new changeset. Use this changeset to add notes and guides to important things that are changed as part of this update.
5253
- Do a find & replace in the code to replace nearly all instances of the old version with the new version.
5354
- However, don't replace documentation unless it makes sense.
5455
- Also be careful that some versions of the Storefront API don't exactly match code here: for example, SFAPI `2022-07` could be both `2022-07` and `2022-7` in this codebase.

packages/react/src/ShopPayButton.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as React from 'react';
21
import {vi} from 'vitest';
32
import {render} from '@testing-library/react';
43
import {ShopifyProvider} from './ShopifyProvider.js';

packages/react/src/ShopPayButton.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,7 @@ export function ShopPayButton({
8989
return (
9090
<div className={className} style={style}>
9191
{shopPayLoadedStatus === 'done' && (
92-
<shop-pay-button
93-
store-url={`https://${storeDomain}`}
94-
variants={ids.join(',')}
95-
/>
92+
<shop-pay-button store-url={storeDomain} variants={ids.join(',')} />
9693
)}
9794
</div>
9895
);

packages/react/src/ShopifyProvider.test.tsx

Lines changed: 8 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
import type {PartialDeep} from 'type-fest';
88

99
const SHOPIFY_CONFIG: ShopifyContextProps = {
10-
storeDomain: 'notashop.myshopify.com',
10+
storeDomain: 'https://notashop.myshopify.com',
1111
storefrontToken: 'abc123',
1212
storefrontApiVersion: '2023-01',
1313
country: {
@@ -30,23 +30,6 @@ describe('<ShopifyProvider/>', () => {
3030
expect(screen.getByText('child')).toBeInTheDocument();
3131
});
3232

33-
it(`contains 'storeDomain' without https:// prefix`, () => {
34-
const {result} = renderHook(() => useShop(), {
35-
wrapper: ({children}) => (
36-
<ShopifyProvider
37-
shopifyConfig={{
38-
...SHOPIFY_CONFIG,
39-
storeDomain: 'https://notashop.myshopify.com',
40-
}}
41-
>
42-
{children}
43-
</ShopifyProvider>
44-
),
45-
});
46-
47-
expect(result.current.storeDomain).toBe('notashop.myshopify.com');
48-
});
49-
5033
describe(`getStorefrontApiUrl()`, () => {
5134
it(`returns the correct values`, () => {
5235
const {result} = renderHook(() => useShop(), {
@@ -83,7 +66,7 @@ describe('<ShopifyProvider/>', () => {
8366

8467
expect(
8568
result.current.getStorefrontApiUrl({
86-
storeDomain: 'override.myshopify.com',
69+
storeDomain: 'https://override.myshopify.com',
8770
storefrontApiVersion: '2022-07',
8871
})
8972
).toBe('https://override.myshopify.com/api/2022-07/graphql.json');
@@ -145,53 +128,14 @@ describe('<ShopifyProvider/>', () => {
145128
});
146129
});
147130

148-
describe(`storeDomain`, () => {
149-
it(`works with just the subdomain`, () => {
150-
const {result} = renderHook(() => useShop(), {
151-
wrapper: ({children}) => (
152-
<ShopifyProvider
153-
shopifyConfig={{
154-
...SHOPIFY_CONFIG,
155-
storeDomain: 'notashop',
156-
}}
157-
>
158-
{children}
159-
</ShopifyProvider>
160-
),
161-
});
162-
163-
expect(result.current.storeDomain).toBe('notashop');
164-
});
165-
});
166-
167131
describe(`getShopifyDomain()`, () => {
168-
it(`works with just the subdomain`, () => {
169-
const {result} = renderHook(() => useShop(), {
170-
wrapper: ({children}) => (
171-
<ShopifyProvider
172-
shopifyConfig={{
173-
...SHOPIFY_CONFIG,
174-
storeDomain: 'notashop',
175-
}}
176-
>
177-
{children}
178-
</ShopifyProvider>
179-
),
180-
});
181-
182-
expect(result.current.getShopifyDomain()).toBe(
183-
'https://notashop.myshopify.com'
184-
);
185-
});
186-
187132
it(`works with the domain`, () => {
188-
// @deprecated to be removed when we no longer support passing in '.myshopify.com' for domainName
189133
const {result} = renderHook(() => useShop(), {
190134
wrapper: ({children}) => (
191135
<ShopifyProvider
192136
shopifyConfig={{
193137
...SHOPIFY_CONFIG,
194-
storeDomain: 'notashop.myshopify.com',
138+
storeDomain: 'https://notashop.myshopify.com',
195139
}}
196140
>
197141
{children}
@@ -204,33 +148,13 @@ describe('<ShopifyProvider/>', () => {
204148
);
205149
});
206150

207-
it(`works with just the subdomain as override`, () => {
208-
const {result} = renderHook(() => useShop(), {
209-
wrapper: ({children}) => (
210-
<ShopifyProvider
211-
shopifyConfig={{
212-
...SHOPIFY_CONFIG,
213-
storeDomain: 'notashop',
214-
}}
215-
>
216-
{children}
217-
</ShopifyProvider>
218-
),
219-
});
220-
221-
expect(result.current.getShopifyDomain({storeDomain: 'test'})).toBe(
222-
'https://test.myshopify.com'
223-
);
224-
});
225-
226151
it(`works with the domain as override`, () => {
227-
// @deprecated to be removed when we no longer support passing in '.myshopify.com' for domainName
228152
const {result} = renderHook(() => useShop(), {
229153
wrapper: ({children}) => (
230154
<ShopifyProvider
231155
shopifyConfig={{
232156
...SHOPIFY_CONFIG,
233-
storeDomain: 'notashop.myshopify.com',
157+
storeDomain: 'https://notashop.myshopify.com',
234158
}}
235159
>
236160
{children}
@@ -239,7 +163,9 @@ describe('<ShopifyProvider/>', () => {
239163
});
240164

241165
expect(
242-
result.current.getShopifyDomain({storeDomain: 'test.myshopify.com'})
166+
result.current.getShopifyDomain({
167+
storeDomain: 'https://test.myshopify.com',
168+
})
243169
).toBe('https://test.myshopify.com');
244170
});
245171
});
@@ -256,7 +182,7 @@ export function getShopifyConfig(
256182
isoCode: config.language?.isoCode ?? 'EN',
257183
},
258184
locale: config.locale ?? 'EN-US',
259-
storeDomain: config.storeDomain ?? 'notashop.myshopify.io',
185+
storeDomain: config.storeDomain ?? 'https://notashop.myshopify.io',
260186
storefrontToken: config.storefrontToken ?? 'abc123',
261187
storefrontApiVersion: config.storefrontApiVersion ?? '2023-01',
262188
};

packages/react/src/ShopifyProvider.tsx

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,12 @@ export function ShopifyProvider({
4848
}
4949

5050
const finalConfig = useMemo<ShopifyContextValue>(() => {
51-
const storeDomain = shopifyConfig.storeDomain.replace(/^https?:\/\//, '');
52-
53-
// @deprecated remove the ability to pass in '.myshopify.com' strings in the future
54-
if (storeDomain.includes('.myshopify.com')) {
55-
if (__HYDROGEN_DEV__) {
56-
console.warn(
57-
`<ShopifyProvider/>: passing a 'storeDomain' prop that includes '.myshopify.com' will be unsupported in the future. Passing only the subdomain (for example, if the URL is 'test.myshopify.com', passing in 'test') will be the supported way going forward.`
58-
);
59-
}
60-
}
61-
6251
function getShopifyDomain(overrideProps?: {storeDomain?: string}) {
63-
let subDomain = overrideProps?.storeDomain ?? storeDomain;
64-
subDomain = subDomain.replace('.myshopify.com', '');
65-
66-
return `https://${subDomain}.myshopify.com`;
52+
return overrideProps?.storeDomain ?? shopifyConfig.storeDomain;
6753
}
6854

6955
return {
7056
...shopifyConfig,
71-
storeDomain,
7257
getPublicTokenHeaders(overrideProps) {
7358
return getPublicTokenHeadersRaw(
7459
overrideProps.contentType,
@@ -86,7 +71,7 @@ export function ShopifyProvider({
8671
}
8772
}
8873
return `${getShopifyDomain({
89-
storeDomain: overrideProps?.storeDomain ?? storeDomain,
74+
storeDomain: overrideProps?.storeDomain ?? shopifyConfig.storeDomain,
9075
})}/api/${
9176
overrideProps?.storefrontApiVersion ??
9277
shopifyConfig.storefrontApiVersion
@@ -119,7 +104,7 @@ export function useShop() {
119104
export type ShopifyContextProps = {
120105
/** The globally-unique identifier for the Shop */
121106
storefrontId?: string;
122-
/** The subdomain of your Shopify storefront URL (eg: `{subdomain}.myshopify.com`). */
107+
/** The full domain of your Shopify storefront URL (eg: the complete string of `{subdomain}.myshopify.com`). */
123108
storeDomain: string;
124109
/** The Storefront API public access token. Refer to the [authentication](https://shopify.dev/api/storefront#authentication) documentation for more details. */
125110
storefrontToken: string;

packages/react/src/cart-queries.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,17 +190,9 @@ export const defaultCartFragment = /* GraphQL */ `
190190
compareAtPrice {
191191
...MoneyFragment
192192
}
193-
# @deprecated remove in next major
194-
compareAtPriceV2 {
195-
...MoneyFragment
196-
}
197193
price {
198194
...MoneyFragment
199195
}
200-
# @deprecated remove in next major
201-
priceV2 {
202-
...MoneyFragment
203-
}
204196
requiresShipping
205197
title
206198
image {

0 commit comments

Comments
 (0)