Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

fix(nuxt): scroll to top on dynamic routes with different params #8327

Merged
merged 5 commits into from Oct 19, 2022

Conversation

Atinux
Copy link
Member

@Atinux Atinux commented Oct 19, 2022

πŸ”— Linked issue

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 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)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Improvement over #3851 so we scroll to top when it's the same page but with different params.

Example: Going from /movies/14 to /movies/15 should scroll to top.

I am only using params to /movies to /movies?q=test does not scroll to top.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@codesandbox
Copy link

codesandbox bot commented Oct 19, 2022

CodeSandbox logoCodeSandbox logoΒ  Open in CodeSandbox Web Editor | VS Code | VS Code Insiders

@netlify
Copy link

netlify bot commented Oct 19, 2022

βœ… Deploy Preview for nuxt3-docs canceled.

Name Link
πŸ”¨ Latest commit 8a25bb8
πŸ” Latest deploy log https://app.netlify.com/sites/nuxt3-docs/deploys/635002f224f63f0008b65a77

@pi0 pi0 changed the title fix(app): scroll to top on dynamic route with different params fix(nuxt): scroll to top on dynamic routes with different params Oct 19, 2022
@pi0 pi0 merged commit 0106e09 into main Oct 19, 2022
@pi0 pi0 deleted the fix/scroll-behaviour branch October 19, 2022 14:33
@pi0 pi0 mentioned this pull request Nov 3, 2022
@chrisnoden
Copy link

I've updated to rc.13 and am not seeing that this issue is fixed. Navigating to a fresh "page" and the scroll position does not return to the top of the page.

Copy link
Member Author

Atinux commented Nov 4, 2022

It should, can you confirm you don't have a app/router.options.ts in your project?

@chrisnoden
Copy link

I do not have that file. I removed my .nuxt and node_modules before updating to rc.13 and have also updated the @nuxtjs libs. My project works fine in all other respects (so far) but navigating (via NuxtLink) to a fresh page from, eg the footer nav, and the scroll position remains so that the footer is still in view and the actual change to the body can't be seen because it is above the fold.

I'll check it on my minimal nuxt project.

@chrisnoden
Copy link

chrisnoden commented Nov 4, 2022

Confirmed. I tested in a bare bones (only nuxt rc.13) project and if my NuxtLink is at the bottom of a long page, clicking it does not cause the browser to scroll to the top. So, this bug is still not resolved.

I am unable to get rc6 to run now, but from my perspective this issue started with rc7.

LINKED: nuxt/nuxt#14544

@misaon
Copy link
Contributor

misaon commented Nov 4, 2022

Same problem. Nested pages scroll to top is not implemented too.

@chrisnoden
Copy link

Here's my minimal project which demonstrates the issue:
https://github.com/chrisnoden/nuxt3-bug

Copy link
Member Author

Atinux commented Nov 4, 2022

Alright I found the bug, it comes after we removed the transitions by default (PR #8463) cc @danielroe

The hooks to wait is page:transition:finish by default, seems that he does not detect we removed the transitions by default.

To fix that, you can define the app/router.config.ts, see my fix on https://github.com/chrisnoden/nuxt3-bug/pull/1/files

Atinux added a commit that referenced this pull request Nov 4, 2022
Resolves a regression from #8463

Learn more in the comments from #8327
Copy link
Member Author

Atinux commented Nov 4, 2022

Opened a PR to fix this: #8700

Really sorry about the regression 😒

@chrisnoden
Copy link

Thanks for the prompt attention. I can confirm this fixes #8327 (also nuxt/nuxt#15356)

@danielroe danielroe added the 3.x label Jan 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants