Skip to content

fix: keep active sidebar item visible - #9090

Open
ulofiai wants to merge 1 commit into
nodejs:mainfrom
ulofiai:fix/issue-8828
Open

fix: keep active sidebar item visible#9090
ulofiai wants to merge 1 commit into
nodejs:mainfrom
ulofiai:fix/issue-8828

Conversation

@ulofiai

@ulofiai ulofiai commented Aug 6, 2026

Copy link
Copy Markdown

Description

  • preserve the existing sidebar scroll restoration behavior while keeping the active link visible after navigation
  • center the active sidebar link only when it falls outside the sidebar viewport
  • match both the app pathname and the browser pathname so locale-prefixed links are handled
  • add unit coverage for off-screen and already-visible active items

Validation

  • git diff --check
  • TypeScript/JSX syntax transpilation for the changed files
  • targeted scroll-centering calculation checks
  • full pnpm format, pnpm test, and pnpm build were not run because dependencies are not included in the bundle environment

Related Issues

Fixes #8828.

Check List

  • I have read the Contributing Guidelines and made commit messages that follow the guideline.
  • I have run pnpm format to ensure the code follows the style guide.
  • I have run pnpm test to check if all tests are passing.
  • I have run pnpm build to check if the website builds without errors.
  • I've covered new added functionality with unit tests if necessary.

@ulofiai
ulofiai requested a review from a team as a code owner August 6, 2026 18:51
@vercel

vercel Bot commented Aug 6, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
nodejs-org Ready Ready Preview Aug 6, 2026 6:52pm

Request Review

@cursor

cursor Bot commented Aug 6, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Localized UI scroll behavior in the site sidebar hook with unit tests; no auth, data, or API changes.

Overview
Extends useScrollToElement so that, after the existing saved scroll restore, it can scroll the sidebar to keep the current page’s link in view when a pathname is passed.

On mount/route change it finds the matching a[href] (comparing both usePathname() and window.location.pathname for locale-prefixed URLs). If the active item is outside the sidebar viewport, it scrolls to center it; if it’s already visible, it does nothing. WithSidebar now passes pathname into the hook.

Unit tests cover off-screen centering (expected scrollTop: 720) and the no-scroll-when-visible case.

Reviewed by Cursor Bugbot for commit bc1941c. Bugbot is set up for automated code reviews on this repo. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sidebar scroll position resets on navigation, active item can be off-screen

1 participant