Persist sidebar scroll position across navigation#379
Conversation
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Workflows to automatically generate PRs for you. |
|
Firetiger deploy monitoring skipped This PR didn't match the auto-monitor filter configured on your GitHub connection:
Reason: PR modifies documentation/UI behavior (sidebar scroll persistence) and does not change kernel API endpoints or Temporal workflows. To monitor this PR anyway, reply with |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 34326a0. Configure here.
| if (isNaN(top)) return false; | ||
| if (Math.abs(sb.scrollTop - top) > 1) sb.scrollTop = top; | ||
| return true; | ||
| } |
There was a problem hiding this comment.
Restore reports success prematurely
Medium Severity
After navigation, restore always returns success once a saved value exists and a sidebar node is found, even when scrollTop could not be set to the stored offset. pollRestore then stops retrying, so a sidebar that is not yet scrollable can stay at the top once content finishes laying out.
Reviewed by Cursor Bugbot for commit 34326a0. Configure here.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 34326a0d46
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| var candidates = document.querySelectorAll( | ||
| "aside, nav[aria-label='Sidebar'], aside[aria-label='Sidebar'], #sidebar" | ||
| ); |
There was a problem hiding this comment.
Prefer the documented scrollable sidebar element
Mintlify documents #sidebar-content as the scrollable content area inside the sidebar, but this selector only considers the outer containers. On pages where the user actually scrolls #sidebar-content, save() records the outer #sidebar/aside scrollTop (typically 0) or finds nothing, so deep API/sidebar navigation still resets instead of restoring the position. Include and prefer #sidebar-content before the container selectors so the saved value comes from the element that receives the scroll.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Risk assessment: Low.
This PR adds one Mintlify custom JavaScript file that runs globally on the docs site to persist sidebar scroll position. The change affects user-facing docs navigation behavior, so it is above very-low risk, but the blast radius is limited to docs UI state: it uses sessionStorage, DOM scroll listeners, and history event hooks only, with no backend, auth, billing, infrastructure, data model, or external network impact.
I found no CODEOWNERS file in this repo and the PR did not already have an approval, so I’m approving based on the low-risk classification.
Sent by Cursor Automation: Assign PR reviewers
|
This seems fine, but would it be better just to have the sidebar scroll to the selected item? Feels simpler long term. |




Summary
sidebar-scroll.jsat the repo root. Mintlify auto-injects any.jsfile in the content directory on every page.scrollToptosessionStoragewhenever the user scrolls the sidebar or clicks a link inside it, and restores it after navigation (both SPA route changes via patchedhistory.pushState/replaceStateand full page loads).Why
Mintlify has no built-in setting to preserve sidebar scroll position. After clicking a nav link the sidebar resets to the top, so picking the page directly below the one you just visited requires re-scrolling.
Notes
Test plan
mintlify dev, open the API reference, scroll the sidebar down, click a deep link, confirm sidebar stays scrolled.Note
Low Risk
Docs-only UX script with no auth, API, or data changes; main risk is brittle DOM selectors if Mintlify changes markup.
Overview
Adds a root-level
sidebar-scroll.jsscript (intended for Mintlify to inject on every docs page) so the docs sidebar keeps its scroll position when users navigate.On scroll (debounced) and on link clicks inside the sidebar, the script stores
scrollTopinsessionStorage. After route changes it restores that offset by polling until the sidebar element exists, and it hookshistory.pushState,history.replaceState,popstate, andloadso both SPA navigations and full reloads get the same behavior.Sidebar targeting is defensive: it picks the first matching
aside/ labeled nav /#sidebarelement that is actually scrollable, since Mintlify’s DOM is not guaranteed stable.Reviewed by Cursor Bugbot for commit 34326a0. Bugbot is set up for automated code reviews on this repo. Configure here.