Skip to content

fix: scroll only the explorer container, not the whole window - #7

Open
narath wants to merge 2 commits into
quartz-community:mainfrom
narath:fix/explorer-scroll-hijacks-window
Open

fix: scroll only the explorer container, not the whole window#7
narath wants to merge 2 commits into
quartz-community:mainfrom
narath:fix/explorer-scroll-hijacks-window

Conversation

@narath

@narath narath commented Jul 9, 2026

Copy link
Copy Markdown

Problem

On each page load the explorer reveals the current page in the sidebar with:

activeElement.scrollIntoView({ behavior: "smooth" })

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. The explorerScrollTop restore branch is unaffected — it already sets explorerUl.scrollTop directly.)

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.

narath added 2 commits July 9, 2026 11:50
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.
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.

1 participant