@graphcommerce/magento-customer 11.0.0-canary.46 → 11.0.0-canary.48

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,37 @@
1
1
  # Change Log
2
2
 
3
+ ## 11.0.0-canary.48
4
+
5
+ ### Minor Changes
6
+
7
+ - [#2699](https://github.com/graphcommerce-org/graphcommerce/pull/2699) [`f28586b`](https://github.com/graphcommerce-org/graphcommerce/commit/f28586b061f48cce3f3a70f7ec2c57f13868f8e1) - The packages export the modules that shops import from the package root: the types of `RichText`, `GetAddressesDocument`, `isSameAddress`, `isCartAddressACustomerAddress`, `AvailableShippingMethodFragment`, `AccountAddressFragment`, `CreateCustomerAddressDocument`, `UpdateCustomerAddressDocument`, `ValidatedPasswordElement`, `useCustomizableOptionPrice`, `UseAddProductsToCartActionFragment`, `useProductFiltersProSearchInput`, `useSearchPageAndParam`, `AddWishlistItemToCartProps` and `safeJsonLdReplacer`. ([@bramvanderholst](https://github.com/bramvanderholst))
8
+
9
+ ### Patch Changes
10
+
11
+ - [#2689](https://github.com/graphcommerce-org/graphcommerce/pull/2689) [`8d74a4b`](https://github.com/graphcommerce-org/graphcommerce/commit/8d74a4b333eeff637dfaa1c10dc29a62961afe25) - `useAccountSignInUpForm` goes to the password step after an email submitted with Enter. React Hook Form 7.67 updates `isValid` of an `onBlur` form on blur only, so the form stayed in the email step. ([@bramvanderholst](https://github.com/bramvanderholst))
12
+
13
+ - [#2675](https://github.com/graphcommerce-org/graphcommerce/pull/2675) [`2a76e15`](https://github.com/graphcommerce-org/graphcommerce/commit/2a76e1581e6149f6fa1cf9f3a6513455c8cfa459) - Empty client fields return complete cache results during rendering. Explicit null values clear saved client state. ([@paales](https://github.com/paales))
14
+
15
+ - [#2679](https://github.com/graphcommerce-org/graphcommerce/pull/2679) [`4d0bb18`](https://github.com/graphcommerce-org/graphcommerce/commit/4d0bb1822241d919e2f57495f644afbd4ea3baf2) - Reduce Total Blocking Time by removing synchronous re-renders right after hydration and splitting up startup work:
16
+
17
+ - `usePrivateQuery` no longer uses `useIsSSR()`. Its `useSyncExternalStore` server/client mismatch forced a synchronous re-render of the whole page after hydration, even for guests. Without a private context the mask stays on, which is inert because it only hides content while the `private-query` CSS flag is set.
18
+ - `useCookie(name)` subscribes to a single cookie via `useSyncExternalStore` (server snapshot `null`), so it only re-renders after hydration when that cookie is actually set.
19
+ - `usePrivateQueryContext` (magento-customer plugin) subscribes to the derived `loggedIn` boolean on the Apollo cache instead of the full `CustomerToken` query result, so the page doesn't re-render when the query result object changes but `loggedIn` doesn't.
20
+ - `CssAndFramerMotionProvider` loads framer-motion features after hydration and applies them in `startTransition`, so the re-render of all `m` components is time-sliced and the features stay out of the startup bundle.
21
+ - Examples: `ThemeProvider` uses `noSsr`, avoiding MUI's color scheme provider re-rendering every styled component after hydration (`colorSchemeSelector: 'class'` already handles the color scheme in CSS before paint).
22
+ - Examples: added `patch-package` patches for `next@16.2.6` (Pages Router hydrates inside `startTransition`, like the App Router; the route loader yields between `_app` and page instantiation) and `react-hook-form@7.67.0` (only set `formState.isReady` when it is subscribed to; the unconditional update re-rendered every form synchronously after mount).
23
+ - `ListFormat` renders a single item directly instead of creating an `Intl.ListFormat`, which loads its locale data on first use. The store switcher in the header rendered one item on every page; this cut ~12–18% of TBT at 4× CPU throttling.
24
+ - `useElementScroll` no longer measures `scrollWidth` synchronously in its layout effect, which forced a style recalc and layout of the whole page during the hydration commit. It measures in framer-motion's read step instead; the ResizeObserver also delivers an initial observation.
25
+ - `framer-utils` uses framer-motion's `frame` instead of `framesync`, and `framer-scroller` loads `popmotion` on demand (only needed after user interaction). Together ~53 KB raw of JS out of the startup bundle. ([@paales](https://github.com/paales))
26
+
27
+ - [#2676](https://github.com/graphcommerce-org/graphcommerce/pull/2676) [`9496f0b`](https://github.com/graphcommerce-org/graphcommerce/commit/9496f0bdcb751c5f7d774ebe961d86347a8beae8) - Cached null customer results remain complete for server queries. ([@paales](https://github.com/paales))
28
+
29
+ ## 11.0.0-canary.47
30
+
31
+ ### Patch Changes
32
+
33
+ - [#2659](https://github.com/graphcommerce-org/graphcommerce/pull/2659) [`e7fe659`](https://github.com/graphcommerce-org/graphcommerce/commit/e7fe65994325510863afb526e8b2caaeba5e66f1) - Support the Magento 2.4.9 guest-order lookup, which renamed the `guestOrder` argument type `OrderInformationInput` → `GuestOrderInformationInput` and swapped the `postcode` lookup field for `lastname`. The `GuestOrder` query and the guest order form now use the new type/field, and `schema-249` re-declares `guestOrder(input: GuestOrderInformationInput!)` so operations keep validating on older backends via the mesh version shim. ([@paales](https://github.com/paales))
34
+
3
35
  ## 11.0.0-canary.46
4
36
 
5
37
  ## 11.0.0-canary.45
@@ -1,4 +1,4 @@
1
- query GuestOrder($input: OrderInformationInput!) {
1
+ query GuestOrder($input: GuestOrderInformationInput!) {
2
2
  guestOrder(input: $input) {
3
3
  ...OrderDetails
4
4
  ...OrderItems
@@ -66,10 +66,10 @@ export function GuestOrderOverviewForm() {
66
66
  <EmailElement control={control} name='input.email' required />
67
67
  <TextFieldElement
68
68
  control={control}
69
- name='input.postcode'
69
+ name='input.lastname'
70
70
  required
71
- label={<Trans>Postcode</Trans>}
72
- autoComplete='postal_code'
71
+ label={<Trans>Last name</Trans>}
72
+ autoComplete='family-name'
73
73
  />
74
74
  </FormRow>
75
75
 
@@ -1,4 +1,5 @@
1
1
  export * from './AccountAddress/AccountAddress'
2
+ export * from './AccountAddress/AccountAddress.gql'
2
3
  export * from './AccountAddresses/AccountAddresses'
3
4
  export * from './AccountAddresses/AccountAddresses.gql'
4
5
  export * from './AccountDeleteForm/AccountDeleteForm'
@@ -18,6 +19,7 @@ export * from './ChangePasswordForm/ChangePasswordForm'
18
19
  export * from './CompanyFields'
19
20
  export * from './ConfirmCustomer/ConfirmCustomerForm'
20
21
  export * from './ContactForm/ContactForm'
22
+ export * from './CreateCustomerAddressForm/CreateCustomerAddress.gql'
21
23
  export * from './CreateCustomerAddressForm/CreateCustomerAddressForm'
22
24
  export * from './CreateCustomerAddressForm/CustomerAddress.gql'
23
25
  export * from './CreditMemo'
@@ -26,6 +28,7 @@ export * from './CustomerForms'
26
28
  export * from './CustomerMenuFabItem/CustomerMenuFabItem'
27
29
  export * from './DeleteCustomerAddressForm/DeleteCustomerAddressForm'
28
30
  export * from './EditAddressForm/EditAddressForm'
31
+ export * from './EditAddressForm/UpdateCustomerAddress.gql'
29
32
  export * from './ForgotPasswordForm/ForgotPassword.gql'
30
33
  export * from './ForgotPasswordForm/ForgotPasswordForm'
31
34
  export * from './GuestOrCustomerMask/GuestOrCustomerMask'
@@ -46,4 +49,5 @@ export * from './SignUpForm/SignUpForm'
46
49
  export * from './SignUpForm/SignUpFormInline'
47
50
  export * from './UpdateCustomerEmailForm/UpdateCustomerEmailForm'
48
51
  export * from './UpdateDefaultAddressForm/UpdateDefaultAddressForm'
52
+ export * from './ValidatedPasswordElement/ValidatedPasswordElement'
49
53
  export * from './WaitForCustomer/WaitForCustomer'
@@ -0,0 +1,38 @@
1
+ // @vitest-environment happy-dom
2
+ import type * as ReactHookForm from '@graphcommerce/react-hook-form'
3
+ import { act, renderHook } from '@testing-library/react'
4
+ import { describe, expect, it, vi } from 'vitest'
5
+ import { useAccountSignInUpForm } from './useAccountSignInUpForm'
6
+
7
+ vi.mock('@graphcommerce/next-config/config', () => ({ enableGuestCheckoutLogin: true }))
8
+ vi.mock('@graphcommerce/framer-next-pages', () => ({ usePageContext: () => undefined }))
9
+ vi.mock('@graphcommerce/next-ui', () => ({ useUrlQuery: () => [{}, async () => {}] }))
10
+ vi.mock('@graphcommerce/graphql', () => ({ useQuery: () => ({ data: undefined }) }))
11
+ vi.mock('./useCustomerPermissions', () => ({ useCustomerAccountCanSignUp: () => true }))
12
+ vi.mock('./useCustomerSession', () => ({
13
+ useCustomerSession: () => ({ token: undefined, valid: false }),
14
+ }))
15
+ vi.mock('@graphcommerce/react-hook-form', async () => {
16
+ const rhf = await vi.importActual<typeof ReactHookForm>('react-hook-form')
17
+ return {
18
+ useWatch: rhf.useWatch,
19
+ useFormGqlQuery: (_document: unknown, options: Parameters<typeof rhf.useForm>[0]) => ({
20
+ ...rhf.useForm(options),
21
+ data: { isEmailAvailable: { is_email_available: false } },
22
+ }),
23
+ }
24
+ })
25
+
26
+ describe('useAccountSignInUpForm', () => {
27
+ it('shows the password step after an email submitted with Enter', async () => {
28
+ const { result } = renderHook(() => useAccountSignInUpForm())
29
+
30
+ const email = result.current.form.register('email', { required: true })
31
+ await act(() =>
32
+ email.onChange({ target: { name: 'email', value: 'a@example.com' }, type: 'change' }),
33
+ )
34
+ await act(() => result.current.submit())
35
+
36
+ expect(result.current.mode).toBe('signin')
37
+ })
38
+ })
@@ -41,7 +41,7 @@ export function useAccountSignInUpForm(props: UseFormIsEmailAvailableProps = {})
41
41
  { fetchPolicy: 'cache-and-network' },
42
42
  )
43
43
  const { formState, data, handleSubmit, setValue, trigger, control } = form
44
- const { isSubmitSuccessful, isValid } = formState
44
+ const { isSubmitSuccessful, errors } = formState
45
45
  const requestedMode = useWatch({ control, name: 'requestedMode' })
46
46
 
47
47
  useEffect(() => {
@@ -74,7 +74,7 @@ export function useAccountSignInUpForm(props: UseFormIsEmailAvailableProps = {})
74
74
  // 1. Nothing is entered
75
75
  mode = 'email'
76
76
 
77
- if (isValid && isSubmitSuccessful) mode = hasAccount ? 'signin' : 'signup'
77
+ if (isSubmitSuccessful && !errors.email) mode = hasAccount ? 'signin' : 'signup'
78
78
  }
79
79
 
80
80
  const { closeSteps = 0 } = usePageContext() ?? {}
package/index.test.ts ADDED
@@ -0,0 +1,27 @@
1
+ import { fileURLToPath } from 'node:url'
2
+ import ts from 'typescript'
3
+
4
+ it('exports the modules that a shop imports', () => {
5
+ const root = fileURLToPath(new URL('.', import.meta.url))
6
+ const files = ts.sys
7
+ .readDirectory(root, ['.ts', '.tsx'])
8
+ .filter((file) => !file.includes('/node_modules/') && !/\.test\.tsx?$/.test(file))
9
+ const program = ts.createProgram(files, {
10
+ noEmit: true,
11
+ noResolve: true,
12
+ jsx: ts.JsxEmit.ReactJSX,
13
+ })
14
+ const checker = program.getTypeChecker()
15
+ const index = program.getSourceFile(`${root}index.ts`)
16
+ const moduleSymbol = index && checker.getSymbolAtLocation(index)
17
+ const exported = moduleSymbol ? checker.getExportsOfModule(moduleSymbol).map((s) => s.name) : []
18
+
19
+ expect(exported).toEqual(
20
+ expect.arrayContaining([
21
+ 'AccountAddressFragment',
22
+ 'CreateCustomerAddressDocument',
23
+ 'UpdateCustomerAddressDocument',
24
+ 'ValidatedPasswordElement',
25
+ ]),
26
+ )
27
+ })
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": "11.0.0-canary.46",
5
+ "version": "11.0.0-canary.48",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -21,20 +21,20 @@
21
21
  "./plugins/magentoCustomerPrivateQueryContext": "./plugins/magentoCustomerPrivateQueryContext.ts"
22
22
  },
23
23
  "peerDependencies": {
24
- "@graphcommerce/ecommerce-ui": "^11.0.0-canary.46",
25
- "@graphcommerce/eslint-config-pwa": "^11.0.0-canary.46",
26
- "@graphcommerce/framer-next-pages": "^11.0.0-canary.46",
27
- "@graphcommerce/framer-utils": "^11.0.0-canary.46",
28
- "@graphcommerce/graphql": "^11.0.0-canary.46",
29
- "@graphcommerce/graphql-mesh": "^11.0.0-canary.46",
30
- "@graphcommerce/image": "^11.0.0-canary.46",
31
- "@graphcommerce/magento-graphql": "^11.0.0-canary.46",
32
- "@graphcommerce/magento-store": "^11.0.0-canary.46",
33
- "@graphcommerce/next-config": "^11.0.0-canary.46",
34
- "@graphcommerce/next-ui": "^11.0.0-canary.46",
35
- "@graphcommerce/prettier-config-pwa": "^11.0.0-canary.46",
36
- "@graphcommerce/react-hook-form": "^11.0.0-canary.46",
37
- "@graphcommerce/typescript-config-pwa": "^11.0.0-canary.46",
24
+ "@graphcommerce/ecommerce-ui": "^11.0.0-canary.48",
25
+ "@graphcommerce/eslint-config-pwa": "^11.0.0-canary.48",
26
+ "@graphcommerce/framer-next-pages": "^11.0.0-canary.48",
27
+ "@graphcommerce/framer-utils": "^11.0.0-canary.48",
28
+ "@graphcommerce/graphql": "^11.0.0-canary.48",
29
+ "@graphcommerce/graphql-mesh": "^11.0.0-canary.48",
30
+ "@graphcommerce/image": "^11.0.0-canary.48",
31
+ "@graphcommerce/magento-graphql": "^11.0.0-canary.48",
32
+ "@graphcommerce/magento-store": "^11.0.0-canary.48",
33
+ "@graphcommerce/next-config": "^11.0.0-canary.48",
34
+ "@graphcommerce/next-ui": "^11.0.0-canary.48",
35
+ "@graphcommerce/prettier-config-pwa": "^11.0.0-canary.48",
36
+ "@graphcommerce/react-hook-form": "^11.0.0-canary.48",
37
+ "@graphcommerce/typescript-config-pwa": "^11.0.0-canary.48",
38
38
  "@lingui/core": "^5",
39
39
  "@lingui/macro": "^5",
40
40
  "@lingui/react": "^5",
@@ -1,12 +1,32 @@
1
1
  import {
2
+ useApolloClient,
2
3
  type getPrivateQueryContextMesh as getPrivateQueryContextMeshType,
3
4
  type getPrivateQueryContext as getPrivateQueryContextType,
4
5
  type usePrivateQueryContext as usePrivateQueryContextType,
5
6
  } from '@graphcommerce/graphql'
6
7
  import type { PrivateContext } from '@graphcommerce/graphql-mesh'
7
8
  import type { FunctionPlugin, PluginConfig } from '@graphcommerce/next-config'
9
+ import { useCallback, useSyncExternalStore } from 'react'
8
10
  import { CustomerTokenDocument } from '../hooks/CustomerToken.gql'
9
- import { useCustomerSession } from '../hooks/useCustomerSession'
11
+
12
+ /**
13
+ * Subscribe to the derived `loggedIn` boolean only. Reading the full CustomerToken query result
14
+ * would re-render the calling page whenever the query object changes (e.g. loading → cached result
15
+ * right after hydration), even when `loggedIn` itself doesn't change.
16
+ */
17
+ function useIsLoggedIn() {
18
+ const { cache } = useApolloClient()
19
+ const subscribe = useCallback(
20
+ (onChange: () => void) =>
21
+ cache.watch({ query: CustomerTokenDocument, optimistic: true, callback: () => onChange() }),
22
+ [cache],
23
+ )
24
+ return useSyncExternalStore(
25
+ subscribe,
26
+ () => !!cache.readQuery({ query: CustomerTokenDocument })?.customerToken?.token,
27
+ () => false,
28
+ )
29
+ }
10
30
 
11
31
  export const config: PluginConfig = {
12
32
  type: 'function',
@@ -38,7 +58,7 @@ export const usePrivateQueryContext: FunctionPlugin<typeof usePrivateQueryContex
38
58
  prev,
39
59
  ...args
40
60
  ) => {
41
- const { loggedIn } = useCustomerSession()
61
+ const loggedIn = useIsLoggedIn()
42
62
  const res = prev(...args)
43
63
  if (!loggedIn) return res
44
64
  return { ...res, loggedIn: true }
package/typePolicies.ts CHANGED
@@ -5,14 +5,9 @@ import { CustomerTokenDocument } from './hooks/CustomerToken.gql'
5
5
  const generateCustomerToken: FieldPolicy<Mutation['generateCustomerToken']> = {
6
6
  keyArgs: () => '',
7
7
  merge(_existing, incoming, options) {
8
- console.log('[generateCustomerToken] merge called', {
9
- isReference: options.isReference(incoming),
10
- incoming,
11
- })
12
8
  if (!options.isReference(incoming)) return incoming
13
9
 
14
10
  const token = options.readField('token', incoming) as string
15
- console.log('[generateCustomerToken] Writing token to cache:', token?.substring(0, 20))
16
11
 
17
12
  options.cache.writeQuery({
18
13
  query: CustomerTokenDocument,
@@ -28,10 +23,6 @@ const generateCustomerToken: FieldPolicy<Mutation['generateCustomerToken']> = {
28
23
  },
29
24
  })
30
25
 
31
- // Verify write
32
- const verify = options.cache.readQuery({ query: CustomerTokenDocument })
33
- console.log('[generateCustomerToken] Verify after write:', verify)
34
-
35
26
  return incoming
36
27
  },
37
28
  }
@@ -39,8 +30,13 @@ const generateCustomerToken: FieldPolicy<Mutation['generateCustomerToken']> = {
39
30
  export const customerTypePolicies: StrictTypedTypePolicies = {
40
31
  Query: {
41
32
  fields: {
42
- // https://github.com/apollographql/apollo-client/issues/12930
43
- customerToken: { merge: (existing, incoming) => incoming ?? existing },
33
+ customerToken: { read: (existing) => existing ?? null },
34
+ customer: {
35
+ read: (existing, { field }) =>
36
+ existing === undefined && field?.directives?.some((d) => d.name.value === 'client')
37
+ ? null
38
+ : existing,
39
+ },
44
40
  },
45
41
  },
46
42
  Mutation: { fields: { generateCustomerToken } },
@@ -48,7 +44,7 @@ export const customerTypePolicies: StrictTypedTypePolicies = {
48
44
 
49
45
  export const migrateCustomer: MigrateCache = (oldCache, newCache) => {
50
46
  const token = oldCache.readQuery({ query: CustomerTokenDocument })
51
- if (token) {
47
+ if (token?.customerToken) {
52
48
  newCache.writeQuery({ query: CustomerTokenDocument, data: token, broadcast: true })
53
49
  }
54
50
  }