Repository navigation
fix: Back from a linked document keeps the reader's place - #2084
Merged
Merged
Conversation
Opening a linked document from the root now remembers the first block visible at the top of the scroll viewport and its offset; back() scrolls that block back to the same place once the root has rendered, and again as late layout settles, unless the reader scrolls first. Fixes #2082.
…ll restore
back({ restoreScroll: false }) skips the restore, and cancelScrollRestore()
stops one still settling. App cancels it when it selects an annotation,
navigates from Contents or reveals for WebMCP, and the jump path's Back
skips it. The restore also ends on the reader's own input and on unmount,
and clears its frames and timers.
1 task
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.
Following a link from the middle of a long document and pressing Back used to land the reader at the top (or bottom) of the document.
Now, when a linked document (HTML or markdown) is opened from the root,
useLinkedDocremembers the first block visible at the top of the scroll viewport and how far its top sat from the viewport's top.back()scrolls that block back to the same offset once the root has rendered, and again at about 150, 400 and 1000 ms to absorb late layout (re-applied highlights, images, a sidebar that changed the column width). A scroll the reader makes in between wins. Anchoring by block instead of raw pixels matters: coming back from an HTML document the column is wider, so the same scrollTop is a different place.packages/ui/utils/scrollAnchor.ts(new): capture and restore.useLinkedDoc: new optionalscrollViewportoption (additive; without it nothing changes). Noted inpackages/ui/HANDOFF.md.packages/editor/App.tsxpasses its scroll viewport.packages/ui/hooks/useLinkedDoc.scrollRestore.test.tsx(added to the CI DOM list); it fails without the fix.The restore never fights a scroll it did not make: it ends on the reader's own input (wheel, touch, key, pointer), on any foreign scroll, on the next navigation and on unmount.
back({ restoreScroll: false })skips it andcancelScrollRestore()stops it; the app uses them where it scrolls to a target itself (a jump to a comment in the root, a Contents click, selecting an annotation, WebMCP reveal), since assigning scrollTop during a smoothscrollIntoViewcancels it in Chromium.Fixes #2082.