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): stop loading indicator on vue errors #20738

Merged
merged 2 commits into from May 15, 2023

Conversation

xanderbarkhatov
Copy link
Contributor

πŸ”— Linked issue

#15788

❓ 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

  • Stop loading indicator when there is an error while navigating
  • Call vue:error hook from NuxtErrorBoundary to signal that there was an error

πŸ“ Checklist

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

@codesandbox
Copy link

codesandbox bot commented May 9, 2023

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

if (process.client && !nuxtApp.isHydrating) {
emit('error', err)
nuxtApp.hooks.callHook('vue:error', err, target, info)
Copy link
Member

Choose a reason for hiding this comment

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

My main question about calling it here is that we explicitly say this will only be called when errors propagate up:

In addition, Nuxt provides a `vue:error` hook that will be called if any errors propagate up to the top level.

I think the concept here is that the error boundary establishes a different kind of error handling. But I'm open to discussion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it makes sense.

The problem is that when error occurs inside an error boundary neither page:finish nor vue:error are called, so not only loading indicator remains active, but view transitions are not finished or aborted either.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

What about something like this? It works but I'm not sure. Feels wrong calling page:finish in case of an error.

Maybe we do need something like page:error hook, as it was suggested in the original issue?

Or am I going in the wrong direction?

Copy link
Member

Choose a reason for hiding this comment

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

I think we could use page:finish there πŸ‘

The page: hooks are really about suspense rather than changing route. (They won't run if a page does not have an async setup or async dependencies, for example.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm pretty sure they're called even with a sync setup, because every page is wrapped with a Suspense.

And in that case page:finish gets called twice with my solution 😒

image
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, to recap

// /nuxt/src/pages/runtime/page.ts

setup (props, { attrs }) {
  const nuxtApp = useNuxtApp()

  const done = nuxtApp.deferHydration()

  onErrorCaptured(() => {
    nuxtApp.callHook('page:finish').finally(done)
  })

It works, but for sync components page:finish gets called twice, because onResolve from Suspense also gets called

@danielroe danielroe changed the title fix(nuxt): stop loading indicator on error, call vue:error hook from error boundary fix(nuxt): stop loading indicator on vue errors May 15, 2023
@danielroe danielroe merged commit e9b2f62 into nuxt:main May 15, 2023
18 checks passed
This was referenced May 15, 2023
@xanderbarkhatov xanderbarkhatov deleted the fix/loading-indicator-error branch June 7, 2023 11:56
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.

None yet

2 participants