Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

router.push scroll config has no effect #57258

Closed
1 task done
alvarlagerlof opened this issue Oct 23, 2023 · 5 comments
Closed
1 task done

router.push scroll config has no effect #57258

alvarlagerlof opened this issue Oct 23, 2023 · 5 comments
Labels
bug Issue was opened via the bug report template. locked

Comments

@alvarlagerlof
Copy link

Link to the code that reproduces this issue

https://github.com/alvarlagerlof/reproduction-router-push-scroll-false-bug

To Reproduce

  1. Start the dev server
  2. Scroll to the bottom of the start page
  3. Click the link
  4. Use the provided example buttons calling various configurations of router.push()

Current vs. Expected behavior

Using router.push with { scroll: false} should be able to keep the previous scroll position as per the docs.

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.0.0: Fri Sep 15 14:42:57 PDT 2023; root:xnu-10002.1.13~1/RELEASE_ARM64_T8112
Binaries:
  Node: 18.17.0
  npm: 9.6.7
  Yarn: 1.22.19
  pnpm: 8.9.2
Relevant Packages:
  next: 13.5.7-canary.16
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.1.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

App Router

Additional context

No response

@alvarlagerlof alvarlagerlof added the bug Issue was opened via the bug report template. label Oct 23, 2023
@Shubhdeep12
Copy link

Hey @alvarlagerlof when we pass scroll: false in router.push then the current scroll position is retained from where the link is clicked.

In your case, since there was no scroll because the height of otherpage is less than the view height of the screen and thus scroll position is 0, you were always pointed back to the top.

If you want to retain the scroll position of the previous page guess the only way is to store the scrollposition somewhere.

@alvarlagerlof
Copy link
Author

Hey @alvarlagerlof when we pass scroll: false in router.push then the current scroll position is retained from where the link is clicked.

In your case, since there was no scroll because the height of otherpage is less than the view height of the screen and thus scroll position is 0, you were always pointed back to the top.

If you want to retain the scroll position of the previous page guess the only way is to store the scrollposition somewhere.

Aha I was expecting it to have the same effect as router.back where if you go back to a page that you've scrolled previously, it keeps that position when you return.

@Shubhdeep12
Copy link

Yeah

@alessiomaffeis
Copy link
Contributor

alessiomaffeis commented Oct 23, 2023

Hey @alvarlagerlof when we pass scroll: false in router.push then the current scroll position is retained from where the link is clicked.

In your case, since there was no scroll because the height of otherpage is less than the view height of the screen and thus scroll position is 0, you were always pointed back to the top.

If you want to retain the scroll position of the previous page guess the only way is to store the scrollposition somewhere.

Got it! That seems to be the case, I didn't notice that before (and I suspect I might not be the only one misunderstanding the expected behavior, based on some comments in this discussion)

I suggested a minor tweak to the wording in the documentation to clarify it: https://github.com/vercel/next.js/pull/57273/files

@alvarlagerlof Then I think this issue is not valid anymore, at least not based on how you described it.

@alvarlagerlof alvarlagerlof closed this as not planned Won't fix, can't repro, duplicate, stale Oct 23, 2023
Copy link
Contributor

github-actions bot commented Nov 7, 2023

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.

@github-actions github-actions bot added the locked label Nov 7, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 7, 2023
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
bug Issue was opened via the bug report template. locked
Projects
None yet
Development

No branches or pull requests

3 participants