From d6c9a07faae894d5e67eb87008964b79d942b966 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20Bl=C3=A4ttermann?= Date: Tue, 13 Dec 2022 05:03:23 +0100 Subject: [PATCH] Fix bug with anchor links after reloading There was no need for the previous implementation, since the browser handles this nativly. Additional the manual scrolling into view was actually broken, because the heading would disappear behind the menu bar. --- website/src/components/sidebar.js | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/website/src/components/sidebar.js b/website/src/components/sidebar.js index f29c66951..f02daf9ea 100644 --- a/website/src/components/sidebar.js +++ b/website/src/components/sidebar.js @@ -38,7 +38,6 @@ const DropdownNavigation = ({ items, defaultValue }) => { } export default function Sidebar({ items = [], pageMenu = [], slug }) { - const [initialized, setInitialized] = useState(false) const [activeSection, setActiveSection] = useState(null) const activeRef = useRef() const activeHeading = getActiveHeading(items, slug) @@ -46,16 +45,10 @@ export default function Sidebar({ items = [], pageMenu = [], slug }) { useEffect(() => { const handleInView = ({ detail }) => setActiveSection(detail) window.addEventListener('inview', handleInView, { passive: true }) - if (!initialized) { - if (activeRef && activeRef.current) { - activeRef.current.scrollIntoView({ block: 'center' }) - } - setInitialized(true) - } return () => { window.removeEventListener('inview', handleInView) } - }, [initialized]) + }) return (