From 0d8201962dcfa21aae987225a8b0b4855bc0abbf Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sat, 28 Nov 2026 10:10:27 -0500 Subject: [PATCH] fix: Guard scrollbar width hook against a missing documentElement (#14788) --- app/hooks/useWindowScrollbarWidth.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/hooks/useWindowScrollbarWidth.ts b/app/hooks/useWindowScrollbarWidth.ts index 3acbb9c4f3..a0f2c57e4e 100644 --- a/app/hooks/useWindowScrollbarWidth.ts +++ b/app/hooks/useWindowScrollbarWidth.ts @@ -1,14 +1,21 @@ import { useSyncExternalStore } from "react"; const subscribe = (onStoreChange: () => void) => { + if (!document.documentElement) { + return () => {}; + } + // Re-measure when the html element resizes (scrollbar appears/disappears). const resizeObserver = new ResizeObserver(onStoreChange); resizeObserver.observe(document.documentElement); return () => resizeObserver.disconnect(); }; -const getSnapshot = (): number => - window.innerWidth - document.documentElement.clientWidth; +// documentElement can be null while some in-app browsers replace the document. +const getSnapshot = (): number | null => + document.documentElement + ? window.innerWidth - document.documentElement.clientWidth + : null; /** * Returns the width of the window's vertical scrollbar in pixels, or null