-
Notifications
You must be signed in to change notification settings - Fork 27.1k
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
Internal next/link to #fragment does not correctly scroll to target #26780
Comments
Please verify that your issue can be recreated with Why was this issue marked with the
|
This issue has been automatically closed because it wasn't verified against next@canary. If you think it was closed by accident, please leave a comment. If you are running into a similar issue, please open a new issue with a reproduction. Thank you. |
This closed issue has been automatically locked because it had no new activity for a month. 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.0.1/11.0.2-canary.3
What version of Node.js are you using?
14.15.4
What browser are you using?
Firefox/Chrome
What operating system are you using?
Linux/MacOS
How are you deploying your application?
next dev/start/export
Describe the Bug
The docs say that
next/link
will honour the #fragment and scroll us to the target element on the destination page.This doesn't appear to be working for me.
I'm sometimes getting scrolled to the very bottom of the destination page (nowhere near the target element, and this seems to be more common in Chrome), or sometimes to some other point in the page (both Firefox and Chrome).
I have determined that when I end up on some seemingly meaningless point on the target page, the
window.scrollY
is identical to where it was on the previous page when the link was clicked.Expected Behavior
On the destination page, we end up with the targeted element at or near the top of the viewport.
To Reproduce
An example of the issue is at https://cesium.com/events/ which has been deployed via
next export
. I see the same issue when runningnext dev
.Near the very bottom of the page, click any of the yellow "view presentation" links, which point to fragments of a different page via
next/link
. The Earth Archive one, for example, should land us very near the top of the destination page, but I never land there; I usually land significantly further down the page.In a dev console, check
window.scrollY
before and after the navigation -- I usually see that the number is identical, i.e. we have not changed scroll position at all.I have been trying to debug this by putting
debugger
andconsole.log
statements in thenode_modules/next/dist/next-server/lib/router/router.js
andnode_modules/next/dist/client/link.js
and restarting my dev server, but I can't seem to make anything change -- I see no logs and the debugger doesn't trip. I can even return early from those functions but they still act as if I haven't changed anything. I must be editing the wrong files. Meanwhile, using the debugger in Chrome or Firefox isn't allowing me to put a breakpoint anywhere useful -- it insists on putting it at the start of the file no matter whether sourcemaps are on or off, or I've got code prettifying on or off. Wonder what I'm doing wrong, but I'm stuck.The text was updated successfully, but these errors were encountered: