From f63dfde85d2d2821fdd574db78c63f00f235ffe3 Mon Sep 17 00:00:00 2001 From: yohlo Date: Sun, 23 Aug 2026 18:27:35 -0700 Subject: [PATCH] fix(ui): defer the visual-viewport read out of render Reading window during render made the client's first render disagree with the SSR markup; start at zero and fill in after mount, matching Mantine's useViewportSize contract. --- src/features/core/hooks/use-visual-viewport-size.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/features/core/hooks/use-visual-viewport-size.ts b/src/features/core/hooks/use-visual-viewport-size.ts index 98584e6..dfc3a94 100644 --- a/src/features/core/hooks/use-visual-viewport-size.ts +++ b/src/features/core/hooks/use-visual-viewport-size.ts @@ -5,11 +5,13 @@ const eventListerOptions = { }; const useVisualViewportSize = () => { - const windowExists = typeof window !== 'undefined'; + // Starts at zero on server and client alike, filling in after mount — the + // same contract as Mantine's useViewportSize. Reading window during render + // makes the client's first render disagree with the SSR markup. const [windowSize, setWindowSize] = useState({ - width: windowExists ? window.visualViewport?.width || 0 : 0, - height: windowExists ? window.visualViewport?.height || 0 : 0, - top: windowExists ? window.visualViewport?.offsetTop || 0 : 0, + width: 0, + height: 0, + top: 0, }); const rafRef = useRef(null);