fix(docs): fix sidebar scrollIntoView selecting last item erroneously#728
Open
Botato300 wants to merge 1 commit intonodejs:mainfrom
Open
fix(docs): fix sidebar scrollIntoView selecting last item erroneously#728Botato300 wants to merge 1 commit intonodejs:mainfrom
Botato300 wants to merge 1 commit intonodejs:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
avivkeller
approved these changes
Mar 30, 2026
avivkeller
reviewed
Mar 30, 2026
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; |
Author
There was a problem hiding this comment.
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?
Member
There was a problem hiding this comment.
I see, opinions @nodejs/web-infra?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
linkvariable 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
activeLinkvariable remainsnulland the function exits early with areturn, preventing the scrollbar from moving.Validation
Just try accessing the website (/docs/latest/api/) with this change.
Related Issues
None.
Check List
node --run testand all tests passed.node --run format&node --run lint.