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): handle errors when booting app with app:error #24376

Merged
merged 6 commits into from Nov 20, 2023

Conversation

antfu
Copy link
Member

@antfu antfu commented Nov 20, 2023

Without a custom errorHandler, Vue will throw an error and crash itself in dev, causing Vue's singleton context has a broken state. In that case, it will cause off-root apps (another createApp) to fail to work. Nuxt DevTools creates a separate app to mount itself, and this PR fixes that DevTools does not work on the error page.

This probably also improves the error capture in Production? As in production, unhandled error are not thrown, make the try catch in entry.ts not been able to capture them.

Copy link

stackblitz bot commented Nov 20, 2023

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

packages/nuxt/src/app/entry.ts Outdated Show resolved Hide resolved
@@ -76,6 +85,8 @@ if (import.meta.client) {
nuxt.payload.error = (nuxt.payload.error || err) as any
}

vueApp.config.errorHandler = prevVueErrorHandler
Copy link
Member Author

Choose a reason for hiding this comment

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

Reset back to undefined. Or should we actually always provide the handler with a better experience?

Copy link
Member

@danielroe danielroe Nov 20, 2023

Choose a reason for hiding this comment

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

Interesting question. I'd be up for always providing an error handler.

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

❗ No coverage uploaded for pull request base (main@6368543). Click here to learn what that means.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #24376   +/-   ##
=======================================
  Coverage        ?   58.76%           
=======================================
  Files           ?        5           
  Lines           ?      861           
  Branches        ?       46           
=======================================
  Hits            ?      506           
  Misses          ?      355           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@danielroe danielroe left a comment

Choose a reason for hiding this comment

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

Does this also need to be included in server-side fork?

@antfu
Copy link
Member Author

antfu commented Nov 20, 2023

errorHandler is only used on the client side, so it should be fine to not set it on server

@danielroe danielroe changed the title fix(nuxt): provide error handler on init app fix(nuxt): handle errors when booting app with app:error Nov 20, 2023
@danielroe danielroe merged commit 1cc05b9 into main Nov 20, 2023
33 checks passed
@danielroe danielroe deleted the feat/vue-handle-error branch November 20, 2023 21:18
@github-actions github-actions bot mentioned this pull request Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants