Skip to content

fix: prevent anchor links from navigating away from HIP detail view - #1431

Merged
mgarbs merged 1 commit into
mainfrom
fix/anchor-links-in-detail-view
Mar 18, 2026
Merged

fix: prevent anchor links from navigating away from HIP detail view#1431
mgarbs merged 1 commit into
mainfrom
fix/anchor-links-in-detail-view

Conversation

@mgarbs

@mgarbs mgarbs commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fix TOC sidebar links and in-body anchor links (e.g. [Motivation](#motivation)) on HIP detail pages navigating back to the HIPs list instead of scrolling to the target section

Root Cause

The site uses hash-based routing (#hip-123, #about, etc.) with a hashchange listener that calls handleRoute(). When a TOC or in-body anchor link like #motivation is clicked, it changes location.hash, which triggers handleRoute. Since #motivation doesn't match any known route pattern (#hip-*, #about, #create), it falls through to the default case which shows the list view — navigating the user away from the HIP they were reading.

Fix

Intercept clicks on both TOC links and in-body anchor links with preventDefault(), then use scrollIntoView({ behavior: 'smooth' }) to scroll to the target heading without changing the hash or triggering the router.

Test plan

  • Open any HIP with a TOC (e.g. HIP-1) → click a TOC entry → page scrolls to that section without leaving the detail view
  • Click an in-body anchor link within a HIP's markdown content → same smooth scroll behavior
  • Normal navigation still works: back link, nav links, clicking other HIPs

🤖 Generated with Claude Code

Clicking TOC links or in-body anchor links (e.g. [Motivation](#motivation))
on a HIP detail page would change location.hash, triggering handleRoute
which didn't recognize the anchor hash and fell through to show the list
view. Fix by intercepting these clicks and using scrollIntoView instead
of hash navigation.

Signed-off-by: Michael Garber <michael.garber@hashgraph.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mgarbs
mgarbs requested a review from a team as a code owner March 17, 2026 14:17

@Reccetech Reccetech 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.

Approved.

@mgarbs
mgarbs merged commit 60f51b9 into main Mar 18, 2026
9 of 13 checks passed
@mgarbs
mgarbs deleted the fix/anchor-links-in-detail-view branch March 18, 2026 12:35
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.

2 participants