Skip to content

Commit 2905f32

Browse files
authored
fix: Docs sidebar auto-scroll not working on page navigation (#2350)
Previously, when navigating between documentation pages using the `command palette (⌘K)`, the sidebar would not automatically scroll to highlight the current page location. This made it difficult to maintain context of where you were in the documentation structure. This PR enhances the `DocsSidebarAutoscroll` component to respond to navigation changes by: - Adding pathname dependency to useLayoutEffect - Making the sidebar auto-scroll to the active page whenever navigation occurs - Maintaining the same smooth scrolling behavior as the initial page load Now the sidebar will properly scroll to the current documentation page regardless of how you navigate to it - whether through direct clicks or command palette navigation.
1 parent 2a68a4b commit 2905f32

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/components/docs-sidebar-autoscroll.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
"use client";
22

33
import { useLayoutEffect, useRef } from "react";
4+
import { usePathname } from "next/navigation";
45

56
export function DocsSidebarAutoscroll({ children }: { children: React.ReactNode }) {
67
let ref = useRef<HTMLDivElement>(null);
8+
let pathname = usePathname();
79

810
useLayoutEffect(() => {
911
let element = ref.current;
@@ -17,7 +19,7 @@ export function DocsSidebarAutoscroll({ children }: { children: React.ReactNode
1719
} else {
1820
activeLink.scrollIntoView();
1921
}
20-
}, []);
22+
}, [pathname]);
2123

2224
return <div ref={ref}>{children}</div>;
2325
}

0 commit comments

Comments
 (0)