fix: page scroll position on navigation (closes #1053)#1059
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes scroll position handling on navigation (issue #1053) by introducing a per-navigation "visit ID" stored in location.state, so each visit gets a unique sessionStorage key. New navigations scroll to top, while browser back/forward restores the saved scroll position for that history entry. All in-app Link/navigate call sites are updated to attach a visit ID, and useScrollRestoration is reworked to key off this ID instead of pathname.
Changes:
- Add
navigationVisit.tshelpers (createNavigationVisitState,getNavigationVisitKey) and propagate visit IDs through Links/navigate across viewer, editor, history, search, tags, tree, breadcrumbs, dialogs, and redirects. - Rework
useScrollRestorationto use a visit-scoped storage key and always scroll (defaulting to 0 when no entry exists), so new navigations no longer inherit a previous page's scroll. - Add Playwright tests covering sidebar navigation reset, revisiting pages, and browser-back scroll restoration.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| ui/leafwiki-ui/src/lib/navigationVisit.ts | New helpers to generate visit IDs and derive a restoration key from a location. |
| ui/leafwiki-ui/src/lib/useScrollRestoration.ts | Switch from pathname to a restoration key; always scroll on mount (to 0 if no stored value). |
| ui/leafwiki-ui/src/features/viewer/PageViewer.tsx | Use visit-key for scroll restoration; attach visit state when navigating to history. |
| ui/leafwiki-ui/src/features/viewer/EmptySectionChildrenList.tsx | Attach visit state to child page links. |
| ui/leafwiki-ui/src/features/viewer/Breadcrumbs.tsx | Attach visit state to breadcrumb links. |
| ui/leafwiki-ui/src/features/tree/TreeNode.tsx | Attach visit state to tree node links. |
| ui/leafwiki-ui/src/features/tags/TagsResultCard.tsx | Attach visit state to tag result links. |
| ui/leafwiki-ui/src/features/search/SearchResultCard.tsx | Attach visit state to search result links. |
| ui/leafwiki-ui/src/features/preview/MarkdownLink.tsx | Attach visit state to internal markdown links. |
| ui/leafwiki-ui/src/features/page/RootRedirect.tsx | Forward incoming location.state through the redirect. |
| ui/leafwiki-ui/src/features/page/PermalinkRedirect.tsx | Forward location.state when navigating to permalink target. |
| ui/leafwiki-ui/src/features/page/pageMutationRefresh.ts | Attach fresh visit state after a page refactor navigation. |
| ui/leafwiki-ui/src/features/page/PageHistoryPage.tsx | Use visit-key for restoration; attach state when closing history. |
| ui/leafwiki-ui/src/features/page/DeletePageDialog.tsx | Attach visit state to backlink list and post-delete redirect. |
| ui/leafwiki-ui/src/features/page-switcher/PageQuickSwitcherDialog.tsx | Attach visit state when opening a switcher result. |
| ui/leafwiki-ui/src/features/links/LinkInfo.tsx | Attach visit state to backlink lists. |
| ui/leafwiki-ui/src/features/history/PageHistoryContent.tsx | Attach visit state after restoring a revision. |
| ui/leafwiki-ui/src/features/editor/PageEditor.tsx | Attach visit state on save/cancel navigation. |
| e2e/tests/page.spec.ts | New Playwright tests verifying scroll reset on navigation and restore on browser back. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Add end-to-end coverage for dialog and editor flows that now use visit-based scroll restoration. This keeps the new navigation semantics protected without touching unrelated workspace changes.
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.
No description provided.