From 13fa6cd4850cc1f17430565dcf84f12b976ec6ab Mon Sep 17 00:00:00 2001 From: Gigi Date: Thu, 23 Oct 2025 20:00:16 +0200 Subject: [PATCH] fix(mobile): preserve scroll position when toggling highlights panel When opening/closing the highlights sidebar on mobile, the body gets position:fixed to prevent background scrolling. This was causing the scroll position to reset to the top. Now we save the scroll position before locking, apply it as a negative top value to maintain visual position, and restore it when unlocking. --- src/components/ThreePaneLayout.tsx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/components/ThreePaneLayout.tsx b/src/components/ThreePaneLayout.tsx index 957faf34..d49d57a2 100644 --- a/src/components/ThreePaneLayout.tsx +++ b/src/components/ThreePaneLayout.tsx @@ -136,13 +136,23 @@ const ThreePaneLayout: React.FC = (props) => { // Lock body scroll when mobile sidebar or highlights is open useEffect(() => { if (isMobile && (props.isSidebarOpen || !props.isHighlightsCollapsed)) { + // Save current scroll position + const scrollY = window.scrollY + document.body.style.top = `-${scrollY}px` document.body.classList.add('mobile-sidebar-open') } else { + // Restore scroll position + const scrollY = document.body.style.top document.body.classList.remove('mobile-sidebar-open') + document.body.style.top = '' + if (scrollY) { + window.scrollTo(0, parseInt(scrollY || '0') * -1) + } } return () => { document.body.classList.remove('mobile-sidebar-open') + document.body.style.top = '' } }, [isMobile, props.isSidebarOpen, props.isHighlightsCollapsed])