@shopify/hydrogen 1.6.4 → 1.6.6
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.
- package/dist/esnext/components/CartProvider/CartProvider.client.js +5 -7
- package/dist/esnext/components/CartProvider/useCartAPIStateMachine.client.js +6 -2
- package/dist/esnext/foundation/Analytics/ClientAnalytics.js +10 -5
- package/dist/esnext/version.d.ts +1 -1
- package/dist/esnext/version.js +1 -1
- package/package.json +1 -1
|
@@ -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
|
|
56
|
-
return {
|
|
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
|
|
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
|
|
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 {
|
|
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?.
|
|
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?.
|
|
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
|
},
|
|
@@ -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
|
|
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,
|
|
44
|
-
|
|
45
|
-
|
|
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));
|
package/dist/esnext/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const LIB_VERSION = "1.6.
|
|
1
|
+
export declare const LIB_VERSION = "1.6.6";
|
package/dist/esnext/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const LIB_VERSION = '1.6.
|
|
1
|
+
export const LIB_VERSION = '1.6.6';
|