Skip to content

Commit

Permalink
Revert "fix: window causes errors in SSR (#256)"
Browse files Browse the repository at this point in the history
This reverts commit d8339cd.
  • Loading branch information
Ruslan Bagautdinov committed Jul 22, 2024
1 parent ccb23c7 commit 3408ad3
Showing 1 changed file with 5 additions and 19 deletions.
24 changes: 5 additions & 19 deletions src/components/SubNavigation/SubNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ export type ShareData = {
const useVisibility = (miniTocOpened: boolean, closeMiniToc: () => void) => {
const [visibility, setVisibility] = useState(true);
const [hiddingTimeout, setHiddingTimeout] = useState<number | undefined>(undefined);
const [lastScrollY, setLastScrollY] = useState(
typeof window === 'undefined' ? null : window.screenY,
);
const [lastScrollY, setLastScrollY] = useState(window.screenY);

const clickOutsideMiniToc = useCallback(
(event: MouseEvent) => {
Expand All @@ -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;
}
Expand All @@ -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);
}

Expand All @@ -85,10 +79,6 @@ const useVisibility = (miniTocOpened: boolean, closeMiniToc: () => void) => {
]);

useEffect(() => {
if (typeof window === 'undefined') {
return;
}

if (window.scrollY === 0) {
return;
}
Expand All @@ -102,10 +92,6 @@ const useVisibility = (miniTocOpened: boolean, closeMiniToc: () => void) => {
}, []);

useEffect(() => {
if (typeof window === 'undefined') {
return () => {};
}

window.addEventListener('scroll', controlVisibility);

return () => {
Expand All @@ -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]);

Expand Down

0 comments on commit 3408ad3

Please sign in to comment.