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
Allow scroll-to-top with shallow routing #21606
Comments
Feel free to send a PR. |
This functionality already exists but the official docs has not been updated yet. See #20606 for more information. You can do:
to disable the auto scroll. |
For shallow routing, this is no longer true with v10.0.6. see #21437 |
I experienced this today as well. Although there are cases where with shallow routing one might not want the page to scroll up, I think there are some where it's convenient. For example, using shallow routing to change pages via query string params (for frontend pagination without refetching data).
The docs currently say that the default behavior is to obey scroll to top, but this is not happening with
|
I have the same problem. I'm doing pagination based on query parameters and only the initial fetch is made with SSR. When the user changes a page, the query is updated and then the fetch is made on the client-side. I would like to have the option to scroll to the top after a shallow route push. |
I have the same exact use case as @luismramirezr. Bummer that this broke. |
Seeing the same "issue" here, although I can understand why it was made to behave this way. We have one case where scrolling to the top is exactly what we want, because the content being swapped is near the top of the page. On the other hand, we have a different case where the paginated content lives much further down the page. In that scenario, we actually don't want to scroll all the way to the top of the page, because that would blow way past the content being refreshed and would be even worse than staying in the same spot. IMO, the "safest" thing to do is append an anchor link (ex.
That way you have full control of exactly where the browser should scroll upon clicking the shallow link. In this case, we may want to scroll up a bit to where the list of posts begins. It's a bit more work, but it's the only reasonable approach because only you know where that particular content actually starts on the page. |
IMO the scroll option should just take precedence over opinionated default behavior when it's explicitly set. |
Exactly. |
Hi @timneutkens, we'd really like to see this fixed and as you might've noticed I opened a pull request with regard to this issue. Alvast bedankt! |
Posted a reply here: #24888 (review) |
…#24888) ## Bug - [x] Related issues linked using `fixes #number` - [ ] Integration tests added fixes [vercel#21606](vercel#21606) ### Description When using shallow routing and wanting to scroll to top by setting the `scroll` option to `true` it didn't work. This PR fixes this issue.
This issue has been automatically locked due to no recent activity. 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?
10.0.6-canary.9
What version of Node.js are you using?
14.15.4
What browser are you using?
Firefox 84
What operating system are you using?
Ubuntu 20.04
How are you deploying your application?
Vercel
Describe the Bug
Recently (i think 10.0.6-canary.8) the behavior for shallow routing was changed to not scroll-to-top anymore. While this makes sense as a default behavior, it should still be possible to force scrolling by providing
<Link shallow scroll>
orrouter.push(path, undefined, { shallow: true, scroll: true )
.Expected Behavior
<Link shallow scroll>
androuter.push(path, undefined, { shallow: true, scroll: true )
should scroll to top.To Reproduce
The text was updated successfully, but these errors were encountered: