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

Restoring scroll position takes too long #25030

Closed
Dananz opened this issue Jan 3, 2024 · 4 comments · Fixed by #25483 · May be fixed by #24960
Closed

Restoring scroll position takes too long #25030

Dananz opened this issue Jan 3, 2024 · 4 comments · Fixed by #25483 · May be fixed by #24960

Comments

@Dananz
Copy link

Dananz commented Jan 3, 2024

Environment

Same as nuxt.com because Im using nuxt.com the example.

Reproduction

https://nuxt.com

Steps to reproduce:

  1. Scroll down a bit
  2. Press ctrl+R
  3. Page should reload and stay in same scroll position but it takes about 400-500ms to restore scroll position

Describe the bug

Nuxt needs to wait until fully hydrated in order to restore scrolling position.
Other web frameworks are not waiting for full hydration and do it instantly on page load.

Additional context

GIF Example:
CleanShot 2024-01-02 at 21 35 31

Logs

No response

@L422Y
Copy link
Contributor

L422Y commented Jan 3, 2024

Minimal reproductions with no modules:
https://github.com/L422Y/scroll-restore

With basic content and no NuxtPage things work as expected:
https://scroll-restore-hz4fqvbf1-l422y.vercel.app

As soon as we start using NuxtPage (even without images) there is a small but noticeable delay:

https://scroll-restore.vercel.app/no-images

https://scroll-restore.vercel.app/defined-image-sizes

https://scroll-restore.vercel.app/undefined-image-sizes

@Dananz
Copy link
Author

Dananz commented Jan 3, 2024

Minimal reproductions with no modules: https://github.com/L422Y/scroll-restore

@L422Y, thanks you for your efforts in creating a minimal reproduction!

While testing your demos on my iPhone, I noticed an issue: the scroll position is not restored after refreshing the page. This problem is not only present in your demo but also reproducible on nuxt.com and in my own application.

Attaching a example video demonstrating the bug. For reference, I am using an iPhone 12 Pro Max running iOS 17.2.1.

RPReplay_Final1704305336.MP4

@manniL
Copy link
Member

manniL commented Jan 3, 2024

@Dananz not sure if that should be a default behavior? 🤔
But you can change that e.g. with a custom scroll behavior (see e.g. https://github.com/manniL/lichter.io/blob/main/app/router.options.ts#L4-L6)

@bernhardberger
Copy link
Contributor

The issue isn't nuxt, it's in upstream vue-router that disables history scroll restoration as soon as a custom ScrollBehavior is defined.

This is fixed in my PR by temporarily re-enabling scroll restoration when appropriate: #24960

bernhardberger added a commit to bernhardberger/nuxt that referenced this issue Jan 7, 2024
handle first page load and page refresh scenarios (restore scroll position without jumps), fixes hash-navigation when changing pages and browser back/forward positions, especiall when page transitions are involved. fixes nuxt#24941, nuxt#22487, nuxt#25030 and nuxt#19664
bernhardberger added a commit to bernhardberger/nuxt that referenced this issue Jan 7, 2024
handle first page load and page refresh scenarios (restore scroll position without jumps), fixes hash-navigation when changing pages and browser back/forward positions, especiall when page transitions are involved. fixes nuxt#24941, nuxt#22487, nuxt#25030 and nuxt#19664

Signed-off-by: Bernhard Berger <bernhard.berger@gmail.com>
bernhardberger added a commit to bernhardberger/nuxt that referenced this issue Jan 7, 2024
handle first page load and page refresh scenarios (restore scroll position without jumps), fixes hash-navigation when changing pages and browser back/forward positions, especiall when page transitions are involved. fixes nuxt#24941, nuxt#22487, nuxt#25030 and nuxt#19664

Signed-off-by: Bernhard Berger <bernhard.berger@gmail.com>
bernhardberger added a commit to bernhardberger/nuxt that referenced this issue Jan 7, 2024
handle first page load and page refresh scenarios (restore scroll position without jumps), fixes hash-navigation when changing pages and browser back/forward positions, especiall when page transitions are involved. fixes nuxt#24941, nuxt#22487, nuxt#25030 and nuxt#19664

Signed-off-by: Bernhard Berger <bernhard.berger@gmail.com>
bernhardberger added a commit to bernhardberger/nuxt that referenced this issue Jan 7, 2024
handle first page load and page refresh scenarios (restore scroll position without jumps), fixes hash-navigation when changing pages and browser back/forward positions, especiall when page transitions are involved. fixes nuxt#24941, nuxt#22487, nuxt#25030 and nuxt#19664

Signed-off-by: Bernhard Berger <bernhard.berger@gmail.com>
bernhardberger added a commit to bernhardberger/nuxt that referenced this issue Jan 7, 2024
handle first page load and page refresh scenarios (restore scroll position without jumps), fixes hash-navigation when changing pages and browser back/forward positions, especiall when page transitions are involved. fixes nuxt#24941, nuxt#22487, nuxt#25030 and nuxt#19664

Signed-off-by: Bernhard Berger <bernhard.berger@gmail.com>
@danielroe danielroe added the bug label Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants