feat(frontend): reset scroll to top on every route navigation - #59
Conversation
✅ Deploy Preview for moodify-emotion-music-app ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
There was a problem hiding this comment.
Code Review
This pull request introduces a scrollToTopOnEnter function to reset the scroll position to the top of the page when navigating to a new route, triggered by the onEnter hook of the page transition. The reviewer suggests checking for the presence of location.hash before scrolling to prevent overriding and breaking anchor-link scrolling behavior.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| const scrollToTopOnEnter = () => { | ||
| if (typeof window === "undefined") return; | ||
| window.scrollTo(0, 0); | ||
| }; |
There was a problem hiding this comment.
If a user navigates to a new route with a hash anchor (e.g., /privacy-policy#terms-of-service), forcing window.scrollTo(0, 0) will override and break the anchor scrolling behavior. Checking if location.hash is present before scrolling to the top prevents this issue.
| const scrollToTopOnEnter = () => { | |
| if (typeof window === "undefined") return; | |
| window.scrollTo(0, 0); | |
| }; | |
| const scrollToTopOnEnter = () => { | |
| if (typeof window === "undefined") return; | |
| if (location.hash) return; | |
| window.scrollTo(0, 0); | |
| }; |
Navigating between pages (e.g. Home -> Privacy Policy) could leave the user partway down the new page, because the browser kept the previous page's scroll position. Reset the scroll to the top from the CSSTransition `onEnter`, i.e. as the incoming page begins entering. With the out-in transition the old page fades out at its position, then the new page mounts at the top and fades in -- so there's no jarring mid-scroll jump; the existing fade/slide is the smoothness. Tied to the keyed transition (location.pathname), so in-page hash/anchor links are unaffected. 60 tests / 10 snapshots pass; eslint + prettier clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
0369b32 to
63d67b5
Compare
Problem
Navigating between pages (e.g. Home → Privacy Policy) sometimes leaves the user partway down the new page — the browser keeps the previous page's scroll position.
Fix
Reset scroll to the top from the route
CSSTransition'sonEnter— i.e. exactly as the incoming page begins entering:With the existing out-in transition, the old page fades out at its scroll position, then the new page mounts at the top and fades in. No jarring mid-scroll jump — the fade/slide provides the smoothness, and the new page always starts at the top.
location.pathname), so in-page hash/anchor links are left alone.appear).Testing
60 tests / 10 snapshots pass; eslint + prettier clean. Branched off latest master.
🤖 Generated with Claude Code