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
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'
/// <reference types="react-dom/experimental" />
......@@ -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
}
......
......@@ -994,6 +994,7 @@ async function getErrorRSCPayload(
{process.env.NODE_ENV !== 'production' && err ? (
<template
data-next-error-message={err.message}
data-next-error-digest={'digest' in err ? err.digest : ''}
data-next-error-stack={err.stack}
/>
) : null}
......
......@@ -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))"
`)
}
})
......
import { notFound } from 'next/navigation'
export default async function Home() {
notFound()
}
export const dynamic = 'force-dynamic'
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'
),
}),
])
})
})
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