From 3408ad3a09a664e201ad9d548e5409a9afa21fec Mon Sep 17 00:00:00 2001 From: Ruslan Bagautdinov Date: Mon, 22 Jul 2024 14:16:05 +0300 Subject: [PATCH] Revert "fix: window causes errors in SSR (#256)" This reverts commit d8339cd5f8f4270aaea8ce340d175453ff320691. --- .../SubNavigation/SubNavigation.tsx | 24 ++++--------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/src/components/SubNavigation/SubNavigation.tsx b/src/components/SubNavigation/SubNavigation.tsx index f3a24ae4..ab4846f3 100644 --- a/src/components/SubNavigation/SubNavigation.tsx +++ b/src/components/SubNavigation/SubNavigation.tsx @@ -16,9 +16,7 @@ export type ShareData = { const useVisibility = (miniTocOpened: boolean, closeMiniToc: () => void) => { const [visibility, setVisibility] = useState(true); const [hiddingTimeout, setHiddingTimeout] = useState(undefined); - const [lastScrollY, setLastScrollY] = useState( - typeof window === 'undefined' ? null : window.screenY, - ); + const [lastScrollY, setLastScrollY] = useState(window.screenY); const clickOutsideMiniToc = useCallback( (event: MouseEvent) => { @@ -44,20 +42,16 @@ const useVisibility = (miniTocOpened: boolean, closeMiniToc: () => void) => { ); const controlVisibility = useCallback(() => { - if (typeof window === 'undefined') { - return; - } - if (miniTocOpened) { setVisibility(true); return; } - if (lastScrollY && lastScrollY === 0) { + if (lastScrollY === 0) { setVisibility(true); } - if (lastScrollY && window.scrollY > lastScrollY) { + if (window.scrollY > lastScrollY) { if (hiddingTimeout) { return; } @@ -70,7 +64,7 @@ const useVisibility = (miniTocOpened: boolean, closeMiniToc: () => void) => { setHiddingTimeout(undefined); }, 300), ); - } else if (lastScrollY && window.scrollY < lastScrollY) { + } else if (window.scrollY < lastScrollY) { setVisibility(true); } @@ -85,10 +79,6 @@ const useVisibility = (miniTocOpened: boolean, closeMiniToc: () => void) => { ]); useEffect(() => { - if (typeof window === 'undefined') { - return; - } - if (window.scrollY === 0) { return; } @@ -102,10 +92,6 @@ const useVisibility = (miniTocOpened: boolean, closeMiniToc: () => void) => { }, []); useEffect(() => { - if (typeof window === 'undefined') { - return () => {}; - } - window.addEventListener('scroll', controlVisibility); return () => { @@ -128,7 +114,7 @@ const useShareHandler = (title: string | undefined) => { const shareData = useMemo(() => { return { title, - url: typeof window === 'undefined' ? undefined : window.location.href, + url: window.location.href, }; }, [title]);