Skip to content

Hash anchor navigation fails on page reload #303

@jonchurch

Description

@jonchurch

The Problem

Reproduction

  1. Open https://lodash.com/docs/4.17.21#concat in a new tab - scrolls to anchor ✅
  2. Refresh the page - scrolls to top instead of anchor ❌

Theory

The docs layout uses a nested scroll container (.doc-container has overflow-y: auto). The document itself doesn't scroll - scrolling happens inside that container.

On fresh page load, browsers seem smart enough to scroll nested containers to bring anchors into view. On reload, scroll restoration kicks in and restores the document scroll position (always 0), which seems to override hash navigation. The nested container's scroll position isn't restored.

Console check:

console.log('document scrollY:', window.scrollY)  // always 0
console.log('doc-container scrollTop:', document.querySelector('.doc-container').scrollTop)

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions