@shopify/hydrogen 1.6.2 → 1.6.4

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.
@@ -47,4 +47,3 @@ export declare function CartProvider({ children, numCartLines, onCreate, onLineA
47
47
  /** The ISO country code for i18n. */
48
48
  countryCode?: CountryCode;
49
49
  }): JSX.Element;
50
- export declare const defaultCartFragment = "\nfragment CartFragment on Cart {\n id\n checkoutUrl\n totalQuantity\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 cost {\n totalAmount {\n amount\n currencyCode\n }\n compareAtAmountPerQuantity {\n amount\n currencyCode\n }\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 cost {\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";
@@ -1,5 +1,6 @@
1
1
  import React, { useCallback, useEffect, useMemo, useRef, useState, useTransition, } from 'react';
2
2
  import { CountryCode, } from '../../storefront-api-types.js';
3
+ import { defaultCartFragment } from './cart-queries.js';
3
4
  import { CartContext } from './context.js';
4
5
  import { useCartAPIStateMachine } from './useCartAPIStateMachine.client.js';
5
6
  import { CART_ID_STORAGE_KEY } from './constants.js';
@@ -432,103 +433,3 @@ function publishDiscountCodesUpdateAnalytics(context, event) {
432
433
  prevCart: context.prevCart,
433
434
  });
434
435
  }
435
- export const defaultCartFragment = `
436
- fragment CartFragment on Cart {
437
- id
438
- checkoutUrl
439
- totalQuantity
440
- buyerIdentity {
441
- countryCode
442
- customer {
443
- id
444
- email
445
- firstName
446
- lastName
447
- displayName
448
- }
449
- email
450
- phone
451
- }
452
- lines(first: $numCartLines) {
453
- edges {
454
- node {
455
- id
456
- quantity
457
- attributes {
458
- key
459
- value
460
- }
461
- cost {
462
- totalAmount {
463
- amount
464
- currencyCode
465
- }
466
- compareAtAmountPerQuantity {
467
- amount
468
- currencyCode
469
- }
470
- }
471
- merchandise {
472
- ... on ProductVariant {
473
- id
474
- availableForSale
475
- compareAtPriceV2 {
476
- ...MoneyFragment
477
- }
478
- priceV2 {
479
- ...MoneyFragment
480
- }
481
- requiresShipping
482
- title
483
- image {
484
- ...ImageFragment
485
- }
486
- product {
487
- handle
488
- title
489
- }
490
- selectedOptions {
491
- name
492
- value
493
- }
494
- }
495
- }
496
- }
497
- }
498
- }
499
- cost {
500
- subtotalAmount {
501
- ...MoneyFragment
502
- }
503
- totalAmount {
504
- ...MoneyFragment
505
- }
506
- totalDutyAmount {
507
- ...MoneyFragment
508
- }
509
- totalTaxAmount {
510
- ...MoneyFragment
511
- }
512
- }
513
- note
514
- attributes {
515
- key
516
- value
517
- }
518
- discountCodes {
519
- code
520
- }
521
- }
522
-
523
- fragment MoneyFragment on MoneyV2 {
524
- currencyCode
525
- amount
526
- }
527
- fragment ImageFragment on Image {
528
- id
529
- url
530
- altText
531
- width
532
- height
533
- }
534
- `;
@@ -8,7 +8,7 @@ export interface LinkProps extends Omit<React.AnchorHTMLAttributes<HTMLAnchorEle
8
8
  clientState?: any;
9
9
  /** Whether to reload the whole document on navigation. */
10
10
  reloadDocument?: boolean;
11
- /** Whether to prefetch the link source when the user signals intent. Defaults to `true`. For more information, refer to [Prefetching a link source](https://shopify.dev/custom-storefronts/hydrogen/framework/routes#prefetching-a-link-source). */
11
+ /** Whether to prefetch the link source when the user signals intent. Defaults to `true`. For more information, refer to [Prefetching a link source](https://shopify.dev/custom-storefronts/hydrogen/routing/manage-routes/#prefetching-a-link-source). */
12
12
  prefetch?: boolean;
13
13
  /** Whether to emulate natural browser behavior and restore scroll position on navigation. Defaults to `true`. */
14
14
  scroll?: boolean;
@@ -573,7 +573,7 @@ function tagOnWrite(response) {
573
573
  const savedChunks = [];
574
574
  response.write = (arg) => {
575
575
  if (arg instanceof Uint8Array) {
576
- savedChunks.push(decoder.decode(arg));
576
+ savedChunks.push(decoder.decode(arg, { stream: true }));
577
577
  }
578
578
  else {
579
579
  savedChunks.push(arg);
@@ -27,7 +27,7 @@ export declare type CookieOptions = {
27
27
  maxAge?: number;
28
28
  };
29
29
  /** The `Cookie` component helps you build your own custom cookie and session implementations. All
30
- * [Hydrogen session storage mechanisms](https://shopify.dev/custom-storefronts/hydrogen/framework/sessions#types-of-session-storage) use the
30
+ * [Hydrogen session storage mechanisms](https://shopify.dev/custom-storefronts/hydrogen/sessions#types-of-session-storage) use the
31
31
  * same configuration options as what's available in `Cookie`.
32
32
  */
33
33
  export declare class Cookie {
@@ -3,7 +3,7 @@ import { log } from '../../utilities/log/index.js';
3
3
  import { parseJSON } from '../../utilities/parse.js';
4
4
  const reservedCookieNames = ['mac', 'user_session_id'];
5
5
  /** The `Cookie` component helps you build your own custom cookie and session implementations. All
6
- * [Hydrogen session storage mechanisms](https://shopify.dev/custom-storefronts/hydrogen/framework/sessions#types-of-session-storage) use the
6
+ * [Hydrogen session storage mechanisms](https://shopify.dev/custom-storefronts/hydrogen/sessions#types-of-session-storage) use the
7
7
  * same configuration options as what's available in `Cookie`.
8
8
  */
9
9
  export class Cookie {
@@ -2,7 +2,10 @@ import React, { FormEvent } from 'react';
2
2
  interface FormProps {
3
3
  action: string;
4
4
  method?: string;
5
- children?: Array<React.ReactNode>;
5
+ children?: Array<React.ReactNode> | ((props: {
6
+ loading: boolean;
7
+ error: Error | null;
8
+ }) => React.ReactNode);
6
9
  onSubmit?: (e: FormEvent<HTMLFormElement>) => void;
7
10
  encType?: string;
8
11
  noValidate?: boolean;
@@ -30,7 +30,7 @@ export function Form({ action, method, children, onSubmit, encType = 'applicatio
30
30
  .then((fetchResponse) => {
31
31
  const rscPathname = fetchResponse.headers.get('Hydrogen-RSC-Pathname');
32
32
  if (!rscPathname)
33
- throw new Error(`The component's \`action\` attribute must point to an API route that responds with a new Request()\nRead more at https://shopify.dev/custom-storefronts/hydrogen/framework/forms`);
33
+ throw new Error(`The component's \`action\` attribute must point to an API route that responds with a new Request()\nRead more at https://shopify.dev/custom-storefronts/hydrogen/forms`);
34
34
  if (rscPathname !== window.location.pathname) {
35
35
  window.history.pushState(null, '', rscPathname);
36
36
  }
@@ -11,7 +11,7 @@ export declare const SHOPIFY_PROVIDER_CONTEXT_KEY: unique symbol;
11
11
  export declare function ShopifyProvider({
12
12
  /**
13
13
  * Shopify connection information. Defaults to
14
- * [the `shopify` property in the `hydrogen.config.js` file](https://shopify.dev/custom-storefronts/hydrogen/framework/hydrogen-config).
14
+ * [the `shopify` property in the `hydrogen.config.js` file](https://shopify.dev/custom-storefronts/hydrogen/configuration).
15
15
  */
16
16
  shopifyConfig, countryCode, languageCode,
17
17
  /** Any `ReactNode` elements. */
@@ -45,7 +45,7 @@ export const SHOPIFY_PROVIDER_CONTEXT_KEY = Symbol.for('SHOPIFY_PROVIDER_RSC');
45
45
  export function ShopifyProvider({
46
46
  /**
47
47
  * Shopify connection information. Defaults to
48
- * [the `shopify` property in the `hydrogen.config.js` file](https://shopify.dev/custom-storefronts/hydrogen/framework/hydrogen-config).
48
+ * [the `shopify` property in the `hydrogen.config.js` file](https://shopify.dev/custom-storefronts/hydrogen/configuration).
49
49
  */
50
50
  shopifyConfig, countryCode, languageCode,
51
51
  /** Any `ReactNode` elements. */
@@ -1,11 +1,11 @@
1
1
  import type { CachingStrategy, PreloadOptions, QueryKey } from '../../types.js';
2
2
  import type { HydrogenRequest } from '../HydrogenRequest/HydrogenRequest.server.js';
3
3
  export interface HydrogenUseQueryOptions {
4
- /** The [caching strategy](https://shopify.dev/custom-storefronts/hydrogen/framework/cache#caching-strategies) to help you
4
+ /** The [caching strategy](https://shopify.dev/custom-storefronts/hydrogen/querying/cache#caching-strategies) to help you
5
5
  * determine which cache control header to set.
6
6
  */
7
7
  cache?: CachingStrategy;
8
- /** Whether to [preload the query](https://shopify.dev/custom-storefronts/hydrogen/framework/preloaded-queries).
8
+ /** Whether to [preload the query](https://shopify.dev/custom-storefronts/hydrogen/querying/preloaded-queries).
9
9
  * Defaults to `false`. Specify `true` to preload the query for the URL or `'*'`
10
10
  * to preload the query for all requests.
11
11
  */
@@ -1,6 +1,6 @@
1
1
  import { ServerPropsContextValue, InternalServerPropsContextValue } from '../ServerPropsProvider/ServerPropsProvider.js';
2
2
  /**
3
- * The `useServerProps` hook allows you to manage the [server props](https://shopify.dev/custom-storefronts/hydrogen/framework/server-props) passed to your server components when using Hydrogen as a React Server Component framework. The server props get cleared when you navigate from one route to another.
3
+ * The `useServerProps` hook allows you to manage the [server props](https://shopify.dev/custom-storefronts/hydrogen/server-props) passed to your server components when using Hydrogen as a React Server Component framework. The server props get cleared when you navigate from one route to another.
4
4
  *
5
5
  * ## Return value
6
6
  *
@@ -1,7 +1,7 @@
1
1
  import { useContext } from 'react';
2
2
  import { ServerPropsContext, } from '../ServerPropsProvider/ServerPropsProvider.js';
3
3
  /**
4
- * The `useServerProps` hook allows you to manage the [server props](https://shopify.dev/custom-storefronts/hydrogen/framework/server-props) passed to your server components when using Hydrogen as a React Server Component framework. The server props get cleared when you navigate from one route to another.
4
+ * The `useServerProps` hook allows you to manage the [server props](https://shopify.dev/custom-storefronts/hydrogen/server-props) passed to your server components when using Hydrogen as a React Server Component framework. The server props get cleared when you navigate from one route to another.
5
5
  *
6
6
  * ## Return value
7
7
  *
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * The `useShop` hook provides access to values within
3
- * [the `shopify` property in the `hydrogen.config.js` file](https://shopify.dev/custom-storefronts/hydrogen/framework/hydrogen-config).
3
+ * [the `shopify` property in the `hydrogen.config.js` file](https://shopify.dev/custom-storefronts/hydrogen/configuration).
4
4
  * The `useShop` hook must be a descendent of a `ShopifyProvider` component.
5
5
  */
6
6
  export declare function useShop(): import("../ShopifyProvider/types.js").ShopifyContextServerValue;
@@ -2,7 +2,7 @@ import { ShopifyContext } from '../ShopifyProvider/index.js';
2
2
  import { useEnvContext } from '../ssr-interop.js';
3
3
  /**
4
4
  * The `useShop` hook provides access to values within
5
- * [the `shopify` property in the `hydrogen.config.js` file](https://shopify.dev/custom-storefronts/hydrogen/framework/hydrogen-config).
5
+ * [the `shopify` property in the `hydrogen.config.js` file](https://shopify.dev/custom-storefronts/hydrogen/configuration).
6
6
  * The `useShop` hook must be a descendent of a `ShopifyProvider` component.
7
7
  */
8
8
  export function useShop() {
@@ -14,13 +14,13 @@ export declare function useShopQuery<T>({ query, variables, cache, preload, }: {
14
14
  query?: string;
15
15
  /** An object of the variables for the GraphQL query. */
16
16
  variables?: Record<string, any>;
17
- /** The [caching strategy](https://shopify.dev/custom-storefronts/hydrogen/framework/cache#caching-strategies) to
17
+ /** The [caching strategy](https://shopify.dev/custom-storefronts/hydrogen/querying/cache#caching-strategies) to
18
18
  * help you determine which cache control header to set.
19
19
  */
20
20
  cache?: CachingStrategy;
21
21
  /** A string corresponding to a valid locale identifier like `en-us` used to make the request. */
22
22
  locale?: string;
23
- /** Whether to[preload the query](https://shopify.dev/custom-storefronts/hydrogen/framework/preloaded-queries).
23
+ /** Whether to[preload the query](https://shopify.dev//custom-storefronts/hydrogen/querying/preloaded-queries).
24
24
  * Defaults to `false`. Specify `true` to preload the query for the URL or `'*'`
25
25
  * to preload the query for all requests.
26
26
  */
@@ -14,7 +14,7 @@ export async function bufferReadableStream(reader, cb) {
14
14
  const { done, value } = await reader.read();
15
15
  if (done)
16
16
  break;
17
- const stringValue = typeof value === 'string' ? value : decoder.decode(value);
17
+ const stringValue = typeof value === 'string' ? value : decoder.decode(value, { stream: true });
18
18
  result += stringValue;
19
19
  if (cb) {
20
20
  cb(stringValue);
@@ -100,6 +100,6 @@ export function logQueryTimings(type, request) {
100
100
  log.debug(yellow('Suspense waterfall detected on query: ' +
101
101
  firstSuspenseWaterfallQueryName));
102
102
  log.debug(' Add the `showQueryTiming` property to your Hydrogen configuration to see more information:');
103
- log.debug(' https://shopify.dev/custom-storefronts/hydrogen/framework/hydrogen-config#logger');
103
+ log.debug(' https://shopify.dev/custom-storefronts/hydrogen/configuration#logger');
104
104
  }
105
105
  }
@@ -1,4 +1,2 @@
1
1
  export declare function parseJSON(json: any): any;
2
- export declare function parseState(url: URL): {
3
- [k: string]: string;
4
- } | undefined;
2
+ export declare function parseState(url: URL): Record<string, any> | undefined;
@@ -11,13 +11,16 @@ function noproto(k, v) {
11
11
  export function parseState(url) {
12
12
  try {
13
13
  const { pathname, search } = url;
14
+ const stateParam = url.searchParams.get('state');
14
15
  const state = pathname === RSC_PATHNAME
15
- ? parseJSON(url.searchParams.get('state') ?? '{}')
16
- : { pathname, search };
17
- return Object.fromEntries(Object.entries(state).map(([key, value]) => [
18
- decodeURIComponent(key ?? ''),
19
- decodeURIComponent(value ?? ''),
20
- ]));
16
+ ? stateParam
17
+ ? parseJSON(decodeURIComponent(stateParam))
18
+ : {}
19
+ : {
20
+ pathname: decodeURIComponent(pathname),
21
+ search: decodeURIComponent(search),
22
+ };
23
+ return state;
21
24
  }
22
25
  catch {
23
26
  // Do not throw to prevent unhandled errors
@@ -13,7 +13,7 @@ export function getStorefrontApiRequestHeaders({ buyerIp, publicStorefrontToken,
13
13
  log.error('No secret Shopify storefront API token was defined. This means your app will be rate limited!\nSee how to add the token: ');
14
14
  }
15
15
  else if (privateStorefrontToken) {
16
- log.warn('The private shopify storefront API token was loaded implicitly by an environment variable. This is deprecated, and instead the variable should be defined directly in the Hydrogen Config.\nFor more information: https://shopify.dev/custom-storefronts/hydrogen/framework/hydrogen-config');
16
+ log.warn('The private shopify storefront API token was loaded implicitly by an environment variable. This is deprecated, and instead the variable should be defined directly in the Hydrogen Config.\nFor more information: https://shopify.dev/custom-storefronts/hydrogen/configuration');
17
17
  }
18
18
  }
19
19
  }
@@ -22,7 +22,7 @@ export function getStorefrontApiRequestHeaders({ buyerIp, publicStorefrontToken,
22
22
  if (!storefrontIdWarned) {
23
23
  storefrontIdWarned = true;
24
24
  if (storefrontId) {
25
- log.warn('The storefrontId was loaded implicitly by an environment variable. This is deprecated, and instead the variable should be defined directly in the Hydrogen Config.\nFor more information: https://shopify.dev/custom-storefronts/hydrogen/framework/hydrogen-config');
25
+ log.warn('The storefrontId was loaded implicitly by an environment variable. This is deprecated, and instead the variable should be defined directly in the Hydrogen Config.\nFor more information: https://shopify.dev/custom-storefronts/hydrogen/configuration');
26
26
  }
27
27
  }
28
28
  }
@@ -1 +1 @@
1
- export declare const LIB_VERSION = "1.6.2";
1
+ export declare const LIB_VERSION = "1.6.4";
@@ -1 +1 @@
1
- export const LIB_VERSION = '1.6.2';
1
+ export const LIB_VERSION = '1.6.4';
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "engines": {
8
8
  "node": ">=14"
9
9
  },
10
- "version": "1.6.2",
10
+ "version": "1.6.4",
11
11
  "description": "Modern custom Shopify storefronts",
12
12
  "license": "MIT",
13
13
  "main": "dist/esnext/index.js",