From d3d584280485d07df750ffe69b4b43bdbd47de6f Mon Sep 17 00:00:00 2001 From: TheMonkeyCoder Date: Thu, 24 Apr 2025 17:30:24 +0330 Subject: [PATCH] fix: keep main feed scroll position on primary page navigation (#299) --- src/layouts/PrimaryPageLayout/index.tsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/layouts/PrimaryPageLayout/index.tsx b/src/layouts/PrimaryPageLayout/index.tsx index 511b49f4..a99f5014 100644 --- a/src/layouts/PrimaryPageLayout/index.tsx +++ b/src/layouts/PrimaryPageLayout/index.tsx @@ -39,10 +39,21 @@ const PrimaryPageLayout = forwardRef( [] ) + const lastScrollTopRef = useRef(0) useEffect(() => { if (isSmallScreen) { - window.scrollTo({ top: 0 }) - return + if (scrollAreaRef.current?.checkVisibility()) { + window.scrollTo({ top: lastScrollTopRef.current }) + } + const handleScroll = () => { + if (scrollAreaRef.current?.checkVisibility()) { + lastScrollTopRef.current = window.scrollY + } + } + window.addEventListener('scroll', handleScroll) + return () => { + window.removeEventListener('scroll', handleScroll) + } } }, [current]) @@ -50,6 +61,7 @@ const PrimaryPageLayout = forwardRef( return (