Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions vesta/vesta_ui/src/components/nav/dl-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,27 @@ export default function DLNav({
const elId = href.split('#')[1]
const el = document.getElementById(elId)

if (href.startsWith('/')) router.push(href, { scroll: false })
else window.open(href, '_blank');

if (el) {
window.scrollTo({
top: el.offsetTop - NavBarHeights[breakpoint].condensed,
behavior: 'smooth',
})
if (!el) {
// no element to scroll to, so it's a normal link
window.open(href, '_blank');
return
}

router.push(href, { scroll: false })
window.scrollTo({
top: el.offsetTop - NavBarHeights[breakpoint].condensed,
behavior: 'smooth',
})
Comment on lines +47 to +51
Copy link

Copilot AI Aug 24, 2025

Choose a reason for hiding this comment

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

The router.push() call will always execute when an element is found, even for external URLs that contain hash fragments. This could cause navigation issues if href contains an external URL with a hash (e.g., 'https://example.com#section'). Consider checking if the href is an internal route before calling router.push().

Suggested change
router.push(href, { scroll: false })
window.scrollTo({
top: el.offsetTop - NavBarHeights[breakpoint].condensed,
behavior: 'smooth',
})
if (isInternalUrl(href)) {
router.push(href, { scroll: false })
window.scrollTo({
top: el.offsetTop - NavBarHeights[breakpoint].condensed,
behavior: 'smooth',
})
} else {
// For external URLs, just open in a new tab
window.open(href, '_blank');
return;
}

Copilot uses AI. Check for mistakes.

onClickNavLink && onClickNavLink()
}

const [anchorEl, setAnchorEl] = React.useState<HTMLAnchorElement|null>(null);
const handleClick = (event: React.MouseEvent<HTMLAnchorElement>) => setAnchorEl(event.currentTarget);
const [anchorEl, setAnchorEl] = React.useState<HTMLAnchorElement | null>(null);
const handleClick = (event: React.MouseEvent<HTMLAnchorElement>) => {
// prevent scrolling to the top of the page
event.preventDefault()
setAnchorEl(event.currentTarget);
}
const handleClose = () => setAnchorEl(null);

const aboutSearchParams: AboutSearchParamsState = { index: 0 }
Expand Down Expand Up @@ -102,10 +108,10 @@ export default function DLNav({
typography={linkTypography}
/>
<RelatedResourcesMenu
anchorEl={anchorEl}
typography={linkTypography}
onClick={handleClickNavLink}
onClose={handleClose}
anchorEl={anchorEl}
typography={linkTypography}
onClick={handleClickNavLink}
onClose={handleClose}
/>
</Box>
)
Expand Down