You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I start my application and land on the homepage, it seems that there is no window scroll entry saved in the scroll restoration cache.
As a result, if I navigate to another page, scroll down, then go back to the homepage, the scroll position is incorrectly restored — instead of resetting to scroll position 0, it retains the scroll position from the second page.
I’ve seen other issues related to scroll restoration, but this doesn’t seem to be exactly the same problem:
Run the application, go to the home page (without scrolling)
Go to About page
Scroll a bit
Go back to previous page
Expected behavior
When I go back to the previous page, it should go back to the previous position (0,0) instead of the current page position.
Screenshots or Videos
Platform
Router: 1.129.8
OS: Windows (WSL)
Browser: Firefox
Browser Version: 141.0
Bundler: Vite
Bundler Version: 6.3.5
Additional context
It seems like the onScroll function in scroll-restoration.ts should be called during initialization, not only in response to scroll events via the event listener.
For example, if I manually call onScroll({ target: window }) right after the onScroll function is declared, the issue appears to be resolved.
Of course, that’s a dirty solution, but I think it demonstrates the root of the problem.
Activity
fix: scroll to top if no scroll restoration entry exists