Repository navigation
feat(nuxt): Capture errors caught by <NuxtErrorBoundary> during SSR #26815
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
Open
pranav514
wants to merge
4
commits into
getsentry:develop
Choose a base branch
from
pranav514:feat/nuxt-ssr-error-boundary
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+79
−11
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ecc2714
feat(nuxt): Capture errors caught by <NuxtErrorBoundary> during SSR
pranav514 bc1947a
fix(nuxt): Synchronously capture and flush SSR error boundary errors
pranav514 baa820c
refactor(nuxt): Address maintainer review for SSR error boundary
pranav514 a6b5818
refactor(nuxt): Apply review suggestions for SSR error boundary E2E test
pranav514 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
dev-packages/e2e-tests/test-applications/nuxt-5/app/components/SSRErrorComponent.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <script setup> | ||
| if (import.meta.server) { | ||
| throw new Error('SSR Error inside NuxtErrorBoundary'); | ||
| } | ||
| </script> | ||
|
|
||
| <template> | ||
| <div>Normal SSR Content</div> | ||
| </template> |
14 changes: 14 additions & 0 deletions
14
dev-packages/e2e-tests/test-applications/nuxt-5/app/pages/ssr-error-boundary.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <script setup> | ||
| import SSRErrorComponent from '../components/SSRErrorComponent.vue'; | ||
| </script> | ||
|
|
||
| <template> | ||
| <div> | ||
| <NuxtErrorBoundary> | ||
| <SSRErrorComponent /> | ||
| <template #error="{ error }"> | ||
| <p id="error-fallback">Caught SSR Error: {{ error.message }}</p> | ||
| </template> | ||
| </NuxtErrorBoundary> | ||
| </div> | ||
| </template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
packages/nuxt/src/runtime/plugins/error-boundary.server.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import { defineNuxtPlugin } from 'nuxt/app'; | ||
| import { reportNuxtError } from '../utils'; | ||
| import { isIgnoredNuxtError } from '../utils/isIgnoredNuxtError'; | ||
|
|
||
| export default defineNuxtPlugin(nuxtApp => { | ||
| const caught: Parameters<typeof reportNuxtError>[0][] = []; | ||
| nuxtApp.hook('vue:error', (error, instance, info) => { | ||
| if (!isIgnoredNuxtError(error)) caught.push({ error, instance, info }); | ||
| }); | ||
| // The Nitro `error` hook reports errors that end on the error page. | ||
| nuxtApp.hook('app:rendered', () => { | ||
| if (!nuxtApp.payload.error) caught.forEach(reportNuxtError); | ||
| }); | ||
| }); | ||
|
cursor[bot] marked this conversation as resolved.
Resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { isNuxtError } from 'nuxt/app'; | ||
|
|
||
| // 3xx/4xx Nuxt errors are expected control flow (redirects, not-found pages), not bugs. The server skips them too. | ||
| export function isIgnoredNuxtError(error: unknown): boolean { | ||
| if (!isNuxtError(error)) { | ||
| return false; | ||
| } | ||
| // oxlint-disable-next-line typescript/no-deprecated | ||
| const statusCode = error?.status || error?.statusCode; | ||
| return !!statusCode && statusCode >= 300 && statusCode < 500; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This plugin is re-writing a lot of code that already exists. By reusing the things we already have, this can be condensed to just this: