diff --git a/src/components/scroll-context.tsx b/src/components/scroll-context.tsx index 1f74f244f..707ef7e76 100644 --- a/src/components/scroll-context.tsx +++ b/src/components/scroll-context.tsx @@ -1,24 +1,18 @@ import React, { useEffect } from 'react'; import { useLocation } from 'react-router-dom'; -import { usePrevious } from 'soapbox/hooks'; - -export type Location = ReturnType>; - interface IScrollContext { - shouldUpdateScroll(prevLocation: Location | undefined, location: Location): boolean; children: React.ReactNode; } -export const ScrollContext: React.FC = ({ shouldUpdateScroll, children }) => { - const location = useLocation(); - const prevLocation = usePrevious(location); +export const ScrollContext: React.FC = ({ children }) => { + const location = useLocation<{ soapboxModalKey?: number } | undefined>(); useEffect(() => { - if (prevLocation && (prevLocation.pathname !== location.pathname) && shouldUpdateScroll(prevLocation, location)) { + if (!location.state?.soapboxModalKey) { window.scrollTo(0, 0); } - }, [location, shouldUpdateScroll]); + }, [location]); return children; }; \ No newline at end of file diff --git a/src/init/soapbox-mount.tsx b/src/init/soapbox-mount.tsx index ea365031f..2c915ebbf 100644 --- a/src/init/soapbox-mount.tsx +++ b/src/init/soapbox-mount.tsx @@ -6,7 +6,7 @@ import { CompatRouter } from 'react-router-dom-v5-compat'; import { openModal } from 'soapbox/actions/modals'; import * as BuildConfig from 'soapbox/build-config'; import LoadingScreen from 'soapbox/components/loading-screen'; -import { Location, ScrollContext } from 'soapbox/components/scroll-context'; +import { ScrollContext } from 'soapbox/components/scroll-context'; import SiteErrorBoundary from 'soapbox/components/site-error-boundary'; import { ModalContainer, @@ -24,10 +24,6 @@ const GdprBanner = React.lazy(() => import('soapbox/components/gdpr-banner')); const EmbeddedStatus = React.lazy(() => import('soapbox/features/embedded-status')); const UI = React.lazy(() => import('soapbox/features/ui')); -interface LocationState { - soapboxModalKey?: string; -} - /** Highest level node with the Redux store. */ const SoapboxMount = () => { useCachedLocationHandler(); @@ -54,15 +50,11 @@ const SoapboxMount = () => { const { redirectRootNoLogin, gdpr } = soapboxConfig; - function shouldUpdateScroll(prev: Location | undefined, location: Location): boolean { - return !(location.state?.soapboxModalKey && location.state?.soapboxModalKey !== prev?.state?.soapboxModalKey); - } - return ( - + {(!isLoggedIn && redirectRootNoLogin) && (