Unverified Commit ec1fefca authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

[dev-overlay] handle ssrd nextjs internal errors in overlay (#76124)

parent 473d47a6
...@@ -27,6 +27,7 @@ import { MissingSlotContext } from '../shared/lib/app-router-context.shared-runt ...@@ -27,6 +27,7 @@ import { MissingSlotContext } from '../shared/lib/app-router-context.shared-runt
import { setAppBuildId } from './app-build-id' import { setAppBuildId } from './app-build-id'
import { shouldRenderRootLevelErrorOverlay } from './lib/is-error-thrown-while-rendering-rsc' import { shouldRenderRootLevelErrorOverlay } from './lib/is-error-thrown-while-rendering-rsc'
import { handleClientError } from './components/errors/use-error-handler' import { handleClientError } from './components/errors/use-error-handler'
import { isNextRouterError } from './components/is-next-router-error'
/// <reference types="react-dom/experimental" /> /// <reference types="react-dom/experimental" />
...@@ -304,7 +305,15 @@ function devQueueSsrError(): Error | undefined { ...@@ -304,7 +305,15 @@ function devQueueSsrError(): Error | undefined {
'data-next-error-message' 'data-next-error-message'
)! )!
const stack = ssrErrorTemplateTag.getAttribute('data-next-error-stack') const stack = ssrErrorTemplateTag.getAttribute('data-next-error-stack')
const digest = ssrErrorTemplateTag.getAttribute('data-next-error-digest')
const error = new Error(message) 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 || '' error.stack = stack || ''
return error return error
} }
......
...@@ -994,6 +994,7 @@ async function getErrorRSCPayload( ...@@ -994,6 +994,7 @@ async function getErrorRSCPayload(
{process.env.NODE_ENV !== 'production' && err ? ( {process.env.NODE_ENV !== 'production' && err ? (
<template <template
data-next-error-message={err.message} data-next-error-message={err.message}
data-next-error-digest={'digest' in err ? err.digest : ''}
data-next-error-stack={err.stack} data-next-error-stack={err.stack}
/> />
) : null} ) : null}
......
...@@ -54,7 +54,7 @@ describe('error-ignored-frames', () => { ...@@ -54,7 +54,7 @@ describe('error-ignored-frames', () => {
at OuterLayoutRouter (../src/client/components/layout-router.tsx (607:20)) at OuterLayoutRouter (../src/client/components/layout-router.tsx (607:20))
at Router (../src/client/components/app-router.tsx (633:8)) at Router (../src/client/components/app-router.tsx (633:8))
at AppRouter (../src/client/components/app-router.tsx (679: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', () => { ...@@ -85,7 +85,7 @@ describe('error-ignored-frames', () => {
at ClientPageRoot (../src/client/components/client-page.tsx (60:13)) at ClientPageRoot (../src/client/components/client-page.tsx (60:13))
at Router (../src/client/components/app-router.tsx (633:8)) at Router (../src/client/components/app-router.tsx (633:8))
at AppRouter (../src/client/components/app-router.tsx (679: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', () => { ...@@ -128,7 +128,7 @@ describe('error-ignored-frames', () => {
at ClientPageRoot (../src/client/components/client-page.tsx (60:13)) at ClientPageRoot (../src/client/components/client-page.tsx (60:13))
at Router (../src/client/components/app-router.tsx (633:8)) at Router (../src/client/components/app-router.tsx (633:8))
at AppRouter (../src/client/components/app-router.tsx (679: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))"
`) `)
} }
}) })
......
import { notFound } from 'next/navigation'
export default async function Home() {
notFound()
}
export const dynamic = 'force-dynamic'
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { import {
assertNoRedbox,
getRedboxDescription, getRedboxDescription,
getRedboxSource, getRedboxSource,
hasErrorToast, hasErrorToast,
...@@ -40,4 +41,30 @@ describe('ssr-only-error', () => { ...@@ -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'
),
}),
])
})
}) })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment