@graphcommerce/next-ui 11.0.0-canary.47 → 11.0.0-canary.49

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,39 @@
1
1
  # Change Log
2
2
 
3
+ ## 11.0.0-canary.49
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2701](https://github.com/graphcommerce-org/graphcommerce/pull/2701) [`561f62d`](https://github.com/graphcommerce-org/graphcommerce/commit/561f62dd0072d3080dc18a01fa5fda66a96af410) - A page that opens with `#gallery`, for example after a reload of the zoomed gallery or after Back from another site, renders without zoom, the same as the server render, and removes `#gallery` without a "Cancel rendering route" error. Before, the gallery rendered zoomed in the browser and closed again, so the image moved on page load. ([@DivaniNL](https://github.com/DivaniNL))
8
+
9
+ - [#2701](https://github.com/graphcommerce-org/graphcommerce/pull/2701) [`7df196c`](https://github.com/graphcommerce-org/graphcommerce/commit/7df196c9115966de4b794c55d9d21f2e1dad007c) - The zoomed SidebarGallery fills the full screen height. It moves up by its measured distance to the top of the page instead of a fixed margin based on the header height. With the fixed margin, the zoomed gallery on desktop started 11px below the top of the screen and the bottom 11px was cut off. ([@DivaniNL](https://github.com/DivaniNL))
10
+
11
+ ## 11.0.0-canary.48
12
+
13
+ ### Minor Changes
14
+
15
+ - [#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))
16
+
17
+ ### Patch Changes
18
+
19
+ - [#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:
20
+
21
+ - `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.
22
+ - `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.
23
+ - `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.
24
+ - `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.
25
+ - 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).
26
+ - 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).
27
+ - `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.
28
+ - `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.
29
+ - `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))
30
+
31
+ - [#2683](https://github.com/graphcommerce-org/graphcommerce/pull/2683) [`24612c2`](https://github.com/graphcommerce-org/graphcommerce/commit/24612c27c98dda60d7281fff85eb9437024a05f8) - `LazyHydrate` keeps the server-rendered HTML when its parent renders again before hydration. With a `height`, it renders its content when the browser is idle after a client-side navigation. Find-in-page finds the content below the fold in both cases. ([@paales](https://github.com/paales))
32
+
33
+ - [#2698](https://github.com/graphcommerce-org/graphcommerce/pull/2698) [`1f56a16`](https://github.com/graphcommerce-org/graphcommerce/commit/1f56a160567101a996445d76ee7b06f3b0e1702b) - `PopperPanel` passes `popperProps` to the `Popper` and merges `popperProps.sx` with its own `sx`. It passed `popperProps` to `PopperPanelActions`, so the prop had no effect. ([@bramvanderholst](https://github.com/bramvanderholst))
34
+
35
+ - [#2706](https://github.com/graphcommerce-org/graphcommerce/pull/2706) [`2518b60`](https://github.com/graphcommerce-org/graphcommerce/commit/2518b60f50072683ef556c167b770efc29840de8) - RowLinks items show a visible keyboard focus outline that the scroller does not clip. ([@DivaniNL](https://github.com/DivaniNL))
36
+
3
37
  ## 11.0.0-canary.47
4
38
 
5
39
  ## 11.0.0-canary.46
@@ -16,7 +16,7 @@ import type { SxProps, Theme } from '@mui/material'
16
16
  import { Box, Fab, styled, Unstable_TrapFocus as TrapFocus, useTheme } from '@mui/material'
17
17
  import { m, useDomEvent, useMotionValue } from 'framer-motion'
18
18
  import { useRouter } from 'next/router'
19
- import React, { useEffect, useRef } from 'react'
19
+ import React, { useCallback, useEffect, useRef } from 'react'
20
20
  import { iconChevronLeft, iconChevronRight, iconFullscreen, iconFullscreenExit } from '../icons'
21
21
  import { IconSvg } from '../IconSvg'
22
22
  import { Row } from '../Row/Row'
@@ -82,28 +82,67 @@ export function SidebarGallery(props: SidebarGalleryProps) {
82
82
  afterScroller,
83
83
  } = props
84
84
 
85
+ const rootRef = useRef<HTMLDivElement>(null)
86
+ const sidebarWrapperRef = useRef<HTMLDivElement>(null)
85
87
  const router = useRouter()
86
88
  const prevRoute = usePrevPageRouter()
87
89
  // const classes = useMergedClasses(useStyles({ clientHeight, aspectRatio }).classes, props.classes)
88
90
 
89
91
  const route = `#${routeHash}`
90
- // We're using the URL to manage the state of the gallery.
91
- const zoomed = router.asPath.endsWith(route)
92
+ // We're using the URL to manage the state of the gallery. A page that opens with #gallery has no
93
+ // previous page and renders without zoom, the same as the server render.
94
+ const zoomed = router.asPath.endsWith(route) && Boolean(prevRoute?.pathname)
92
95
  usePreventScroll(zoomed)
93
96
 
94
97
  // cleanup if someone enters the page with #gallery
95
98
  useEffect(() => {
96
- if (!prevRoute?.pathname && zoomed) {
97
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
98
- router.replace(router.asPath.replace(route, ''))
99
+ if (prevRoute?.pathname || !router.asPath.endsWith(route)) return undefined
100
+ let active = true
101
+ const removeHash = async () => {
102
+ try {
103
+ await router.replace(router.asPath.replace(route, ''))
104
+ } catch (e) {
105
+ // The route change of Next.js after hydration can cancel this replace.
106
+ if (!(e as { cancelled?: boolean }).cancelled) throw e
107
+ if (active) await removeHash()
108
+ }
109
+ }
110
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
111
+ removeHash()
112
+ return () => {
113
+ active = false
99
114
  }
100
115
  }, [prevRoute?.pathname, route, router, zoomed])
101
116
 
117
+ // The zoomed gallery moves up by its layout distance to the top of the page, so it fills the full
118
+ // screen height. offsetTop ignores transforms, so the Framer layout animation and the translate
119
+ // do not change the measurement. The sidebar keeps its height from before the zoom, so its content
120
+ // does not move while it slides out.
121
+ const measureZoomOffsets = useCallback(() => {
122
+ const root = rootRef.current
123
+ if (!root || !sidebarWrapperRef.current) return
124
+ let top = 0
125
+ for (let el: HTMLElement | null = root; el; el = el.offsetParent as HTMLElement | null) {
126
+ top += el.offsetTop
127
+ }
128
+ root.style.setProperty('--zoom-offset', `${top}px`)
129
+ if (!zoomed) {
130
+ root.style.setProperty('--sidebar-height', `${sidebarWrapperRef.current.offsetHeight}px`)
131
+ }
132
+ }, [zoomed])
133
+
134
+ useEffect(() => {
135
+ measureZoomOffsets()
136
+ window.addEventListener('resize', measureZoomOffsets)
137
+ return () => window.removeEventListener('resize', measureZoomOffsets)
138
+ }, [measureZoomOffsets])
139
+
102
140
  const toggle = () => {
103
141
  if (disableZoom) {
104
142
  return
105
143
  }
106
144
  if (!zoomed) {
145
+ measureZoomOffsets()
107
146
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
108
147
  router.push(route, undefined, { shallow: true })
109
148
  window.scrollTo({ top: 0, behavior: 'smooth' })
@@ -160,6 +199,7 @@ export function SidebarGallery(props: SidebarGalleryProps) {
160
199
  )}
161
200
  >
162
201
  <MotionBox
202
+ ref={rootRef}
163
203
  layout
164
204
  layoutDependency={zoomed}
165
205
  className={classes.root}
@@ -175,9 +215,8 @@ export function SidebarGallery(props: SidebarGalleryProps) {
175
215
  '&.zoomed': {
176
216
  position: 'relative',
177
217
  zIndex: theme.zIndex.modal,
178
- marginTop: `calc(${theme.appShell.headerHeightSm} * -1)`,
218
+ translate: '0 calc(var(--zoom-offset) * -1)',
179
219
  [theme.breakpoints.up('md')]: {
180
- marginTop: `calc(${theme.appShell.headerHeightMd} * -1 - ${theme.spacings.lg})`,
181
220
  gridTemplateColumns: '1fr auto',
182
221
  },
183
222
  px: 0,
@@ -367,6 +406,7 @@ export function SidebarGallery(props: SidebarGalleryProps) {
367
406
  </MotionBox>
368
407
  </TrapFocus>
369
408
  <Box
409
+ ref={sidebarWrapperRef}
370
410
  className={classes.sidebarWrapper}
371
411
  sx={sxx(
372
412
  {
@@ -386,6 +426,8 @@ export function SidebarGallery(props: SidebarGalleryProps) {
386
426
  left: `calc(${responsiveVal(300, 500, undefined, theme.breakpoints.values.lg)} + ${
387
427
  theme.page.horizontal
388
428
  } * 2)`,
429
+ marginTop: 'var(--zoom-offset)',
430
+ height: 'var(--sidebar-height)',
389
431
  },
390
432
  },
391
433
  )}
@@ -6,12 +6,13 @@ export type ListFormatProps = {
6
6
  children: React.ReactNode[]
7
7
  } & UseIntlListFormatOptions
8
8
 
9
- /** @public */
10
- export function ListFormat(props: ListFormatProps) {
11
- const { children, ...options } = props
9
+ function ListFormatMultiple(props: {
10
+ childArray: React.ReactNode[]
11
+ options: UseIntlListFormatOptions
12
+ }) {
13
+ const { childArray, options } = props
12
14
  const formatter = useIntlListFormat(options)
13
15
 
14
- const childArray = React.Children.toArray(children)
15
16
  const fauxChildren = childArray.map((child, index) => `${index}`) ?? []
16
17
  const parts = formatter.formatToParts(fauxChildren)
17
18
 
@@ -26,3 +27,14 @@ export function ListFormat(props: ListFormatProps) {
26
27
  </>
27
28
  )
28
29
  }
30
+
31
+ /** @public */
32
+ export function ListFormat(props: ListFormatProps) {
33
+ const { children, ...options } = props
34
+ const childArray = React.Children.toArray(children)
35
+
36
+ // A single item needs no list formatting; skip creating an Intl.ListFormat, which loads its locale data on first use.
37
+ if (childArray.length < 2) return <>{childArray}</>
38
+
39
+ return <ListFormatMultiple childArray={childArray} options={options} />
40
+ }
@@ -1,6 +1,7 @@
1
1
  import { useIsomorphicLayoutEffect } from '@graphcommerce/framer-utils'
2
2
  import type { BoxProps } from '@mui/material'
3
3
  import { Box } from '@mui/material'
4
+ import { cancelIdleCallback, requestIdleCallback } from 'next/dist/client/request-idle-callback'
4
5
  import type { CSSProperties } from 'react'
5
6
  import React, { startTransition, useRef, useState } from 'react'
6
7
 
@@ -28,11 +29,15 @@ export type LazyHydrateProps = BoxProps<'div'> & {
28
29
  * side, because using an IntersectionObserver on an element with no height, will cause all
29
30
  * siblings to render at once.
30
31
  *
31
- * By proving a height, we can use the IntersectionObserver on the client as well.
32
+ * By proving a height, we can use the IntersectionObserver on the client as well. The content
33
+ * still renders when the browser is idle, so find-in-page finds it.
32
34
  */
33
35
  height?: CSSProperties['height']
34
36
  }
35
37
 
38
+ // React sets innerHTML again when this object changes, which removes the server-rendered HTML
39
+ const keepServerHtml = { __html: '' }
40
+
36
41
  /**
37
42
  * LazyHydrate can defer the hydration of a component until it becomes visible. OR manually by using
38
43
  * the hydrated prop. This can be a way to improve the TBT of a page.
@@ -48,8 +53,10 @@ export function LazyHydrate(props: LazyHydrateProps) {
48
53
  // If we are manually hydrating, we watch that value and do not use the IntersectionObserver
49
54
  if (isHydrated || !rootRef.current) return undefined
50
55
 
56
+ const serverRendered = rootRef.current.hasAttribute('data-lazy-hydrate')
57
+
51
58
  // If the element wasn't rendered on the server, we hydrate it immediately
52
- if (!height && !rootRef.current?.hasAttribute('data-lazy-hydrate')) {
59
+ if (!height && !serverRendered) {
53
60
  setIsHydrated(true)
54
61
  return undefined
55
62
  }
@@ -57,17 +64,23 @@ export function LazyHydrate(props: LazyHydrateProps) {
57
64
  // The user has opted to manually hydrate the component
58
65
  if (hydrated !== undefined) return undefined
59
66
 
67
+ const hydrate = () => startTransition(() => setIsHydrated(true))
68
+
60
69
  const observer = new IntersectionObserver(
61
70
  ([entry]) => {
62
- if (entry.isIntersecting && entry.intersectionRatio > 0) {
63
- startTransition(() => setIsHydrated(true))
64
- }
71
+ if (entry.isIntersecting && entry.intersectionRatio > 0) hydrate()
65
72
  },
66
73
  { rootMargin: '200px' },
67
74
  )
68
75
  observer.observe(rootRef.current)
69
76
 
70
- return () => observer.disconnect()
77
+ // A client-rendered element stays empty until it renders, so render it when the browser is idle
78
+ const idle = serverRendered ? undefined : requestIdleCallback(hydrate)
79
+
80
+ return () => {
81
+ observer.disconnect()
82
+ if (idle !== undefined) cancelIdleCallback(idle)
83
+ }
71
84
  }, [height, hydrated, isHydrated])
72
85
 
73
86
  if (isHydrated) {
@@ -86,7 +99,7 @@ export function LazyHydrate(props: LazyHydrateProps) {
86
99
  <Box
87
100
  ref={rootRef}
88
101
  // eslint-disable-next-line react/no-danger
89
- dangerouslySetInnerHTML={{ __html: '' }}
102
+ dangerouslySetInnerHTML={keepServerHtml}
90
103
  suppressHydrationWarning
91
104
  {...elementProps}
92
105
  style={{ ...elementProps.style, height }}
@@ -0,0 +1,46 @@
1
+ // @vitest-environment happy-dom
2
+
3
+ import type React from 'react'
4
+ import { act } from 'react'
5
+ import { createRoot } from 'react-dom/client'
6
+ import { afterAll, beforeAll, expect, it, vi } from 'vitest'
7
+ import { PopperPanel } from './PopperPanel'
8
+
9
+ vi.mock('./PopperPanelActions', () => ({
10
+ PopperPanelActions: (props: { children: React.ReactNode }) => props.children,
11
+ }))
12
+
13
+ beforeAll(() => {
14
+ Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
15
+ })
16
+
17
+ afterAll(() => {
18
+ Reflect.deleteProperty(globalThis, 'IS_REACT_ACT_ENVIRONMENT')
19
+ })
20
+
21
+ it('passes popperProps to the Popper', () => {
22
+ const anchor = document.createElement('button')
23
+ const container = document.createElement('div')
24
+ document.body.append(anchor, container)
25
+ const root = createRoot(container)
26
+
27
+ act(() =>
28
+ root.render(
29
+ <PopperPanel
30
+ activeEl={anchor}
31
+ title='Filter'
32
+ onApply={() => {}}
33
+ onClose={() => {}}
34
+ popperProps={{ className: 'CustomPopper' }}
35
+ >
36
+ {() => 'Content'}
37
+ </PopperPanel>,
38
+ ),
39
+ )
40
+ const popper = container.querySelector('.CustomPopper')
41
+ act(() => root.unmount())
42
+ anchor.remove()
43
+ container.remove()
44
+
45
+ expect(popper).not.toBeNull()
46
+ })
@@ -1,6 +1,7 @@
1
1
  import type { PopperProps } from '@mui/material'
2
2
  import { ClickAwayListener, Popper } from '@mui/material'
3
3
  import { useRef } from 'react'
4
+ import { sxx } from '../utils/sxx'
4
5
  import { PopperPanelActions } from './PopperPanelActions'
5
6
  import type { PanelProps } from './types'
6
7
  import { useHandleClickNotDrag } from './useHandleClickNotDrag'
@@ -10,7 +11,7 @@ export type PopperPanelProps = PanelProps & {
10
11
  }
11
12
 
12
13
  export function PopperPanel(props: PopperPanelProps) {
13
- const { activeEl, children, ...actionsProps } = props
14
+ const { activeEl, children, popperProps, ...actionsProps } = props
14
15
  const ref = useRef<HTMLDivElement>(null)
15
16
  const movement = useHandleClickNotDrag(ref)
16
17
  const handleClickAway = () => {
@@ -23,21 +24,25 @@ export function PopperPanel(props: PopperPanelProps) {
23
24
  return (
24
25
  <ClickAwayListener onClickAway={handleClickAway}>
25
26
  <Popper
27
+ {...popperProps}
26
28
  ref={ref}
27
29
  open={Boolean(activeEl)}
28
30
  anchorEl={activeEl}
29
- sx={{
30
- boxShadow: 12,
31
- borderRadius: 3,
32
- overflow: 'hidden',
33
- zIndex: 1,
34
- bgcolor: 'background.paper',
35
- display: 'grid',
36
- gridTemplateRows: 'min-content auto min-content',
37
- minWidth: 350,
38
- overflowY: 'auto',
39
- maxHeight: '500px',
40
- }}
31
+ sx={sxx(
32
+ {
33
+ boxShadow: 12,
34
+ borderRadius: 3,
35
+ overflow: 'hidden',
36
+ zIndex: 1,
37
+ bgcolor: 'background.paper',
38
+ display: 'grid',
39
+ gridTemplateRows: 'min-content auto min-content',
40
+ minWidth: 350,
41
+ overflowY: 'auto',
42
+ maxHeight: '500px',
43
+ },
44
+ popperProps?.sx,
45
+ )}
41
46
  disablePortal
42
47
  modifiers={[
43
48
  { name: 'offset', options: { offset: [0, 10] } },
@@ -1,8 +1,28 @@
1
1
  import { GlobalStyles } from '@mui/material'
2
+ import type { FeatureBundle } from 'framer-motion'
2
3
  import { LazyMotion } from 'framer-motion'
4
+ import { startTransition, useEffect, useState } from 'react'
3
5
  import type { EmotionProviderProps } from '../Styles/EmotionProvider'
4
6
  import { EmotionProvider } from '../Styles/EmotionProvider'
5
7
 
8
+ // Until the features are loaded `m` components render as plain elements.
9
+ const noFeatures = {} as FeatureBundle
10
+
11
+ /**
12
+ * Loads framer-motion's features after hydration and applies them in a transition, so the resulting
13
+ * re-render of all `m` components is time-sliced instead of one blocking task, and the features
14
+ * stay out of the startup bundle.
15
+ */
16
+ function useFramerFeatures() {
17
+ const [features, setFeatures] = useState<FeatureBundle>(noFeatures)
18
+ useEffect(() => {
19
+ import('./framerFeatures')
20
+ .then((m) => startTransition(() => setFeatures(m.default)))
21
+ .catch(console.error)
22
+ }, [])
23
+ return features
24
+ }
25
+
6
26
  export type CssAndFramerMotionProviderProps = EmotionProviderProps
7
27
 
8
28
  /**
@@ -16,7 +36,7 @@ export function CssAndFramerMotionProvider(props: CssAndFramerMotionProviderProp
16
36
  const { children, emotionCache } = props
17
37
  return (
18
38
  <EmotionProvider emotionCache={emotionCache}>
19
- <LazyMotion features={async () => (await import('./framerFeatures')).default} strict>
39
+ <LazyMotion features={useFramerFeatures()} strict>
20
40
  {children}
21
41
  <GlobalStyles
22
42
  styles={{
@@ -77,6 +77,8 @@ export function RowLinks(props: RowLinksProps) {
77
77
  md: 'end',
78
78
  },
79
79
  },
80
+ // Inset, because the scroller overflow clips an outline outside the item
81
+ '& :focus-visible': { outline: 'revert', outlineOffset: '-1px' },
80
82
  })}
81
83
  >
82
84
  {inlineTitle && (
package/index.test.ts ADDED
@@ -0,0 +1,20 @@
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(expect.arrayContaining(['safeJsonLdReplacer']))
20
+ })
package/index.ts CHANGED
@@ -30,6 +30,7 @@ export * from './icons'
30
30
  export * from './IconSvg'
31
31
  export * from './Intl'
32
32
  export * from './JsonLd/JsonLd'
33
+ export * from './JsonLd/safeJsonLdReplacer'
33
34
  export * from './Layout'
34
35
  export * from './LayoutDefault'
35
36
  export * from './LayoutOverlay'
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/next-ui",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "11.0.0-canary.47",
5
+ "version": "11.0.0-canary.49",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -43,13 +43,13 @@
43
43
  "@emotion/react": "^11.14.0",
44
44
  "@emotion/server": "^11.11.0",
45
45
  "@emotion/styled": "^11.14.1",
46
- "@graphcommerce/eslint-config-pwa": "^11.0.0-canary.47",
47
- "@graphcommerce/framer-next-pages": "^11.0.0-canary.47",
48
- "@graphcommerce/framer-scroller": "^11.0.0-canary.47",
49
- "@graphcommerce/framer-utils": "^11.0.0-canary.47",
50
- "@graphcommerce/image": "^11.0.0-canary.47",
51
- "@graphcommerce/prettier-config-pwa": "^11.0.0-canary.47",
52
- "@graphcommerce/typescript-config-pwa": "^11.0.0-canary.47",
46
+ "@graphcommerce/eslint-config-pwa": "^11.0.0-canary.49",
47
+ "@graphcommerce/framer-next-pages": "^11.0.0-canary.49",
48
+ "@graphcommerce/framer-scroller": "^11.0.0-canary.49",
49
+ "@graphcommerce/framer-utils": "^11.0.0-canary.49",
50
+ "@graphcommerce/image": "^11.0.0-canary.49",
51
+ "@graphcommerce/prettier-config-pwa": "^11.0.0-canary.49",
52
+ "@graphcommerce/typescript-config-pwa": "^11.0.0-canary.49",
53
53
  "@lingui/core": "^5",
54
54
  "@lingui/macro": "^5",
55
55
  "@lingui/react": "^5",
package/utils/cookie.ts CHANGED
@@ -2,6 +2,7 @@ import { useMotionValueValue } from '@graphcommerce/framer-utils'
2
2
  import type { SerializeOptions } from 'cookie'
3
3
  import { parse, serialize } from 'cookie'
4
4
  import { motionValue } from 'framer-motion'
5
+ import { useSyncExternalStore } from 'react'
5
6
  import { useIsSSR } from '../hooks'
6
7
 
7
8
  // We need this motionValue to be synced with the actual cookie store.
@@ -67,7 +68,13 @@ export function useCookie<T extends string>(
67
68
  else cookie(name, null)
68
69
  }
69
70
 
70
- const cookies = useCookies()
71
- const value = (cookies[name] as T | undefined | null) ?? defaultValue
71
+ // Subscribe to this single cookie; the server snapshot is `null`, so hydration only causes a re-render
72
+ // when this specific cookie is actually set.
73
+ const raw = useSyncExternalStore(
74
+ (onChange) => cookieNotify.on('change', onChange),
75
+ () => (cookie(name) as T | undefined) ?? null,
76
+ () => null,
77
+ )
78
+ const value = raw ?? defaultValue
72
79
  return [value, update] as const
73
80
  }