Skip to content
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

Prevent scrolling to top when using router.replace() #21625

Closed
bgoyarts opened this issue Jan 28, 2021 · 2 comments
Closed

Prevent scrolling to top when using router.replace() #21625

bgoyarts opened this issue Jan 28, 2021 · 2 comments
Labels
bug Issue was opened via the bug report template.

Comments

@bgoyarts
Copy link

What version of Next.js are you using?

10.0.5

What version of Node.js are you using?

12

What browser are you using?

Firefox

What operating system are you using?

Windows

How are you deploying your application?

Other platform

Describe the Bug

When using the router to replace the query parameters, the page is scrolled to the top. I have created an example of this on codesandbox

In our scenario we have a listing page with a pagination button. When clicking the pagination button, new items are being loaded and rendered on screen. We store the page-number in the query parameters so we can determine how many items to load when navigating between item detail page and the listing page.

However, this PR seems to have introduced unexpected behavior to our implementation.

Is there a way to prevent the page from scrolling?

Expected Behavior

The page should not scroll.

To Reproduce

I have created a codesandbox here where you will see a list of items. All the way to the bottom of the list is a button which updates the pageNumber, and with it, the amount of items on the page.
When updating the pageNumber, the url parameters are updated through router.replace. This causes the page to scroll to the top.

@bgoyarts bgoyarts added the bug Issue was opened via the bug report template. label Jan 28, 2021
@Timer
Copy link
Member

Timer commented Jan 28, 2021

Fixed in #21437

@Timer Timer closed this as completed Jan 28, 2021
@balazsorban44
Copy link
Member

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.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

3 participants