Skip to content

Commit

Permalink
Throw when storeDomain is missing in production (#1979)
Browse files Browse the repository at this point in the history
* Throw when storeDomain is missing in production

* Changesets

* Fix log enhancer after changing message
  • Loading branch information
frandiox committed Apr 11, 2024
1 parent 42d3c60 commit dcabe91
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .changeset/spicy-lemons-impress.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
'@shopify/hydrogen': patch
---

Fall back to "mock.shop" when no value is passed in `storeDomain` to `createStorefrontClient`.
Fall back to "mock.shop" when no value is passed in `storeDomain` to `createStorefrontClient` in development.
2 changes: 1 addition & 1 deletion packages/cli/src/lib/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ export function enhanceH2Logs(options: {

if (
stringArg.startsWith('[h2:info:createStorefrontClient]') &&
stringArg.includes('"mock.shop"')
stringArg.includes('defaulting to mock.shop')
) {
// This message comes from hydrogen-react. Let's enhance it:
stringArg += '\nRun `h2 link` to link your store.';
Expand Down
14 changes: 12 additions & 2 deletions packages/hydrogen-react/src/storefront-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,18 @@ export function createStorefrontClient({
contentType,
}: StorefrontClientProps): StorefrontClientReturn {
if (!storeDomain) {
storeDomain = MOCK_SHOP_DOMAIN;
warnOnce(`storeDomain missing, defaulting to ${MOCK_SHOP_DOMAIN}`, 'info');
if (__HYDROGEN_DEV__) {
storeDomain = MOCK_SHOP_DOMAIN;
warnOnce(
`storeDomain missing, defaulting to ${MOCK_SHOP_DOMAIN}`,
'info',
);
} else {
throw new Error(
H2_PREFIX_ERROR +
`\`storeDomain\` is required when creating a new Storefront client in production.`,
);
}
}

if (storefrontApiVersion !== SFAPI_VERSION) {
Expand Down

0 comments on commit dcabe91

Please sign in to comment.