-
Notifications
You must be signed in to change notification settings - Fork 28.9k
Description
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 running next 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
and console.log
statements in the node_modules/next/dist/next-server/lib/router/router.js
and node_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.