fix: scroll only the explorer container, not the whole window - #7
Open
narath wants to merge 2 commits into
Open
Conversation
On page load the explorer reveals the active item with
`activeElement.scrollIntoView({ behavior: "smooth" })`. `scrollIntoView`
scrolls *every* scrollable ancestor, including the document, so when SPA
routing is disabled (each navigation is a full page load) the window gets
dragged down to wherever the active item sits in the sidebar — the reader
lands partway down the new page instead of at the top.
Use `explorerUl.scrollTo(...)`, which only moves the explorer's own scroll
container, to center the active item without ever scrolling the window.
The smooth animation is preserved.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On each page load the explorer reveals the current page in the sidebar with:
Element.scrollIntoView()scrolls every scrollable ancestor of the element — including the document itself. When a site disables SPA routing (enableSPA: false), every navigation is a full page load, so this call drags the whole window down to wherever the active item sits in the file tree. The reader lands partway down the new page instead of at the top.(With SPA enabled the bug is masked, because Quartz's SPA router calls
window.scrollTo({ top: 0 })after morphing the DOM. TheexplorerScrollToprestore branch is unaffected — it already setsexplorerUl.scrollTopdirectly.)Fix
Use
explorerUl.scrollTo(...)instead. Called on the explorer's own scroll container, it moves only that container — never the window — while still centering the active item and preserving the smooth animation.Testing
Reproduced on a non-SPA Quartz site: clicking a link scrolled the window 302px down (matching the active item's offset in the sidebar) while the sidebar list moved 2px. After the fix, the same action leaves the window at 0px and the active item is still revealed in the sidebar.