Skip to content

Keep browser back navigation anchored after hash jumps#96

Open
xyjk0511 wants to merge 1 commit into
Scinawa:mainfrom
xyjk0511:codex/issue-72-safari-back-scroll
Open

Keep browser back navigation anchored after hash jumps#96
xyjk0511 wants to merge 1 commit into
Scinawa:mainfrom
xyjk0511:codex/issue-72-safari-back-scroll

Conversation

@xyjk0511

Copy link
Copy Markdown

PR draft: Fix Safari back button scroll restoration after reference jumps

Closes #72

Summary

This adds a small, dependency-free scroll restoration helper to header.html.

When a reader clicks an in-page reference link, the script stores the current scroll position for the current page. If the browser later navigates back via history or restores the page from the back-forward cache, it restores that saved position after layout has had a chance to settle.

Why

Safari can lose the expected scroll position after jumping from a deep section to an appendix/reference anchor and then pressing Back. The page also has delayed layout work from rendered math/content, so a single immediate scrollTo is not always enough. The helper retries briefly and then stops.

Scope

  • Does not change book content.
  • Does not change styles.
  • Does not add dependencies.
  • Only runs for same-page hash links and browser history/page-cache restoration.

Verification

  • Extracted the injected JavaScript from header.html and ran node --check successfully.
  • Reviewed the diff to confirm the change is limited to header.html.

Not tested

  • Manual Safari reproduction, because Safari is not available in this Windows environment.

Constraint: Safari can lose the pre-anchor scroll position after intra-page reference jumps and async page layout.\nConfidence: medium\nScope-risk: narrow\nDirective: Keep this fix limited to history/hash scroll restoration; do not change book content or generated pages by hand.\nTested: Extracted injected JavaScript from header.html and ran node --check successfully.\nNot-tested: Manual Safari reproduction; Safari is not available in this Windows environment.
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.

Fix "back" button of few browsers (like Safari)

1 participant