@graphcommerce/graphql 11.0.0-canary.47 → 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,23 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 11.0.0-canary.48
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#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:
|
|
8
|
+
|
|
9
|
+
- `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.
|
|
10
|
+
- `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.
|
|
11
|
+
- `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.
|
|
12
|
+
- `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.
|
|
13
|
+
- 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).
|
|
14
|
+
- 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).
|
|
15
|
+
- `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.
|
|
16
|
+
- `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.
|
|
17
|
+
- `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))
|
|
18
|
+
|
|
19
|
+
- [#2684](https://github.com/graphcommerce-org/graphcommerce/pull/2684) [`f856e98`](https://github.com/graphcommerce-org/graphcommerce/commit/f856e9866db4676fc2f37cdf3ee0105aaad4d4b4) - Queries that watch the cache receive the state that `createCacheReviver` restores from localStorage, so a full page load of the cart or the checkout shows the cart. ([@bramvanderholst](https://github.com/bramvanderholst))
|
|
20
|
+
|
|
3
21
|
## 11.0.0-canary.47
|
|
4
22
|
|
|
5
23
|
## 11.0.0-canary.46
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { gql, InMemoryCache } from '@apollo/client'
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
3
|
+
import { cartTypePolicies } from '../magento-cart/typePolicies'
|
|
4
|
+
import { compareTypePolicies } from '../magento-compare/typePolicies'
|
|
5
|
+
import { customerTypePolicies, migrateCustomer } from '../magento-customer/typePolicies'
|
|
6
|
+
import { recentlyViewedProductsTypePolicies } from '../magento-recently-viewed-products/typePolicies'
|
|
7
|
+
|
|
8
|
+
vi.mock('../magento-cart/hooks', () => ({ readCartId: vi.fn(), writeCartId: vi.fn() }))
|
|
9
|
+
|
|
10
|
+
const cases = [
|
|
11
|
+
{
|
|
12
|
+
field: 'customerToken',
|
|
13
|
+
policies: customerTypePolicies,
|
|
14
|
+
selection: '{ __typename token createdAt valid xMagentoCacheId }',
|
|
15
|
+
value: {
|
|
16
|
+
__typename: 'CustomerToken',
|
|
17
|
+
token: 'test-token',
|
|
18
|
+
createdAt: '2026-01-01T00:00:00Z',
|
|
19
|
+
valid: true,
|
|
20
|
+
xMagentoCacheId: null,
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
field: 'currentCartId',
|
|
25
|
+
policies: cartTypePolicies,
|
|
26
|
+
selection: '{ __typename id locked }',
|
|
27
|
+
value: { __typename: 'CurrentCartId', id: 'test-cart', locked: false },
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
field: 'currentCompareUid',
|
|
31
|
+
policies: compareTypePolicies,
|
|
32
|
+
selection: '{ __typename uid }',
|
|
33
|
+
value: { __typename: 'CurrentCompareUid', uid: 'test-compare' },
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
field: 'recentlyViewedProducts',
|
|
37
|
+
policies: recentlyViewedProductsTypePolicies,
|
|
38
|
+
selection: '{ __typename items { __typename sku parentSku } }',
|
|
39
|
+
value: {
|
|
40
|
+
__typename: 'RecentlyViewedProducts',
|
|
41
|
+
items: [{ __typename: 'RecentlyViewedProduct', sku: 'test-sku', parentSku: null }],
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
describe.each(cases)('$field', ({ field, policies, selection, value }) => {
|
|
47
|
+
const query = gql(`query ClientField { ${field} @client ${selection} }`)
|
|
48
|
+
|
|
49
|
+
it('returns a complete result from an empty cache', () => {
|
|
50
|
+
const cache = new InMemoryCache({ typePolicies: policies })
|
|
51
|
+
expect(cache.diff({ query })).toMatchObject({ complete: true, result: { [field]: null } })
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('retains stored values and accepts an explicit clear', () => {
|
|
55
|
+
const cache = new InMemoryCache({ typePolicies: policies })
|
|
56
|
+
cache.writeQuery({ query, data: { [field]: value } })
|
|
57
|
+
expect(cache.readQuery({ query })).toEqual({ [field]: value })
|
|
58
|
+
cache.writeQuery({ query, data: { [field]: null } })
|
|
59
|
+
expect(cache.readQuery({ query })).toEqual({ [field]: null })
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('keeps an empty server customer query eligible for fetching', () => {
|
|
64
|
+
const cache = new InMemoryCache({ typePolicies: customerTypePolicies })
|
|
65
|
+
const local = gql`
|
|
66
|
+
query GuestCustomer {
|
|
67
|
+
customer @client {
|
|
68
|
+
email
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
`
|
|
72
|
+
const remote = gql`
|
|
73
|
+
query ServerCustomer {
|
|
74
|
+
customer {
|
|
75
|
+
email
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
`
|
|
79
|
+
expect(cache.diff({ query: local })).toMatchObject({ complete: true, result: { customer: null } })
|
|
80
|
+
expect(cache.diff({ query: remote }).complete).toBe(false)
|
|
81
|
+
cache.writeQuery({ query: remote, data: { customer: { email: 'customer@example.test' } } })
|
|
82
|
+
expect(cache.readQuery({ query: local })).toEqual({
|
|
83
|
+
customer: { email: 'customer@example.test' },
|
|
84
|
+
})
|
|
85
|
+
cache.writeQuery({ query: remote, data: { customer: null } })
|
|
86
|
+
expect(cache.diff({ query: remote })).toMatchObject({
|
|
87
|
+
complete: true,
|
|
88
|
+
result: { customer: null },
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
it('preserves the destination session when the source cache is empty', () => {
|
|
93
|
+
const source = new InMemoryCache({ typePolicies: customerTypePolicies })
|
|
94
|
+
const destination = new InMemoryCache({ typePolicies: customerTypePolicies })
|
|
95
|
+
const query = gql`
|
|
96
|
+
query CustomerToken {
|
|
97
|
+
customerToken @client {
|
|
98
|
+
token
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
`
|
|
102
|
+
destination.writeQuery({ query, data: { customerToken: { token: 'test-token' } } })
|
|
103
|
+
migrateCustomer(source, destination)
|
|
104
|
+
expect(destination.readQuery({ query })).toEqual({ customerToken: { token: 'test-token' } })
|
|
105
|
+
})
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ApolloClient, ApolloLink, gql, InMemoryCache } from '@apollo/client'
|
|
2
|
+
import { LocalState } from '@apollo/client/local-state'
|
|
3
|
+
import { expect, it, vi } from 'vitest'
|
|
4
|
+
import { cartTypePolicies } from '../../../magento-cart/typePolicies'
|
|
5
|
+
import type { ApolloClientConfig } from '../../config'
|
|
6
|
+
import { createCacheReviver } from './createCacheReviver'
|
|
7
|
+
|
|
8
|
+
vi.mock('../../../magento-cart/hooks', () => ({ readCartId: vi.fn(), writeCartId: vi.fn() }))
|
|
9
|
+
|
|
10
|
+
const query = gql`
|
|
11
|
+
query CurrentCartId {
|
|
12
|
+
currentCartId @client {
|
|
13
|
+
__typename
|
|
14
|
+
id
|
|
15
|
+
locked
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
`
|
|
19
|
+
const currentCartId = { __typename: 'CurrentCartId', id: 'test-cart', locked: false }
|
|
20
|
+
|
|
21
|
+
it('notifies the watching queries of the revived state', async () => {
|
|
22
|
+
const createCache = () => new InMemoryCache({ typePolicies: cartTypePolicies })
|
|
23
|
+
const client = new ApolloClient({
|
|
24
|
+
cache: createCache(),
|
|
25
|
+
link: ApolloLink.empty(),
|
|
26
|
+
localState: new LocalState(),
|
|
27
|
+
defaultOptions: { preview: {} },
|
|
28
|
+
})
|
|
29
|
+
const config = { policies: [cartTypePolicies], migrations: [] } as Partial<ApolloClientConfig>
|
|
30
|
+
|
|
31
|
+
const results: unknown[] = []
|
|
32
|
+
const subscription = client.watchQuery({ query }).subscribe(({ data }) => results.push(data))
|
|
33
|
+
await vi.waitFor(() => expect(results.at(-1)).toEqual({ currentCartId: null }))
|
|
34
|
+
|
|
35
|
+
await createCacheReviver(client, createCache, config as ApolloClientConfig, {
|
|
36
|
+
ROOT_QUERY: { __typename: 'Query', currentCartId },
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
await vi.waitFor(() => expect(results.at(-1)).toEqual({ currentCartId }))
|
|
40
|
+
subscription.unsubscribe()
|
|
41
|
+
})
|
package/hooks/usePrivateQuery.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type { InputMaybe, PrivateContext } from '@graphcommerce/graphql-mesh'
|
|
2
2
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
3
|
-
import { useIsSSR } from '@graphcommerce/next-ui/hooks/useIsSsr'
|
|
4
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
5
3
|
import { getCssFlag, removeCssFlag, setCssFlag } from '@graphcommerce/next-ui/utils/cssFlags'
|
|
6
4
|
import { useContext, useEffect } from 'react'
|
|
7
5
|
import type { MaybeMasked, TypedDocumentNode, useQuery } from '../apollo'
|
|
@@ -35,15 +33,13 @@ export function usePrivateQuery<
|
|
|
35
33
|
): Omit<useQuery.Result<Q, V>, 'data'> & { data: Q | NonNullable<MaybeMasked<Q>>; mask: boolean } {
|
|
36
34
|
const { skip = true } = options
|
|
37
35
|
const context = usePrivateQueryContext()
|
|
38
|
-
const isSsr = useIsSSR()
|
|
39
36
|
|
|
40
37
|
const privateContext = useContext(PrivateQueryMaskContext)
|
|
41
38
|
|
|
42
39
|
useEffect(() => {
|
|
43
|
-
if (isSsr) return
|
|
44
40
|
if (context && !getCssFlag('private-query')) setCssFlag('private-query', true)
|
|
45
41
|
else if (!context && getCssFlag('private-query')) removeCssFlag('private-query')
|
|
46
|
-
}, [context
|
|
42
|
+
}, [context])
|
|
47
43
|
|
|
48
44
|
const clientQuery = useQueryHook<Q, V>(document, {
|
|
49
45
|
...options,
|
|
@@ -55,8 +51,11 @@ export function usePrivateQuery<
|
|
|
55
51
|
if (!skip) data ??= clientQuery.previousData
|
|
56
52
|
|
|
57
53
|
// If the user is logged in we might need to show a skeleton:
|
|
58
|
-
|
|
59
|
-
|
|
54
|
+
// Without a private context (SSR, guests) the mask stays on: it only hides content while the
|
|
55
|
+
// `private-query` CSS flag is set, which never happens without a context. Keeping it constant avoids a
|
|
56
|
+
// forced synchronous re-render of the whole page right after hydration.
|
|
57
|
+
let mask = true
|
|
58
|
+
if (context) {
|
|
60
59
|
// Show skeleton while loading, but not when there's an error
|
|
61
60
|
mask = !skip
|
|
62
61
|
? !clientQuery.data && !clientQuery.previousData && !clientQuery.error
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/graphql",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "11.0.0-canary.
|
|
5
|
+
"version": "11.0.0-canary.48",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"main": "index.ts",
|
|
8
8
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
@@ -28,12 +28,12 @@
|
|
|
28
28
|
"rxjs": "^7.8.2"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"@graphcommerce/eslint-config-pwa": "^11.0.0-canary.
|
|
32
|
-
"@graphcommerce/graphql-codegen-near-operation-file": "11.0.0-canary.
|
|
33
|
-
"@graphcommerce/graphql-codegen-relay-optimizer-plugin": "11.0.0-canary.
|
|
34
|
-
"@graphcommerce/next-config": "^11.0.0-canary.
|
|
35
|
-
"@graphcommerce/prettier-config-pwa": "^11.0.0-canary.
|
|
36
|
-
"@graphcommerce/typescript-config-pwa": "^11.0.0-canary.
|
|
31
|
+
"@graphcommerce/eslint-config-pwa": "^11.0.0-canary.48",
|
|
32
|
+
"@graphcommerce/graphql-codegen-near-operation-file": "11.0.0-canary.48",
|
|
33
|
+
"@graphcommerce/graphql-codegen-relay-optimizer-plugin": "11.0.0-canary.48",
|
|
34
|
+
"@graphcommerce/next-config": "^11.0.0-canary.48",
|
|
35
|
+
"@graphcommerce/prettier-config-pwa": "^11.0.0-canary.48",
|
|
36
|
+
"@graphcommerce/typescript-config-pwa": "^11.0.0-canary.48",
|
|
37
37
|
"@graphql-mesh/plugin-http-details-extensions": "*",
|
|
38
38
|
"react": "^19.2.0",
|
|
39
39
|
"react-dom": "^19.2.0"
|