fix: Fixing left menu collapsing too quickly#943
Conversation
Signed-off-by: Emmanuel Hugonnet <ehugonne@redhat.com>
There was a problem hiding this comment.
Code Review
This pull request updates the active link detection logic in head-scripts.html to iterate over all anchor elements within a wrapper list. The reviewer pointed out an improvement opportunity to simplify the logic and reduce overhead by directly using the pathname property of the anchor elements (a.pathname) instead of creating a new URL object for each link.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| var hasActive = Array.from(wrapperUl.querySelectorAll('a')).some(function (a) { | ||
| try { return new URL(a.href).pathname === window.location.pathname; } catch (e) { return false; } | ||
| }); |
There was a problem hiding this comment.
The HTMLAnchorElement (anchor tag <a>) already implements the HTMLHyperlinkElementUtils interface, which provides a standard pathname property. Creating a new URL object for every link is redundant and introduces unnecessary overhead and try-catch complexity. You can directly compare a.pathname with window.location.pathname.
| var hasActive = Array.from(wrapperUl.querySelectorAll('a')).some(function (a) { | |
| try { return new URL(a.href).pathname === window.location.pathname; } catch (e) { return false; } | |
| }); | |
| var hasActive = Array.from(wrapperUl.querySelectorAll('a')).some(function (a) { | |
| return a.pathname === window.location.pathname; | |
| }); |
No description provided.