-
Notifications
You must be signed in to change notification settings - Fork 27k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not scroll to top after changing route #28778
Comments
Bump. Facing same issue. Using to navigate but it doesn't scroll to top as mentioned in documentation. But mine just doesn't work on every device, regardless of OS & browser type Edit:
in the layout component |
Having same issue even with router.push("/",{ scroll: true }) |
Seems like the bug is there only when router.push() is called nested in some deep function like onSubmit() |
Even i am also facing the same issue . As per documentation https://nextjs.org/docs/api-reference/next/router#routerpush, Any update on this issue ? |
@timneutkens can you help in checking this issue ? |
@TanDung2512 I just tested your reproduction on iOS Chrome, and could not reproduce the issue. I deployed it here: https://28778.vercel.app/ I suspect if it ever was, it might have been a browser bug that is now fixed. 👍 Could you see if this is an issue still? Otherwise, I'll need a new reproduction. For anyone else, if you think it is a bug, please open a separate bug report and attach your reproduction. Or you can ask for help in the Discussions 🙏 |
Ok i got this fix.
|
Interestingly, this does fix the issue. Finally can drop my |
Same issue here. Except that I do need to keep Are there any solutions to this? |
Try adding the height: 100% to body instead of httml |
@Gabsys @lumenwrites @TanDung2512 if you are able to reproduce, could you please link to a reproduction? 🙏 |
Here you go: https://codesandbox.io/s/next-js-failed-to-scroll-top-bug-bjfrr After playing around, it seems like |
@balazsorban44 @Gabsys good example, I tried to remove both: height: 100%;
overflow-x: hidden; And it doesn't scroll to the top when I go to the |
Thanks for creating the sandbox. The bug is easily reproducible indeed. Something has to be done with How could we raise the bug priority up? |
for me it works when running in dev mode, but no in production mode |
I already ditched this |
No new update found. Any solution ? |
Also experiencing this, especially on iOS, and the |
I experienced this bug only in Firefox on Ubuntu, all the other browsers are working fine. |
I removed following prop in my global.css for body and kept
And it seems to work again. |
Same problem.. When I refresh the page or navigate to another page the scroll stay at his position. |
Solved this problem by removing |
I am on version
|
@nmitic does this work if you have an anchor tag down the page? The browser might scroll to it but you code will scroll back to the top. I think we need a solution that scroll to the top right before changing the page |
You are definitely right. I just reverted my fix because it doesn't actually work properly as it has slight delay after you navigate. And as I am doing navigation with framer motion it looks very ugly. |
Just to add some findings of mine.
When I remove sticky, scroll restoration works fine. |
Sorry for spamming you guys, but the solution for me was to add extra empty div before the sticky or fixed positioned element.
After this scroll restoration works as expected. |
Is there a way to disable scrolling to the top of the page when using I'm calling |
@oncet |
That's awesome! Do you know in which version is available? I'm using |
@oncet The feature landed in the latest release |
We need the option to initialize the scroll position (top: 0, left: 0) when the page changes. |
This worked for me, but how do I stop the page from scrolling to that section (i.e. it automatically redirects to that section)? |
every page may include 'nav component' use this in nav component 'use client'
import { usePathname } from "next/navigation";
import { useEffect } from "react";
//....
export function MainNav(props){
const pathname = usePathname();
useEffect(()=>{
window.scrollTo(0,0);
},[pathname])
return(
<nav>mynav</nav>
)
} |
with this solution, it is scrolling when reload (ctrl+r) the same page, i think it should scroll on route (to other pages) |
on version 13.4.13 and none of the solutions worked for me. No overflow or height set for body or html in css, I don't have fixed or sticky elements either... |
|
sorry to waste your time! rookie mistake... while I was trying to reproduce the issue on an example project I realised I had a mysterious {" "} before the first element in the pages I was trying to route to. Removing it solved the problem |
Hey all! As mentioned in the thread there are a couple of different solutions to the various different issues that have been brought up, some of which have landed as features or bugfixes in newer versions of Next, namely:
I'm going to close this thread, but if you run into a scenario that seems like a bug, please open a new issue with a minimal reproduction so that we can investigate it. Thank you! |
i had the same problem i fixed it by changing the component wrapper from <></> to , its silly but someone could have the same problem LOL |
Add extra div at the top
|
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
What version of Next.js are you using?
11.1.2
What version of Node.js are you using?
v15.9.0
What browser are you using?
Chrome
What operating system are you using?
macOS
How are you deploying your application?
next start
Describe the Bug
I have two pages, each one contains lazy render components. After changing route by clicking . The page doesn't scroll to top. This happens on Chrome IOS (work well on safari IOS)
Expected Behavior
It should scroll to top after changing page
To Reproduce
I have created a demo project here: https://github.com/TanDung2512/demo-bug-scroll-nextjs
RPReplay_Final1630728078.MP4
NEXT-1347
The text was updated successfully, but these errors were encountered: