Repository navigation
fix(ui): keep active sidebar item visible on navigation - #9154
codebyanas wants to merge 5 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
🟡 Changes recommended
The new effect currently won’t re-run on locale-only route changes (locale switch keeps pathname stable), so the “active item visible” behavior can fail in that navigation path.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR updates the site’s sidebar wrapper to keep the currently active navigation link visible after route changes by automatically adjusting the sidebar container’s internal scrollTop when needed.
Changes:
- Adds a
useEffectthat finds the active sidebar link after navigation and scrolls it into view if it’s outside the sidebar viewport. - Keeps existing “preserve sidebar scroll position” behavior via
useScrollToElement. - Uses pathname-based matching to identify the active link (including locale-prefixed URLs).
File summaries
| File | Description |
|---|---|
| apps/site/components/withSidebar.tsx | Adds an effect that scrolls the active sidebar item into view after pathname changes. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| 0, | ||
| offsetTop - aside.clientHeight / 2 + active.offsetHeight / 2 | ||
| ); | ||
| }, [pathname]); |
| const active = [ | ||
| ...(aside?.querySelectorAll<HTMLAnchorElement>('a[href]') ?? []), | ||
| ].find(link => new URL(link.href).pathname === window.location.pathname); | ||
|
|
ovflowd
left a comment
There was a problem hiding this comment.
The code feels pretty complex. And seems to be in the wrong place. IMO this should be on ui-components and it should be a Hook that uses one of the Browser's Observer APIs (i.e.: IntersectionObserver) -- in other words the component using this i.e.: Sidebar should be an extended version of the Sidebar (ie.: FocusableSidebar (?))
But the current implementation is just not OK.
Apologies for the late review, this PR slipped 😅
Description
Fixes #8828.
The sidebar's internal scroll position could leave the active navigation item outside the visible area after navigation. This change ensures that the active sidebar link is automatically scrolled into view when the pathname changes.
The implementation:
scrollTopwhen the item is off-screen./en/about/....Testing
Tested locally by navigating between sidebar pages and verifying that the active item remains visible after navigation.