Skip to content

fix: page scroll position on navigation (closes #1053)#1059

Merged
perber merged 2 commits into
mainfrom
fix/1053-pages-scroll-position-on-navigation
May 28, 2026
Merged

fix: page scroll position on navigation (closes #1053)#1059
perber merged 2 commits into
mainfrom
fix/1053-pages-scroll-position-on-navigation

Conversation

@perber
Copy link
Copy Markdown
Owner

@perber perber commented May 28, 2026

No description provided.

Copilot AI review requested due to automatic review settings May 28, 2026 17:35
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.ts helpers (createNavigationVisitState, getNavigationVisitKey) and propagate visit IDs through Links/navigate across viewer, editor, history, search, tags, tree, breadcrumbs, dialogs, and redirects.
  • Rework useScrollRestoration to 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.
@perber perber merged commit 0c3b1f3 into main May 28, 2026
8 checks passed
@perber perber deleted the fix/1053-pages-scroll-position-on-navigation branch May 28, 2026 18:04
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.

2 participants