Skip to content

Commit 60f51b9

Browse files
mgarbsclaude
andauthored
fix: prevent anchor links from navigating away from HIP detail view (#1431)
Signed-off-by: Michael Garber <michael.garber@hashgraph.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f0d2273 commit 60f51b9

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

site/src/main.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,16 @@ async function showDetail(num) {
677677
safeHTML($('#hip-content'), rendered);
678678
applyRainbowIndent($('#hip-content'));
679679

680+
// Intercept in-body anchor links (e.g. [see Motivation](#motivation)) so they
681+
// scroll within the detail view instead of triggering handleRoute
682+
$('#hip-content').addEventListener('click', e => {
683+
const a = e.target.closest('a[href^="#"]');
684+
if (!a) return;
685+
const id = a.getAttribute('href').slice(1);
686+
const target = document.getElementById(id);
687+
if (target) { e.preventDefault(); target.scrollIntoView({ behavior: 'smooth' }); }
688+
});
689+
680690
// Render any Mermaid diagrams
681691
const mermaidEls = $('#hip-content').querySelectorAll('.mermaid');
682692
if (mermaidEls.length) {
@@ -779,6 +789,16 @@ function buildTOC() {
779789
html += `<li class="${lvl}"><a href="#${id}" data-toc-target="${id}">${h.textContent}</a></li>`;
780790
});
781791
safeHTML(tocList, html);
792+
793+
// Intercept TOC clicks to scroll without changing the hash,
794+
// which would trigger handleRoute and navigate away from the detail view
795+
tocList.addEventListener('click', e => {
796+
const link = e.target.closest('a[data-toc-target]');
797+
if (!link) return;
798+
e.preventDefault();
799+
const target = document.getElementById(link.dataset.tocTarget);
800+
if (target) target.scrollIntoView({ behavior: 'smooth' });
801+
});
782802
}
783803

784804
function setupScrollSpy() {

0 commit comments

Comments
 (0)