@shopify/hydrogen 1.6.5 → 1.6.7

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.
@@ -1,12 +1,13 @@
1
1
  import React from 'react';
2
2
  import { BaseButtonProps } from '../BaseButton/index.js';
3
- interface CartLineQuantityAdjustButtonProps {
3
+ interface CartLineQuantityAdjustButtonBaseProps {
4
4
  /** The adjustment for a cart line's quantity. Valid values: `increase` (default), `decrease`, or `remove`. */
5
5
  adjust?: 'increase' | 'decrease' | 'remove';
6
6
  }
7
+ declare type CartLineQuantityAdjustButtonProps<AsType extends React.ElementType = 'button'> = BaseButtonProps<AsType> & CartLineQuantityAdjustButtonBaseProps;
7
8
  /**
8
9
  * The `CartLineQuantityAdjustButton` component renders a button that adjusts the cart line's quantity when pressed.
9
10
  * It must be a descendent of a `CartLineProvider` component.
10
11
  */
11
- export declare function CartLineQuantityAdjustButton<AsType extends React.ElementType = 'button'>(props: CartLineQuantityAdjustButtonProps & BaseButtonProps<AsType>): JSX.Element;
12
+ export declare function CartLineQuantityAdjustButton<AsType extends React.ElementType = 'button'>(props: CartLineQuantityAdjustButtonProps<AsType>): JSX.Element;
12
13
  export {};
@@ -12,15 +12,32 @@ export function CartLineQuantityAdjustButton(props) {
12
12
  const { children, adjust, onClick, ...passthroughProps } = props;
13
13
  const handleAdjust = useCallback(() => {
14
14
  if (adjust === 'remove') {
15
- linesRemove([cartLine.id]);
15
+ linesRemove([cartLine?.id ?? '']);
16
16
  return;
17
17
  }
18
- const quantity = adjust === 'decrease' ? cartLine.quantity - 1 : cartLine.quantity + 1;
18
+ const quantity = adjust === 'decrease'
19
+ ? (cartLine?.quantity ?? 0) - 1
20
+ : (cartLine?.quantity ?? 0) + 1;
19
21
  if (quantity <= 0) {
20
- linesRemove([cartLine.id]);
22
+ linesRemove([cartLine?.id ?? '']);
21
23
  return;
22
24
  }
23
- linesUpdate([{ id: cartLine.id, quantity }]);
24
- }, [adjust, cartLine.id, cartLine.quantity, linesRemove, linesUpdate]);
25
- return (React.createElement(BaseButton, { disabled: status !== 'idle', onClick: onClick, defaultOnClick: handleAdjust, ...passthroughProps }, children));
25
+ const lineUpdate = {
26
+ id: cartLine?.id ?? '',
27
+ quantity,
28
+ attributes: (cartLine?.attributes ??
29
+ []),
30
+ };
31
+ linesUpdate([lineUpdate]);
32
+ }, [
33
+ adjust,
34
+ cartLine?.attributes,
35
+ cartLine?.id,
36
+ cartLine?.quantity,
37
+ linesRemove,
38
+ linesUpdate,
39
+ ]);
40
+ return (React.createElement(BaseButton, { onClick: onClick, defaultOnClick: handleAdjust, ...passthroughProps, disabled: typeof passthroughProps.disabled !== 'undefined'
41
+ ? passthroughProps.disabled
42
+ : status !== 'idle' }, children));
26
43
  }
@@ -35,14 +35,19 @@ function publish(eventname, guardDup = false, payload = {}) {
35
35
  const namedspacedEventname = getNamedspacedEventname(eventname);
36
36
  // De-dup events due to re-renders
37
37
  if (guardDup) {
38
- const eventGuardTimeout = guardDupEvents[namedspacedEventname];
38
+ const guardName = namedspacedEventname + ':' + pageAnalyticsData.url;
39
+ const eventGuardTimeout = guardDupEvents[guardName];
39
40
  if (eventGuardTimeout) {
40
- clearTimeout(eventGuardTimeout);
41
+ clearTimeout(eventGuardTimeout.timeout);
41
42
  }
42
43
  const namespacedTimeout = setTimeout(() => {
43
- publishEvent(namedspacedEventname, mergeDeep(pageAnalyticsData, payload));
44
- }, 100);
45
- guardDupEvents[namedspacedEventname] = namespacedTimeout;
44
+ publishEvent(namedspacedEventname, guardDupEvents[guardName].data);
45
+ delete guardDupEvents[guardName];
46
+ }, 2000);
47
+ guardDupEvents[guardName] = {
48
+ timeout: namespacedTimeout,
49
+ data: mergeDeep(pageAnalyticsData, payload),
50
+ };
46
51
  }
47
52
  else {
48
53
  publishEvent(namedspacedEventname, mergeDeep(pageAnalyticsData, payload));
@@ -1 +1 @@
1
- export declare const LIB_VERSION = "1.6.5";
1
+ export declare const LIB_VERSION = "1.6.7";
@@ -1 +1 @@
1
- export const LIB_VERSION = '1.6.5';
1
+ export const LIB_VERSION = '1.6.7';
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "engines": {
8
8
  "node": ">=14"
9
9
  },
10
- "version": "1.6.5",
10
+ "version": "1.6.7",
11
11
  "description": "Modern custom Shopify storefronts",
12
12
  "license": "MIT",
13
13
  "main": "dist/esnext/index.js",
@@ -70,7 +70,7 @@
70
70
  },
71
71
  "repository": {
72
72
  "type": "git",
73
- "url": "git+https://github.com/Shopify/hydrogen.git",
73
+ "url": "git+https://github.com/Shopify/hydrogen-v1.git",
74
74
  "directory": "packages/hydrogen"
75
75
  },
76
76
  "devDependencies": {