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

fix(nuxt): prevent initial scroll jump when loading page #25483

Merged
merged 1 commit into from Jan 29, 2024

Conversation

danielroe
Copy link
Member

@danielroe danielroe commented Jan 29, 2024

πŸ”— Linked issue

resolves #19664
resolves #25030
resolves #22487

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

When performing an initial load of a page, there are two navigation events that happen, first when the router plugin initialises, and then after all plugins run (to give a chance for plugins to register middleware).

This causes a jump of the scroll to the top and then after all plugins run, it restores the scroll position. However, this is unaesthetic and a bad user experience.

Rather than adjusting the scrollBehavior itself, we can set window.history.scrollRestoration to auto until these first two navigations have taken place.

https://github.com/vuejs/router/blob/main/packages/router/src/router.ts#L378-L381

This supersedes some of #24960 but by no means all. (cc: @bernhardberger)

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have added tests (if possible).
  • I have updated the documentation accordingly.

Copy link

stackblitz bot commented Jan 29, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link
Member

@manniL manniL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really good catch! And also, the stream agrees 😁

@bernhardberger
Copy link
Contributor

bernhardberger commented Jan 29, 2024

Thanks @danielroe - I overlooked this in my PR.

@danielroe danielroe merged commit ecc4c8e into main Jan 29, 2024
36 checks passed
@danielroe danielroe deleted the fix/initial-scroll branch January 29, 2024 13:56
@github-actions github-actions bot mentioned this pull request Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants