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

feat(nuxt): start loading indicator state with middleware #21003

Merged
merged 5 commits into from Jun 16, 2023

Conversation

quentint
Copy link
Contributor

πŸ”— Linked issue

This PR aims to fix issue #19528.

❓ 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

This PR introduces 2 new router hooks: router:beforeMiddleware and router:afterMiddleware. These hooks can be useful on their own, but this PR also changes <NuxtLoadingIndicator> so it relies on router:beforeMiddleware, making it reflect any middleware latency.

Resolves #19528.

πŸ“ Checklist

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

@@ -30,7 +30,7 @@ export default defineComponent({
// Hook to app lifecycle
// TODO: Use unified loading API
const nuxtApp = useNuxtApp()
nuxtApp.hook('page:start', indicator.start)
nuxtApp.hook('router:beforeMiddleware', indicator.start)
Copy link
Member

Choose a reason for hiding this comment

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

what about using useRouter().beforeEach(indicator.start) and afterEach instead of introducing new hooks?

Copy link
Member

Choose a reason for hiding this comment

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

Pushed an implementation - what do you think? Do you see any issues with this approach?

@danielroe danielroe requested a review from manniL June 15, 2023 15:27
@danielroe danielroe changed the title feat(nuxt): add router before and after middleware hooks so <NuxtLoadingIndicator> takes middlewares into account feat(nuxt): start loading indicator state with middleware Jun 15, 2023
@danielroe danielroe merged commit 7e74e7c into nuxt:main Jun 16, 2023
22 checks passed
@github-actions github-actions bot mentioned this pull request Jun 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

<NuxtLoadingIndicator> is not taking middleware into account
2 participants