@shopify/hydrogen 1.6.4 → 1.6.5

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.
@@ -52,25 +52,23 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
52
52
  onNoteUpdate,
53
53
  ]);
54
54
  const onCartActionOptimisticUI = useCallback((context, event) => {
55
- if (!context?.cart)
56
- return { cart: undefined };
55
+ if (!context.cart)
56
+ return { ...context };
57
57
  switch (event.type) {
58
58
  case 'CARTLINE_REMOVE':
59
59
  return {
60
60
  ...context,
61
- lastValidCart: context.cart,
62
61
  cart: {
63
62
  ...context.cart,
64
- lines: context?.cart?.lines.filter(({ id }) => !event.payload.lines.includes(id)),
63
+ lines: context.cart.lines.filter(({ id }) => !event.payload.lines.includes(id)),
65
64
  },
66
65
  };
67
66
  case 'CARTLINE_UPDATE':
68
67
  return {
69
68
  ...context,
70
- lastValidCart: context.cart,
71
69
  cart: {
72
70
  ...context.cart,
73
- lines: context.cart.lines.map((line) => {
71
+ lines: context?.cart?.lines.map((line) => {
74
72
  const updatedLine = event.payload.lines.find(({ id }) => id === line.id);
75
73
  if (updatedLine && updatedLine.quantity) {
76
74
  return {
@@ -83,7 +81,7 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
83
81
  },
84
82
  };
85
83
  }
86
- return { cart: context.cart ? { ...context.cart } : undefined };
84
+ return { ...context };
87
85
  }, []);
88
86
  const onCartActionComplete = useCallback((context, event) => {
89
87
  const cartActionEvent = event.payload.cartActionEvent;
@@ -7,6 +7,9 @@ function invokeCart(action, options) {
7
7
  return {
8
8
  entry: [
9
9
  ...(options?.entryActions || []),
10
+ assign({
11
+ lastValidCart: (context) => context?.cart,
12
+ }),
10
13
  'onCartActionEntry',
11
14
  'onCartActionOptimisticUI',
12
15
  action,
@@ -16,7 +19,7 @@ function invokeCart(action, options) {
16
19
  target: options?.resolveTarget || 'idle',
17
20
  actions: [
18
21
  assign({
19
- prevCart: (context) => context?.cart,
22
+ prevCart: (context) => context?.lastValidCart,
20
23
  cart: (_, event) => event?.payload?.cart,
21
24
  rawCartResult: (_, event) => event?.payload?.rawCartResult,
22
25
  errors: (_) => undefined,
@@ -27,7 +30,7 @@ function invokeCart(action, options) {
27
30
  target: options?.errorTarget || 'error',
28
31
  actions: [
29
32
  assign({
30
- prevCart: (context) => context?.cart,
33
+ prevCart: (context) => context?.lastValidCart,
31
34
  cart: (context, _) => context?.lastValidCart,
32
35
  errors: (_, event) => event?.payload?.errors,
33
36
  }),
@@ -39,6 +42,7 @@ function invokeCart(action, options) {
39
42
  prevCart: (_) => undefined,
40
43
  cart: (_) => undefined,
41
44
  lastValidCart: (_) => undefined,
45
+ rawCartResult: (_) => undefined,
42
46
  errors: (_) => undefined,
43
47
  }),
44
48
  },
@@ -1 +1 @@
1
- export declare const LIB_VERSION = "1.6.4";
1
+ export declare const LIB_VERSION = "1.6.5";
@@ -1 +1 @@
1
- export const LIB_VERSION = '1.6.4';
1
+ export const LIB_VERSION = '1.6.5';
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "engines": {
8
8
  "node": ">=14"
9
9
  },
10
- "version": "1.6.4",
10
+ "version": "1.6.5",
11
11
  "description": "Modern custom Shopify storefronts",
12
12
  "license": "MIT",
13
13
  "main": "dist/esnext/index.js",