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.
This commit is contained in:
2026-08-23 18:27:35 -07:00
parent 5ac39ac7a2
commit f63dfde85d
@@ -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<number | null>(null);