From 662d2aaf9327806299ec5526d2b266de05007c84 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 10 Nov 2024 12:07:51 -0600 Subject: [PATCH] Don't scroll to the top when navigating between posts in a thread Fixes https://gitlab.com/soapbox-pub/soapbox/-/issues/1778 --- src/components/scroll-context.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/components/scroll-context.tsx b/src/components/scroll-context.tsx index f5ffeeb60..74470e279 100644 --- a/src/components/scroll-context.tsx +++ b/src/components/scroll-context.tsx @@ -9,6 +9,12 @@ export const ScrollContext: React.FC = ({ children }) => { const location = useLocation<{ soapboxModalKey?: number } | undefined>(); useEffect(() => { + // HACK: Don't scroll when navigating between posts. + // Surely there's a better way, so that components can negate the behavior from within instead of out here. + if (location.pathname.includes('/posts/')) { + return; + } + if (!location.state?.soapboxModalKey) { window.scrollTo(0, 0); }