Skip to content

fix(html): preserve sidebar scroll when clicking chapter links#3120

Open
leno23 wants to merge 1 commit into
rust-lang:masterfrom
leno23:fix/sidebar-scroll-preserve-3081
Open

fix(html): preserve sidebar scroll when clicking chapter links#3120
leno23 wants to merge 1 commit into
rust-lang:masterfrom
leno23:fix/sidebar-scroll-preserve-3081

Conversation

@leno23
Copy link
Copy Markdown

@leno23 leno23 commented May 17, 2026

Summary

  • On sidebar link click, save the scrollbox scrollTop in sessionStorage
  • On the next page, restore that value instead of adjusting by active-link offset

Motivation

In mdBook 0.5+, clicking a chapter in the sidebar often jumped the TOC back to the top (#3081). The previous logic compared the new page’s .active link position to a saved offset from the clicked link, which produced incorrect scroll adjustments.

This matches the existing GUI test sidebar-scroll.goml.

Notes

Some reports link this to clean/prettified URLs (#3034); this fix addresses scroll preservation for normal sidebar navigation regardless.

Test plan

  • cargo test --test testsuite
  • CI GUI tests (sidebar-scroll.goml)

Fixes #3081

Made with Cursor

Store the sidebar scrollbox scrollTop on link click and restore it on
the next page load. The previous offset-based adjustment used the new
page's active link and reset the sidebar to the top.

Fixes rust-lang#3081

Co-authored-by: Cursor <cursoragent@cursor.com>
@rustbot rustbot added the S-waiting-on-review Status: waiting on a review label May 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: waiting on a review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sidebar no longer scrolling to current chapter

2 participants