@graphcommerce/magento-cart-payment-method 10.1.0-canary.7 → 11.0.0-canary.45

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/CHANGELOG.md CHANGED
@@ -1,5 +1,87 @@
1
1
  # Change Log
2
2
 
3
+ ## 11.0.0-canary.45
4
+
5
+ ## 10.1.0-canary.44
6
+
7
+ ## 10.1.0-canary.43
8
+
9
+ ### Patch Changes
10
+
11
+ - [#2667](https://github.com/graphcommerce-org/graphcommerce/pull/2667) [`6ee8488`](https://github.com/graphcommerce-org/graphcommerce/commit/6ee84883ece679b4fd4ed191ecd00a9ec39cc206) - Give `useClearCurrentCartId()` and `useCartLock()`'s `lock`/`unlock` a stable function identity, so consumers can list them in a `useEffect` dependency array without the effect re-running on every render.
12
+
13
+ `useClearCurrentCartId` returned a bare arrow function and `useCartLock` defined `lock`/`unlock` inline, while the neighbouring `useAssignCurrentCartId` already returned a `useCallback`. `useClearCurrentCartId` now uses `useCallback` with the Apollo `cache` as its only dependency (matching `useAssignCurrentCartId`), and `lock`/`unlock` use `useEventCallback` because they read values that legitimately change (`currentCartId`, the router query state and the Apollo client) — `useEventCallback` keeps the identity stable while always reading the latest values, so no stale closure is introduced. ([@paales](https://github.com/paales))
14
+
15
+ ## 10.1.0-canary.42
16
+
17
+ ## 10.1.0-canary.41
18
+
19
+ ## 10.1.0-canary.40
20
+
21
+ ## 10.1.0-canary.39
22
+
23
+ ## 10.1.0-canary.38
24
+
25
+ ## 10.1.0-canary.37
26
+
27
+ ## 10.1.0-canary.36
28
+
29
+ ## 10.1.0-canary.35
30
+
31
+ ## 10.1.0-canary.34
32
+
33
+ ## 10.1.0-canary.33
34
+
35
+ ## 10.1.0-canary.32
36
+
37
+ ## 10.1.0-canary.31
38
+
39
+ ## 10.1.0-canary.30
40
+
41
+ ## 10.1.0-canary.29
42
+
43
+ ## 10.1.0-canary.28
44
+
45
+ ## 10.1.0-canary.27
46
+
47
+ ## 10.1.0-canary.26
48
+
49
+ ## 10.1.0-canary.25
50
+
51
+ ## 10.1.0-canary.24
52
+
53
+ ## 10.1.0-canary.23
54
+
55
+ ## 10.1.0-canary.22
56
+
57
+ ## 10.1.0-canary.21
58
+
59
+ ## 10.1.0-canary.20
60
+
61
+ ## 10.1.0-canary.19
62
+
63
+ ## 10.1.0-canary.18
64
+
65
+ ## 10.1.0-canary.17
66
+
67
+ ## 10.1.0-canary.16
68
+
69
+ ## 10.1.0-canary.15
70
+
71
+ ## 10.1.0-canary.14
72
+
73
+ ## 10.1.0-canary.13
74
+
75
+ ## 10.1.0-canary.12
76
+
77
+ ## 10.1.0-canary.11
78
+
79
+ ## 10.1.0-canary.10
80
+
81
+ ## 10.1.0-canary.9
82
+
83
+ ## 10.1.0-canary.8
84
+
3
85
  ## 10.1.0-canary.7
4
86
 
5
87
  ## 10.1.0-canary.6
@@ -1,6 +1,7 @@
1
1
  import { useApolloClient } from '@graphcommerce/graphql'
2
2
  import { cartLock, useCurrentCartId } from '@graphcommerce/magento-cart'
3
3
  import { useUrlQuery } from '@graphcommerce/next-ui'
4
+ import { useEventCallback } from '@mui/material'
4
5
  import { useEffect, useState } from 'react'
5
6
 
6
7
  export type CartLockState = {
@@ -37,7 +38,13 @@ export function useCartLock<E extends CartLockState>() {
37
38
  }
38
39
  })
39
40
 
40
- const lock = (params: Omit<E, 'locked' | 'cart_id'>) => {
41
+ /**
42
+ * `lock` and `unlock` are wrapped in `useEventCallback` so they keep a stable identity across
43
+ * renders while still reading the latest `currentCartId`, `queryState` and `client`. This allows
44
+ * consumers to add them to their `useEffect` dependency arrays without re-running the effect on
45
+ * every render.
46
+ */
47
+ const lock = useEventCallback((params: Omit<E, 'locked' | 'cart_id'>) => {
41
48
  if (!currentCartId) return undefined
42
49
  justLocked = true
43
50
  cartLock(client.cache, true)
@@ -46,13 +53,13 @@ export function useCartLock<E extends CartLockState>() {
46
53
  cart_id: currentCartId,
47
54
  ...params,
48
55
  } as unknown as E)
49
- }
56
+ })
50
57
 
51
- const unlock = async (params: Omit<E, 'locked' | 'cart_id' | 'method'>) => {
58
+ const unlock = useEventCallback(async (params: Omit<E, 'locked' | 'cart_id' | 'method'>) => {
52
59
  cartLock(client.cache, false)
53
60
  await setRouterQuery({ cart_id: null, locked: null, method: null, ...params } as E)
54
61
  return queryState
55
- }
62
+ })
56
63
 
57
64
  const resulting: Omit<E, 'locked'> & { locked: boolean; justLocked: boolean } = {
58
65
  ...queryState,
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/magento-cart-payment-method",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "10.1.0-canary.7",
5
+ "version": "11.0.0-canary.45",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -18,18 +18,18 @@
18
18
  "./PaymentMethodPlaceOrderNoop/PaymentMethodPlaceOrderNoop": "./PaymentMethodPlaceOrderNoop/PaymentMethodPlaceOrderNoop.tsx"
19
19
  },
20
20
  "peerDependencies": {
21
- "@graphcommerce/ecommerce-ui": "^10.1.0-canary.7",
22
- "@graphcommerce/eslint-config-pwa": "^10.1.0-canary.7",
23
- "@graphcommerce/framer-scroller": "^10.1.0-canary.7",
24
- "@graphcommerce/graphql": "^10.1.0-canary.7",
25
- "@graphcommerce/image": "^10.1.0-canary.7",
26
- "@graphcommerce/magento-cart": "^10.1.0-canary.7",
27
- "@graphcommerce/magento-cart-shipping-address": "^10.1.0-canary.7",
28
- "@graphcommerce/magento-store": "^10.1.0-canary.7",
29
- "@graphcommerce/next-ui": "^10.1.0-canary.7",
30
- "@graphcommerce/prettier-config-pwa": "^10.1.0-canary.7",
31
- "@graphcommerce/react-hook-form": "^10.1.0-canary.7",
32
- "@graphcommerce/typescript-config-pwa": "^10.1.0-canary.7",
21
+ "@graphcommerce/ecommerce-ui": "^11.0.0-canary.45",
22
+ "@graphcommerce/eslint-config-pwa": "^11.0.0-canary.45",
23
+ "@graphcommerce/framer-scroller": "^11.0.0-canary.45",
24
+ "@graphcommerce/graphql": "^11.0.0-canary.45",
25
+ "@graphcommerce/image": "^11.0.0-canary.45",
26
+ "@graphcommerce/magento-cart": "^11.0.0-canary.45",
27
+ "@graphcommerce/magento-cart-shipping-address": "^11.0.0-canary.45",
28
+ "@graphcommerce/magento-store": "^11.0.0-canary.45",
29
+ "@graphcommerce/next-ui": "^11.0.0-canary.45",
30
+ "@graphcommerce/prettier-config-pwa": "^11.0.0-canary.45",
31
+ "@graphcommerce/react-hook-form": "^11.0.0-canary.45",
32
+ "@graphcommerce/typescript-config-pwa": "^11.0.0-canary.45",
33
33
  "@lingui/core": "^5",
34
34
  "@lingui/macro": "^5",
35
35
  "@lingui/react": "^5",