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

Page loading triggered when navigating to same page with different fragment #27157

Open
lhoucinecherif opened this issue May 11, 2024 · 9 comments

Comments

@lhoucinecherif
Copy link

Environment

  • Operating System: Linux
  • Node Version: v20.9.0
  • Nuxt Version: 3.10.0
  • CLI Version: 3.10.0
  • Nitro Version: 2.8.1
  • Package Manager: [email protected]
  • Builder: -
  • User Config: css, devtools
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://codesandbox.io/p/devbox/nuxt-link-test-fqzqn9

Describe the bug

When using NuxtLink components within a Nuxt 3 project, I've noticed that clicking on a NuxtLink with "#" as the value (e.g., <NuxtLink to="#">) triggers the 'page:loading:start' hook, even when navigating to the same page. This behavior is unexpected and can be confusing for users.

You can observe the loading even if you're already on the current page by clicking on the links (anchor links) provided in the example (https://codesandbox.io/p/devbox/nuxt-link-test-fqzqn9).

Additional context

I believe that clicking on a NuxtLink component with "#" as the value should not trigger the loading indicator, as it indicates navigation to the same page. This behavior should be consistent with user expectations and improve the overall user experience.

Thank you for your attention to this matter.

Logs

No response

@uniqueeest
Copy link

hello, @manniL ! Can I solve this problem?

@manniL
Copy link
Member

manniL commented May 12, 2024

@uniqueeest Sure, go ahead ☺️

@uniqueeest
Copy link

@manniL Should I stop the move from nuxtlink to # altogether?

@manniL
Copy link
Member

manniL commented May 14, 2024

@uniqueeest no no, the main part is not triggering the loading indicator if only the hash is different

@uniqueeest
Copy link

@manniL sorry. I'm a beginner, so I don't know where to fix it 😢

@manniL
Copy link
Member

manniL commented May 20, 2024

@uniqueeest Take a look at this PR as a starting point. Changing the logic there to "ignore" differences between the fragment should be fine

@manniL
Copy link
Member

manniL commented May 20, 2024

Actually, the reproduction is not using the NuxtLoadingIndicator nor useLoadingIndicator. Using it should work fine as the diffing is done there.

@manniL manniL closed this as not planned Won't fix, can't repro, duplicate, stale May 20, 2024
@manniL manniL changed the title Clicking on NuxtLink with "#" as Value Triggers Loading of The Page Page loading triggered when navigating to same page with different fragment May 20, 2024
@manniL
Copy link
Member

manniL commented May 20, 2024

Re-opening as the "actual issue" is valid though (+renamed the title)

@manniL manniL reopened this May 20, 2024
@danielroe
Copy link
Member

The issue is here that vue router regards this as a 'navigation' event, so it will trigger middleware - and it is even possible to force reloading the page in this case (with a custom page-key passed to <NuxtPage>).

We start the loading when middleware begins, because if middleware perform data fetching this should be shown as part of the page loading.

As long as these two things are the case, I think it is correct that this triggers a loading event. Because you are creating a custom integration with the page:loading:start hook, it might be more appropriate to handle this edge case yourself. (Perhaps we could pass an argument to the hook to allow you to do this more easily?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants