diff --git a/packages/next/src/client/app-index.tsx b/packages/next/src/client/app-index.tsx
index a582477530453..be6569079fcb5 100644
--- a/packages/next/src/client/app-index.tsx
+++ b/packages/next/src/client/app-index.tsx
@@ -27,6 +27,7 @@ import { MissingSlotContext } from '../shared/lib/app-router-context.shared-runt
import { setAppBuildId } from './app-build-id'
import { shouldRenderRootLevelErrorOverlay } from './lib/is-error-thrown-while-rendering-rsc'
import { handleClientError } from './components/errors/use-error-handler'
+import { isNextRouterError } from './components/is-next-router-error'
///
@@ -304,7 +305,15 @@ function devQueueSsrError(): Error | undefined {
'data-next-error-message'
)!
const stack = ssrErrorTemplateTag.getAttribute('data-next-error-stack')
+ const digest = ssrErrorTemplateTag.getAttribute('data-next-error-digest')
const error = new Error(message)
+ if (digest) {
+ ;(error as any).digest = digest
+ }
+ // Skip Next.js SSR'd internal errors that which will be handled by the error boundaries.
+ if (isNextRouterError(error)) {
+ return
+ }
error.stack = stack || ''
return error
}
diff --git a/packages/next/src/server/app-render/app-render.tsx b/packages/next/src/server/app-render/app-render.tsx
index c2ced452b9814..8a55b2cfe01ca 100644
--- a/packages/next/src/server/app-render/app-render.tsx
+++ b/packages/next/src/server/app-render/app-render.tsx
@@ -994,6 +994,7 @@ async function getErrorRSCPayload(
{process.env.NODE_ENV !== 'production' && err ? (
) : null}
diff --git a/test/development/app-dir/error-overlay/error-ignored-frames/error-ignored-frames.test.ts b/test/development/app-dir/error-overlay/error-ignored-frames/error-ignored-frames.test.ts
index cbc81732506e4..4bf3aa3d5e4f4 100644
--- a/test/development/app-dir/error-overlay/error-ignored-frames/error-ignored-frames.test.ts
+++ b/test/development/app-dir/error-overlay/error-ignored-frames/error-ignored-frames.test.ts
@@ -54,7 +54,7 @@ describe('error-ignored-frames', () => {
at OuterLayoutRouter (../src/client/components/layout-router.tsx (607:20))
at Router (../src/client/components/app-router.tsx (633:8))
at AppRouter (../src/client/components/app-router.tsx (679:8))
- at ServerRoot (../src/client/app-index.tsx (200:6))"
+ at ServerRoot (../src/client/app-index.tsx (201:6))"
`)
}
})
@@ -85,7 +85,7 @@ describe('error-ignored-frames', () => {
at ClientPageRoot (../src/client/components/client-page.tsx (60:13))
at Router (../src/client/components/app-router.tsx (633:8))
at AppRouter (../src/client/components/app-router.tsx (679:8))
- at ServerRoot (../src/client/app-index.tsx (200:6))"
+ at ServerRoot (../src/client/app-index.tsx (201:6))"
`)
}
})
@@ -128,7 +128,7 @@ describe('error-ignored-frames', () => {
at ClientPageRoot (../src/client/components/client-page.tsx (60:13))
at Router (../src/client/components/app-router.tsx (633:8))
at AppRouter (../src/client/components/app-router.tsx (679:8))
- at ServerRoot (../src/client/app-index.tsx (200:6))"
+ at ServerRoot (../src/client/app-index.tsx (201:6))"
`)
}
})
diff --git a/test/development/app-dir/ssr-only-error/app/notfound/page.tsx b/test/development/app-dir/ssr-only-error/app/notfound/page.tsx
new file mode 100644
index 0000000000000..b50037824b94f
--- /dev/null
+++ b/test/development/app-dir/ssr-only-error/app/notfound/page.tsx
@@ -0,0 +1,7 @@
+import { notFound } from 'next/navigation'
+
+export default async function Home() {
+ notFound()
+}
+
+export const dynamic = 'force-dynamic'
diff --git a/test/development/app-dir/ssr-only-error/ssr-only-error.test.ts b/test/development/app-dir/ssr-only-error/ssr-only-error.test.ts
index e472af021e3f3..20fa235468612 100644
--- a/test/development/app-dir/ssr-only-error/ssr-only-error.test.ts
+++ b/test/development/app-dir/ssr-only-error/ssr-only-error.test.ts
@@ -1,5 +1,6 @@
import { nextTestSetup } from 'e2e-utils'
import {
+ assertNoRedbox,
getRedboxDescription,
getRedboxSource,
hasErrorToast,
@@ -40,4 +41,30 @@ describe('ssr-only-error', () => {
}
`)
})
+
+ it('should not handle internal nextjs errors that will be handled by error boundaries', async () => {
+ const browser = await next.browser('/notfound', {
+ pushErrorAsConsoleLog: true,
+ })
+
+ await assertNoRedbox(browser)
+ expect(await hasErrorToast(browser)).toBe(false)
+
+ const text = await browser.elementByCss('body').text()
+ expect(text).toBe('404\nThis page could not be found.')
+
+ // Assert there's only one console.error from browser itself
+ const errorLogs = (await browser.log()).filter(
+ (log) => log.source === 'error'
+ )
+
+ expect(errorLogs).toEqual([
+ expect.objectContaining({
+ source: 'error',
+ message: expect.stringContaining(
+ 'the server responded with a status of 404'
+ ),
+ }),
+ ])
+ })
})