Skip to content

fix(docs): fix sidebar scrollIntoView selecting last item erroneously#728

Open
Botato300 wants to merge 1 commit intonodejs:mainfrom
Botato300:main
Open

fix(docs): fix sidebar scrollIntoView selecting last item erroneously#728
Botato300 wants to merge 1 commit intonodejs:mainfrom
Botato300:main

Conversation

@Botato300
Copy link
Copy Markdown

Description

Problem: Currently, when you go to: https://nodejs.org/docs/latest/api/. the scrollbar in the side menu automatically scrolls all the way to the bottom; it should only scroll automatically when a module is selected. The problem was that when there was no match, the link variable would retain the last item in the array, which is why it would scroll the scrollbar all the way to the bottom.

Solution: Simply change how the match is detected and the for-of loop: if no match is found, the activeLink variable remains null and the function exits early with a return, preventing the scrollbar from moving.

Validation

Just try accessing the website (/docs/latest/api/) with this change.

Related Issues

None.

Check List

  • I have read the Contributing Guidelines and made commit messages that follow the guideline.
  • I have run node --run test and all tests passed.
  • I have check code formatting with node --run format & node --run lint.
  • I've covered new added functionality with unit tests if necessary.

@Botato300 Botato300 requested a review from a team as a code owner March 30, 2026 01:02
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 30, 2026

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

Project Deployment Actions Updated (UTC)
api-docs-tooling Ready Ready Preview Mar 30, 2026 1:02am

Request Review

Comment on lines +206 to 215
let activeLink = null;
for (const link of sidebarLinks) {
if (link.pathname === window.location.pathname) {
activeLink = link;
break;
}
}

if (!link) {
if (!activeLink) {
return;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use a .find?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To use .find(), you first need to convert sidebarLinks into an array (using Array.from()). I can simplify this, would you like me to do that?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, opinions @nodejs/web-infra?

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.

2 participants