Skip to content

Restore scroll position when navigating back to a list - #7143

Open
tassilogravura wants to merge 1 commit into
stashapp:developfrom
tassilogravura:fix/back-navigation-scroll-restoration
Open

Restore scroll position when navigating back to a list#7143
tassilogravura wants to merge 1 commit into
stashapp:developfrom
tassilogravura:fix/back-navigation-scroll-restoration

Conversation

@tassilogravura

Copy link
Copy Markdown

Description

React Router v5 has no scroll restoration, so the app relied on the browser's native restoration. That doesn't work for the list views: at the point the history entry is popped, the list content hasn't been fetched and rendered yet, so the document is one viewport tall and the position is clamped to the top. Nothing scrolls back once the content arrives, leaving the user at the top of the list.

Record the scroll position for each history entry and re-apply it on POP until the page is able to scroll there, holding it briefly while the list settles. Positions are kept in session storage so they survive a page reload.

Coming back to a list that was showing a page other than the first re-parses the filter from the query string, which looks like a page change to useScrollToTopOnPageChange and scrolled over the restored position, so that hook now defers to an in-progress restoration.

Related Issue

#7142

Testing

manual testing in my own browser

Screenshots

Checklist

  • I have read and understood the Contributing document.
  • I have read and understood the AI Usage Policy document.
  • I have made corresponding changes to the documentation (if applicable).

AI Usage Disclosure

  • I have used AI tools to assist with this pull request, and I have disclosed the tools and how I used them below.
  • Claude Opus 5

Additional Context

React Router v5 has no scroll restoration, so the app relied on the
browser's native restoration. That doesn't work for the list views: at
the point the history entry is popped, the list content hasn't been
fetched and rendered yet, so the document is one viewport tall and the
position is clamped to the top. Nothing scrolls back once the content
arrives, leaving the user at the top of the list.

Record the scroll position for each history entry and re-apply it on
POP until the page is able to scroll there, holding it briefly while
the list settles. Positions are kept in session storage so they survive
a page reload.

Coming back to a list that was showing a page other than the first
re-parses the filter from the query string, which looks like a page
change to useScrollToTopOnPageChange and scrolled over the restored
position, so that hook now defers to an in-progress restoration.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GBjwuhWgCvRbAvcYed3mfv
@tassilogravura
tassilogravura force-pushed the fix/back-navigation-scroll-restoration branch from 74a1992 to dbea5e9 Compare August 6, 2026 10:57
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