Skip to content

fix: Issue with trailing / in the left menu script#944

Merged
ehsavoie merged 1 commit into
a2aproject:mainfrom
ehsavoie:left_menu_webcontext_fiw
Jun 19, 2026
Merged

fix: Issue with trailing / in the left menu script#944
ehsavoie merged 1 commit into
a2aproject:mainfrom
ehsavoie:left_menu_webcontext_fiw

Conversation

@ehsavoie

Copy link
Copy Markdown
Collaborator

No description provided.

Signed-off-by: Emmanuel Hugonnet <ehugonne@redhat.com>
@ehsavoie ehsavoie merged commit 6e77457 into a2aproject:main Jun 19, 2026
1 check passed

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates the active menu item detection script to ignore trailing slashes when comparing URLs. The review feedback suggests optimizing this check by utilizing native HTMLAnchorElement properties (origin and pathname) instead of instantiating a new URL object inside a try-catch block, which also prevents potential false positives with external links.

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.

Comment on lines 38 to 40
var hasActive = Array.from(wrapperUl.querySelectorAll('a')).some(function (a) {
try { return new URL(a.href).pathname === window.location.pathname; } catch (e) { return false; }
try { return new URL(a.href).pathname.replace(/\/$/, '') === currentPath; } catch (e) { return false; }
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using new URL(a.href) inside a try-catch block for every link is inefficient and unnecessary because HTMLAnchorElement already provides native pathname and origin properties. Additionally, comparing only the pathname can lead to false positives if there are external links in the menu that share the same path (e.g., an external link to https://github.com/some-path when the current site path is /some-path).

We can simplify the code, improve performance, and prevent potential false positives by directly comparing a.origin and a.pathname.

Suggested change
var hasActive = Array.from(wrapperUl.querySelectorAll('a')).some(function (a) {
try { return new URL(a.href).pathname === window.location.pathname; } catch (e) { return false; }
try { return new URL(a.href).pathname.replace(/\/$/, '') === currentPath; } catch (e) { return false; }
});
var hasActive = Array.from(wrapperUl.querySelectorAll('a')).some(function (a) {
return a.origin === window.location.origin && a.pathname.replace(/\/$/, '') === currentPath;
});

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.

1 participant