Skip to content

fix(docs): heading anchor links now include the hash so it doesnt scoll all the way up, follows navbar logic#5791

Open
FucciUnavailable wants to merge 1 commit intocolinhacks:mainfrom
FucciUnavailable:fix/heading-anchor-scroll
Open

fix(docs): heading anchor links now include the hash so it doesnt scoll all the way up, follows navbar logic#5791
FucciUnavailable wants to merge 1 commit intocolinhacks:mainfrom
FucciUnavailable:fix/heading-anchor-scroll

Conversation

@FucciUnavailable
Copy link

Fixes #5788

Problem

Clicking a heading (e.g. "Coercion") on a docs page like /api sets the
URL to ?id=coercion. Clicking the same heading a second time causes the
page to jump to the top instead of staying at the section.

This happens because the <Link> only sets a query param (?id=coercion).
When the URL hasn't changed, Next.js treats it as a no-op navigation —
no scroll happens, and the page snaps to top via scroll restoration.

The right-side TOC nav already uses ?id=coercion#coercion (both query
param and hash), which works reliably on every click.

Fix

Add the hash to the heading anchor href to match what the TOC nav already does:

  • Before: ?id=${props.id}
  • After: ?id=${props.id}#${props.id}

This means every click is always a real URL change (the hash is always
present), and the browser's native anchor scrolling handles positioning
correctly and idempotently.

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.

Buggy navigation on docs

1 participant