@graphcommerce/magento-cart 4.4.8 → 4.5.2

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,50 @@
1
1
  # Change Log
2
2
 
3
+ ## 4.5.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`18054c441`](https://github.com/graphcommerce-org/graphcommerce/commit/18054c441962ba750bed3acc39ab46c8d3a341ce), [`c5c539c44`](https://github.com/graphcommerce-org/graphcommerce/commit/c5c539c44eeac524cd62ce649e132d2e00333794), [`6f69bc54c`](https://github.com/graphcommerce-org/graphcommerce/commit/6f69bc54c6e0224452817c532ae58d9c332b61ea), [`21886d6fa`](https://github.com/graphcommerce-org/graphcommerce/commit/21886d6fa64a48d9e932bfaf8d138c9b13c36e43), [`b4936e961`](https://github.com/graphcommerce-org/graphcommerce/commit/b4936e96175fe80717895822e245274db05638bd)]:
8
+ - @graphcommerce/framer-next-pages@3.2.4
9
+ - @graphcommerce/graphql@3.4.1
10
+ - @graphcommerce/magento-customer@4.7.2
11
+ - @graphcommerce/next-ui@4.13.1
12
+ - @graphcommerce/framer-scroller@2.1.23
13
+ - @graphcommerce/ecommerce-ui@1.1.2
14
+ - @graphcommerce/magento-graphql@3.1.1
15
+ - @graphcommerce/magento-store@4.2.17
16
+
17
+ ## 4.5.1
18
+
19
+ ### Patch Changes
20
+
21
+ - Updated dependencies [[`8d8fda262`](https://github.com/graphcommerce-org/graphcommerce/commit/8d8fda2623e561cb43441110c67ffa34b692668a), [`d41cff721`](https://github.com/graphcommerce-org/graphcommerce/commit/d41cff7211230561ceeb7786cf75790efd6377cd), [`cefa7b365`](https://github.com/graphcommerce-org/graphcommerce/commit/cefa7b3652b55108d2178927e3c5d98a111cf373), [`584b683a2`](https://github.com/graphcommerce-org/graphcommerce/commit/584b683a2aedcdf5067644c8dcc0e63a5b9e894c)]:
22
+ - @graphcommerce/next-ui@4.13.0
23
+ - @graphcommerce/magento-store@4.2.16
24
+ - @graphcommerce/framer-scroller@2.1.22
25
+ - @graphcommerce/ecommerce-ui@1.1.1
26
+ - @graphcommerce/magento-customer@4.7.1
27
+
28
+ ## 4.5.0
29
+
30
+ ### Minor Changes
31
+
32
+ - [#1544](https://github.com/graphcommerce-org/graphcommerce/pull/1544) [`5f927ebdc`](https://github.com/graphcommerce-org/graphcommerce/commit/5f927ebdc6f0331833e02b96e4f169bfe475ac6b) Thanks [@mikekeehnen](https://github.com/mikekeehnen)! - Fixed hydration errors on account, cart and wishlist
33
+
34
+ ### Patch Changes
35
+
36
+ - [#1545](https://github.com/graphcommerce-org/graphcommerce/pull/1545) [`c87a28e7d`](https://github.com/graphcommerce-org/graphcommerce/commit/c87a28e7dad87bffd0bd125ad5fdca65aaa389cc) Thanks [@paales](https://github.com/paales)! - Faster hydration with useLayoutEffect
37
+
38
+ - Updated dependencies [[`5f927ebdc`](https://github.com/graphcommerce-org/graphcommerce/commit/5f927ebdc6f0331833e02b96e4f169bfe475ac6b), [`c87a28e7d`](https://github.com/graphcommerce-org/graphcommerce/commit/c87a28e7dad87bffd0bd125ad5fdca65aaa389cc), [`c756f42e5`](https://github.com/graphcommerce-org/graphcommerce/commit/c756f42e503761a497e4a5a7a02d02141df231c3)]:
39
+ - @graphcommerce/ecommerce-ui@1.1.0
40
+ - @graphcommerce/graphql@3.4.0
41
+ - @graphcommerce/magento-customer@4.7.0
42
+ - @graphcommerce/magento-graphql@3.1.0
43
+ - @graphcommerce/react-hook-form@3.3.0
44
+ - @graphcommerce/next-ui@4.12.0
45
+ - @graphcommerce/magento-store@4.2.15
46
+ - @graphcommerce/framer-scroller@2.1.21
47
+
3
48
  ## 4.4.8
4
49
 
5
50
  ### Patch Changes
@@ -109,15 +109,15 @@ function CartFabContent(props: CartFabContentProps) {
109
109
  * product to the cart. This would mean that it would immediately start executing this query.
110
110
  */
111
111
  export function CartFab(props: CartFabProps) {
112
- const { data } = useCartQuery(CartFabDocument, {
112
+ const { data, loading, called } = useCartQuery(CartFabDocument, {
113
113
  fetchPolicy: 'cache-only',
114
114
  nextFetchPolicy: 'cache-first',
115
115
  })
116
116
  const qty = data?.cart?.total_quantity ?? 0
117
117
 
118
- return (
119
- <NoSsr fallback={<CartFabContent {...props} total_quantity={0} />}>
120
- <CartFabContent total_quantity={qty} {...props} />
121
- </NoSsr>
122
- )
118
+ if (loading || !called) {
119
+ return <CartFabContent {...props} total_quantity={0} />
120
+ }
121
+
122
+ return <CartFabContent total_quantity={qty} {...props} />
123
123
  }
@@ -5,12 +5,12 @@ import { useAssignCurrentCartId } from './useAssignCurrentCartId'
5
5
  import { useCurrentCartId } from './useCurrentCartId'
6
6
 
7
7
  export function useCartIdCreate() {
8
- const cartId = useCurrentCartId()
8
+ const { currentCartId } = useCurrentCartId()
9
9
  const [create] = useMutation(CreateEmptyCartDocument)
10
10
  const assignCurrentCartId = useAssignCurrentCartId()
11
11
 
12
12
  return async (): Promise<string> => {
13
- if (cartId) return cartId
13
+ if (currentCartId) return currentCartId
14
14
 
15
15
  const { data } = await create()
16
16
  if (!data?.createEmptyCart) throw Error(i18n._(/* i18n */ 'Could not create an empty cart'))
@@ -1,5 +1,6 @@
1
1
  import { useQuery, TypedDocumentNode, QueryHookOptions } from '@graphcommerce/graphql'
2
2
  import { useRouter } from 'next/router'
3
+ import { useEffect, useState } from 'react'
3
4
  import { useCurrentCartId } from './useCurrentCartId'
4
5
 
5
6
  /**
@@ -17,12 +18,10 @@ export function useCartQuery<Q, V extends { cartId: string; [index: string]: unk
17
18
  options: QueryHookOptions<Q, Omit<V, 'cartId'>> & { allowUrl?: boolean } = {},
18
19
  ) {
19
20
  const { allowUrl = true, ...queryOptions } = options
20
-
21
21
  const router = useRouter()
22
- const currentCartId = useCurrentCartId()
22
+ const { currentCartId } = useCurrentCartId()
23
23
  const urlCartId = router.query.cart_id
24
24
  const usingUrl = allowUrl && typeof urlCartId === 'string'
25
-
26
25
  const cartId = usingUrl ? urlCartId : currentCartId
27
26
 
28
27
  if (usingUrl && typeof queryOptions.fetchPolicy === 'undefined')
@@ -1,6 +1,23 @@
1
- import { useQuery } from '@graphcommerce/graphql'
2
- import { CurrentCartIdDocument } from './CurrentCartId.gql'
1
+ import { useIsomorphicLayoutEffect } from '@graphcommerce/framer-utils'
2
+ import { QueryHookOptions, useQuery } from '@graphcommerce/graphql'
3
+ import { useState } from 'react'
4
+ import { CurrentCartIdDocument, CurrentCartIdQuery } from './CurrentCartId.gql'
3
5
 
4
- export function useCurrentCartId() {
5
- return useQuery(CurrentCartIdDocument, { ssr: false }).data?.currentCartId?.id ?? undefined
6
+ export function useCurrentCartId<Q, V>(
7
+ options: QueryHookOptions<Q & Pick<CurrentCartIdQuery, 'currentCartId'>, Omit<V, 'skip'>> = {},
8
+ ) {
9
+ const [skip, setSkip] = useState(true)
10
+ const { data, ...queryResults } = useQuery(CurrentCartIdDocument, {
11
+ ...options,
12
+ skip,
13
+ })
14
+
15
+ useIsomorphicLayoutEffect(() => {
16
+ if (skip) setSkip(false)
17
+ }, [skip])
18
+
19
+ return {
20
+ currentCartId: data?.currentCartId?.id || '',
21
+ ...queryResults,
22
+ }
6
23
  }
@@ -13,7 +13,7 @@ import { useCurrentCartId } from './useCurrentCartId'
13
13
  * @todo: Implement the assignCustomerToGuestCart when available: https://github.com/magento/magento2/pull/33106
14
14
  */
15
15
  export function useMergeCustomerCart() {
16
- const sourceCartId = useCurrentCartId()
16
+ const { currentCartId } = useCurrentCartId()
17
17
  const assignCurrentCartId = useAssignCurrentCartId()
18
18
  const [merge] = useMutation(UseMergeCustomerCartDocument, { errorPolicy: 'all' })
19
19
 
@@ -27,21 +27,21 @@ export function useMergeCustomerCart() {
27
27
  if (!destinationCartId) return
28
28
 
29
29
  // If the vistor cart is the same as the customer cart, we're done
30
- if (sourceCartId === destinationCartId) return
30
+ if (currentCartId === destinationCartId) return
31
31
 
32
32
  // If there is no visitor cart, assign the customer cart as the current cart
33
- if (!sourceCartId) {
33
+ if (!currentCartId) {
34
34
  assignCurrentCartId(destinationCartId)
35
35
  return
36
36
  }
37
37
 
38
38
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
39
39
  ;(async () => {
40
- const result = await merge({ variables: { sourceCartId, destinationCartId } })
40
+ const result = await merge({ variables: { sourceCartId: currentCartId, destinationCartId } })
41
41
 
42
42
  if (!result.data?.mergeCarts.id) return
43
43
 
44
44
  assignCurrentCartId(result.data?.mergeCarts.id)
45
45
  })()
46
- }, [assignCurrentCartId, sourceCartId, destinationCartId, merge])
46
+ }, [assignCurrentCartId, destinationCartId, merge, currentCartId])
47
47
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/magento-cart",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "4.4.8",
5
+ "version": "4.5.2",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -12,22 +12,23 @@
12
12
  }
13
13
  },
14
14
  "devDependencies": {
15
- "@graphcommerce/eslint-config-pwa": "^4.1.8",
15
+ "@graphcommerce/eslint-config-pwa": "^4.1.9",
16
16
  "@graphcommerce/prettier-config-pwa": "^4.0.6",
17
- "@graphcommerce/typescript-config-pwa": "^4.0.3",
17
+ "@graphcommerce/typescript-config-pwa": "^4.0.4",
18
18
  "@playwright/test": "^1.21.1"
19
19
  },
20
20
  "dependencies": {
21
- "@graphcommerce/ecommerce-ui": "1.0.23",
22
- "@graphcommerce/framer-next-pages": "3.2.3",
23
- "@graphcommerce/framer-scroller": "2.1.20",
24
- "@graphcommerce/graphql": "3.3.0",
21
+ "@graphcommerce/ecommerce-ui": "1.1.2",
22
+ "@graphcommerce/framer-utils": "3.1.4",
23
+ "@graphcommerce/framer-next-pages": "3.2.4",
24
+ "@graphcommerce/framer-scroller": "2.1.23",
25
+ "@graphcommerce/graphql": "3.4.1",
25
26
  "@graphcommerce/image": "3.1.7",
26
- "@graphcommerce/magento-customer": "4.6.3",
27
- "@graphcommerce/magento-graphql": "3.0.15",
28
- "@graphcommerce/magento-store": "4.2.14",
29
- "@graphcommerce/next-ui": "4.11.2",
30
- "@graphcommerce/react-hook-form": "3.2.2"
27
+ "@graphcommerce/magento-customer": "4.7.2",
28
+ "@graphcommerce/magento-graphql": "3.1.1",
29
+ "@graphcommerce/magento-store": "4.2.17",
30
+ "@graphcommerce/next-ui": "4.13.1",
31
+ "@graphcommerce/react-hook-form": "3.3.0"
31
32
  },
32
33
  "peerDependencies": {
33
34
  "@lingui/react": "^3.13.2",