Next.js Discord

Discord Forum

router.refresh() return page scroll position to the top

Answered
Northeast Congo Lion posted this in #help-forum
Open in Discord
Avatar
Northeast Congo LionOP
Is it intended to scroll back to the top.
I'm checking projects on github that uses router.refresh() for example in button event handlers after some mutations, but it doesn't scroll back to the top.
What could be the problem or it is standard behaviour ?
Answered by Virtue
There must be an error somewhere.
If you post the source code maybe I can find the error.
Image
View full answer

2 Replies

Avatar
There must be an error somewhere.
If you post the source code maybe I can find the error.
Image
Answer
Avatar
Northeast Congo LionOP
Thank you! It was a bug, my fault 🥲 It turned out that one of the components on the page called router.push() inside useEffect (and scroll parameter was not set to false, so it was returning scoll position to the top). It should be called inside this useEffect except the first render in my case, so I've fixed it.