@graphcommerce/magento-customer 4.7.2 → 4.8.0

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,21 @@
1
1
  # Change Log
2
2
 
3
+ ## 4.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#1553](https://github.com/graphcommerce-org/graphcommerce/pull/1553) [`03d01c06c`](https://github.com/graphcommerce-org/graphcommerce/commit/03d01c06c6dc13df8d38ab5b40bd100c567a9e8d) Thanks [@NickdeK](https://github.com/NickdeK)! - Added a `{ hydrate: boolean }` option to `useCartQuery`, `useCurrentCartId`, `useCustomerQuery` and `useCustomerSession` to allow for data during the hydration phase. This can cause hydration warnings, but prevents an additional rerender.
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [[`1afc6a547`](https://github.com/graphcommerce-org/graphcommerce/commit/1afc6a5473d6e31f47b5d0188801803b31865290), [`4a4579bb2`](https://github.com/graphcommerce-org/graphcommerce/commit/4a4579bb2f7da378f3fcc504405caf2560dc10f6), [`afcd8e4bf`](https://github.com/graphcommerce-org/graphcommerce/commit/afcd8e4bfb7010da4d5faeed85b61991ed7975f4), [`02e1988e5`](https://github.com/graphcommerce-org/graphcommerce/commit/02e1988e5f361c6f66ae30d3bbee38ef2ac062df), [`323fdee4b`](https://github.com/graphcommerce-org/graphcommerce/commit/323fdee4b15ae23e0e84dd0588cb2c6446dcfd50)]:
12
+ - @graphcommerce/graphql@3.4.2
13
+ - @graphcommerce/react-hook-form@3.3.1
14
+ - @graphcommerce/next-ui@4.14.0
15
+ - @graphcommerce/ecommerce-ui@1.1.3
16
+ - @graphcommerce/magento-graphql@3.1.2
17
+ - @graphcommerce/magento-store@4.2.18
18
+
3
19
  ## 4.7.2
4
20
 
5
21
  ### Patch Changes
@@ -19,9 +19,10 @@ const notLoggedInError = new ApolloError({
19
19
  /** Will only execute when the customer is signed in. */
20
20
  export function useCustomerQuery<Q, V>(
21
21
  document: TypedDocumentNode<Q, V>,
22
- queryOptions: QueryHookOptions<Q, V> = {},
22
+ options: QueryHookOptions<Q, V> & { hydration?: boolean } = {},
23
23
  ): QueryResult<Q, V> {
24
- const { loggedIn, called } = useCustomerSession()
24
+ const { hydration, ...queryOptions } = options
25
+ const { loggedIn, called } = useCustomerSession({ hydration })
25
26
 
26
27
  const result = useQuery(document, {
27
28
  ...queryOptions,
@@ -3,28 +3,27 @@ import { useQuery } from '@graphcommerce/graphql'
3
3
  import { useState } from 'react'
4
4
  import { CustomerTokenDocument, CustomerTokenQuery } from './CustomerToken.gql'
5
5
 
6
- type TokenResponse = Omit<NonNullable<CustomerTokenQuery['customerToken']>, '__typename'> & {
7
- called: boolean
8
- }
6
+ export type UseCustomerSessionOptions = { hydration?: boolean }
9
7
 
10
8
  export type UseCustomerSessionReturn =
11
- | Partial<TokenResponse> & { loggedIn: boolean; requireAuth: boolean }
12
-
13
- export function useCustomerSession(): UseCustomerSessionReturn {
14
- const [skip, setSkip] = useState(true)
15
-
16
- const { called, data } = useQuery(CustomerTokenDocument, {
17
- ssr: false,
18
- fetchPolicy: 'cache-only',
19
- skip,
20
- })
9
+ | Partial<
10
+ Omit<NonNullable<CustomerTokenQuery['customerToken']>, '__typename'> & {
11
+ called: boolean
12
+ }
13
+ > & { loggedIn: boolean; requireAuth: boolean }
14
+
15
+ export function useCustomerSession(
16
+ options: UseCustomerSessionOptions = {},
17
+ ): UseCustomerSessionReturn {
18
+ const { hydration = true } = options
19
+ const [hydrating, setHydrating] = useState(!hydration)
20
+ useIsomorphicLayoutEffect(() => setHydrating(false), [])
21
+ const skip = hydrating
22
+
23
+ const { called, data } = useQuery(CustomerTokenDocument, { skip })
21
24
 
22
25
  const token = data?.customerToken
23
26
 
24
- useIsomorphicLayoutEffect(() => {
25
- if (skip) setSkip(false)
26
- }, [skip])
27
-
28
27
  if (!token) return { called, loggedIn: false, requireAuth: true }
29
28
 
30
29
  return {
@@ -1,4 +1,4 @@
1
- import { useFormAutoSubmit, useFormGqlQuery, useFormPersist } from '@graphcommerce/react-hook-form'
1
+ import { useFormAutoSubmit, useFormGqlQuery } from '@graphcommerce/react-hook-form'
2
2
  import { useEffect, useState } from 'react'
3
3
  import { CustomerDocument } from './Customer.gql'
4
4
  import { IsEmailAvailableDocument } from './IsEmailAvailable.gql'
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/magento-customer",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "4.7.2",
5
+ "version": "4.8.0",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -19,15 +19,15 @@
19
19
  "type-fest": "^2.12.2"
20
20
  },
21
21
  "dependencies": {
22
- "@graphcommerce/ecommerce-ui": "1.1.2",
22
+ "@graphcommerce/ecommerce-ui": "1.1.3",
23
23
  "@graphcommerce/framer-utils": "3.1.4",
24
- "@graphcommerce/graphql": "3.4.1",
24
+ "@graphcommerce/graphql": "3.4.2",
25
25
  "@graphcommerce/graphql-mesh": "4.1.5",
26
26
  "@graphcommerce/image": "3.1.7",
27
- "@graphcommerce/magento-graphql": "3.1.1",
28
- "@graphcommerce/magento-store": "4.2.17",
29
- "@graphcommerce/next-ui": "4.13.1",
30
- "@graphcommerce/react-hook-form": "3.3.0"
27
+ "@graphcommerce/magento-graphql": "3.1.2",
28
+ "@graphcommerce/magento-store": "4.2.18",
29
+ "@graphcommerce/next-ui": "4.14.0",
30
+ "@graphcommerce/react-hook-form": "3.3.1"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "@lingui/react": "^3.13.2",