From 7a51f35ec4bbe07e4dc1799d905c1ec2201cc758 Mon Sep 17 00:00:00 2001 From: Iqbal Date: Fri, 30 Oct 2026 10:25:59 +0700 Subject: [PATCH] Keep scrollTo's Promise out of the route-change effect Chrome's window.scrollTo now returns a Promise. The effect that opens each page at the top returned it, so React kept it as the cleanup and called it on the next route change: "TypeError: Z is not a function", which unmounted the whole app until a reload. Co-Authored-By: Claude Opus 5.5 --- src/components/AppLayout.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/AppLayout.tsx b/src/components/AppLayout.tsx index 63aebcb..f3b4f56 100644 --- a/src/components/AppLayout.tsx +++ b/src/components/AppLayout.tsx @@ -144,9 +144,11 @@ export function AppLayout() { const current = NAV.find(n => pathname.startsWith(n.to)) // Nav groups stay closed unless they hold the current page; a click on the label overrides that until the next route. const [toggled, setToggled] = useState>>({}) - useEffect(() => setToggled({}), [pathname]) + useEffect(() => { setToggled({}) }, [pathname]) // The window scrolls, not
, so a new page would open at the last page's scroll position. - useLayoutEffect(() => window.scrollTo(0, 0), [pathname]) + // In braces: Chrome's scrollTo now returns a Promise, which React would keep as the effect's + // cleanup and call on the next route change ("is not a function"), unmounting the whole app. + useLayoutEffect(() => { window.scrollTo(0, 0) }, [pathname]) const [collapsed, setCollapsed] = useState(readCollapsed) const toggleCollapsed = () => setCollapsed(c => { try { localStorage.setItem(COLLAPSED_KEY, c ? '0' : '1') } catch { /* keep it for this visit only */ }