Unverified Commit 871ca31e authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[app] Send errors not handled by explicit error boundaries through `reportError` (#76101)

parent 0dc87f71
...@@ -244,11 +244,11 @@ function Root({ children }: React.PropsWithChildren<{}>) { ...@@ -244,11 +244,11 @@ function Root({ children }: React.PropsWithChildren<{}>) {
return children return children
} }
const reactRootOptions = { const reactRootOptions: ReactDOMClient.RootOptions = {
onRecoverableError, onRecoverableError,
onCaughtError, onCaughtError,
onUncaughtError, onUncaughtError,
} satisfies ReactDOMClient.RootOptions }
export function hydrate() { export function hydrate() {
const reactEl = ( const reactEl = (
......
...@@ -3,7 +3,7 @@ import { isNextRouterError } from '../is-next-router-error' ...@@ -3,7 +3,7 @@ import { isNextRouterError } from '../is-next-router-error'
import { handleClientError } from '../errors/use-error-handler' import { handleClientError } from '../errors/use-error-handler'
import { parseConsoleArgs } from '../../lib/console' import { parseConsoleArgs } from '../../lib/console'
export const originConsoleError = window.console.error export const originConsoleError = globalThis.console.error
// Patch console.error to collect information about hydration errors // Patch console.error to collect information about hydration errors
export function patchConsoleError() { export function patchConsoleError() {
......
// This file is only used in app router due to the specific error state handling. // This file is only used in app router due to the specific error state handling.
import type { HydrationOptions } from 'react-dom/client' import type { ErrorInfo } from 'react'
import { getReactStitchedError } from '../components/errors/stitched-error' import { getReactStitchedError } from '../components/errors/stitched-error'
import { handleClientError } from '../components/errors/use-error-handler' import { handleClientError } from '../components/errors/use-error-handler'
import { isNextRouterError } from '../components/is-next-router-error' import { isNextRouterError } from '../components/is-next-router-error'
import { isBailoutToCSRError } from '../../shared/lib/lazy-dynamic/bailout-to-csr' import { isBailoutToCSRError } from '../../shared/lib/lazy-dynamic/bailout-to-csr'
import { reportGlobalError } from './report-global-error' import { reportGlobalError } from './report-global-error'
import { originConsoleError } from '../components/globals/intercept-console-error' import { originConsoleError } from '../components/globals/intercept-console-error'
import { AppDevOverlayErrorBoundary } from '../components/react-dev-overlay/app/app-dev-overlay-error-boundary'
import {
ErrorBoundaryHandler,
GlobalError as DefaultErrorBoundary,
} from '../components/error-boundary'
export function onCaughtError(
err: unknown,
errorInfo: ErrorInfo & { errorBoundary?: React.Component }
) {
const errorBoundaryComponent = errorInfo.errorBoundary?.constructor
const isImplicitErrorBoundary =
(process.env.NODE_ENV !== 'production' &&
errorBoundaryComponent === AppDevOverlayErrorBoundary) ||
(errorBoundaryComponent === ErrorBoundaryHandler &&
(errorInfo.errorBoundary! as InstanceType<typeof ErrorBoundaryHandler>)
.props.errorComponent === DefaultErrorBoundary)
if (isImplicitErrorBoundary) {
// We don't consider errors caught unless they're caught by an explicit error
// boundary. The built-in ones are considered implicit.
// This mimics how the same app would behave without Next.js.
return onUncaughtError(err, errorInfo)
}
export const onCaughtError: HydrationOptions['onCaughtError'] = (
err,
errorInfo
) => {
// Skip certain custom errors which are not expected to be reported on client // Skip certain custom errors which are not expected to be reported on client
if (isBailoutToCSRError(err) || isNextRouterError(err)) return if (isBailoutToCSRError(err) || isNextRouterError(err)) return
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
const errorBoundaryComponent = errorInfo?.errorBoundary?.constructor
const errorBoundaryName = const errorBoundaryName =
// read react component displayName // read react component displayName
(errorBoundaryComponent as any)?.displayName || (errorBoundaryComponent as any)?.displayName ||
...@@ -57,26 +76,11 @@ export const onCaughtError: HydrationOptions['onCaughtError'] = ( ...@@ -57,26 +76,11 @@ export const onCaughtError: HydrationOptions['onCaughtError'] = (
} }
} }
export const onUncaughtError: HydrationOptions['onUncaughtError'] = ( export function onUncaughtError(err: unknown, errorInfo: React.ErrorInfo) {
err,
errorInfo
) => {
// Skip certain custom errors which are not expected to be reported on client // Skip certain custom errors which are not expected to be reported on client
if (isBailoutToCSRError(err) || isNextRouterError(err)) return if (isBailoutToCSRError(err) || isNextRouterError(err)) return
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
const componentThatErroredFrame = errorInfo?.componentStack?.split('\n')[1]
// Match chrome or safari stack trace
const matches =
componentThatErroredFrame?.match(/\s+at (\w+)\s+|(\w+)@/) ?? []
const componentThatErroredName = matches[1] || matches[2] || 'Unknown'
// Create error location with errored component and error boundary, to match the behavior of default React onCaughtError handler.
const errorLocation = componentThatErroredName
? `The above error occurred in the <${componentThatErroredName}> component.`
: `The above error occurred in one of your components.`
const stitchedError = getReactStitchedError(err) const stitchedError = getReactStitchedError(err)
// TODO: change to passing down errorInfo later // TODO: change to passing down errorInfo later
// In development mode, pass along the component stack to the error // In development mode, pass along the component stack to the error
...@@ -84,8 +88,7 @@ export const onUncaughtError: HydrationOptions['onUncaughtError'] = ( ...@@ -84,8 +88,7 @@ export const onUncaughtError: HydrationOptions['onUncaughtError'] = (
;(stitchedError as any)._componentStack = errorInfo.componentStack ;(stitchedError as any)._componentStack = errorInfo.componentStack
} }
// Log and report the error with location but without modifying the error stack // TODO: Add an adendum to the overlay telling people about custom error boundaries.
originConsoleError('%o\n\n%s', err, errorLocation)
reportGlobalError(stitchedError) reportGlobalError(stitchedError)
} else { } else {
reportGlobalError(err) reportGlobalError(err)
......
...@@ -4,5 +4,6 @@ export const reportGlobalError = ...@@ -4,5 +4,6 @@ export const reportGlobalError =
// emulating an uncaught JavaScript error. // emulating an uncaught JavaScript error.
reportError reportError
: (error: unknown) => { : (error: unknown) => {
window.console.error(error) // TODO: Dispatch error event
globalThis.console.error(error)
} }
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { import { assertNoRedbox, retry } from 'next-test-utils'
assertHasRedbox,
assertNoRedbox,
openRedbox,
getRedboxDescription,
hasRedboxCallStack,
} from 'next-test-utils'
// TODO: parse the location and assert them in the future
// Remove the location `()` part in every line of stack trace; // Remove the location `()` part in every line of stack trace;
// Remove the leading spaces in every line of stack trace; // Remove the leading spaces in every line of stack trace;
// Remove the trailing spaces in every line of stack trace; // Remove the trailing spaces in every line of stack trace;
function normalizeStackTrace(trace: string) { // These stacks are not sourcemapped and therefore not ignore-listed.
// Feel free to update internal frames in assertions.
function normalizeBrowserConsoleStackTrace(trace: unknown) {
if (typeof trace !== 'string') {
return trace
}
return trace return trace
.replace(/\(.*\)/g, '') .replace(/\(.*\)/g, '')
.replace(/^\s+/gm, '') .replace(/^\s+/gm, '')
.trim() .trim()
} }
async function getStackFramesContent(browser) {
await hasRedboxCallStack(browser)
const stackFrameElements = await browser.elementsByCss(
'[data-nextjs-call-stack-frame]'
)
const stackFramesContent = (
await Promise.all(
stackFrameElements.map(async (frame) => {
const functionNameEl = await frame.$('[data-nextjs-frame-expanded]')
const sourceEl = await frame.$('[data-has-source]')
const functionName = functionNameEl
? await functionNameEl.innerText()
: ''
const source = sourceEl ? await sourceEl.innerText() : ''
if (!functionName) {
return ''
}
return `at ${functionName} (${source})`
})
)
)
.filter(Boolean)
.join('\n')
return stackFramesContent
}
describe('app-dir - owner-stack', () => { describe('app-dir - owner-stack', () => {
const { next } = nextTestSetup({ const { isTurbopack, next } = nextTestSetup({
files: __dirname, files: __dirname,
}) })
it('should log stitched error for browser uncaught errors', async () => { it('should log stitched error for browser uncaught errors', async () => {
const browser = await next.browser('/browser/uncaught') let errorStack: string | undefined
const browser = await next.browser('/browser/uncaught', {
await assertHasRedbox(browser) beforePageLoad: (page) => {
page.on('pageerror', (error: unknown) => {
const stackFramesContent = await getStackFramesContent(browser) errorStack = (error as any).stack
expect(stackFramesContent).toMatchInlineSnapshot(` })
"at useThrowError (app/browser/uncaught/page.js (5:11)) },
at useErrorHook (app/browser/uncaught/page.js (10:3)) })
at Page (app/browser/uncaught/page.js (14:3))"
`)
if (!isTurbopack) {
// Wait for Redbox to settle.
// TODO: Don't reload when landing on a faulty page.
// The issue may be that we receive an HMR update at all on landing.
// This is flaky. Sometimes we miss that the reload happened.
await retry(
async () => {
const logs = await browser.log() const logs = await browser.log()
const errorLog = logs.find((log) => { expect(logs).toEqual(
return log.message.includes('Error: browser error') expect.arrayContaining([
}).message expect.objectContaining({
message:
'[Fast Refresh] performing full reload because your application had an unrecoverable error',
}),
])
)
},
1000,
200
).catch(() => {})
}
if (process.env.TURBOPACK) { await expect(browser).toDisplayRedbox(`
expect(normalizeStackTrace(errorLog)).toMatchInlineSnapshot(` {
"%o "count": 1,
%s Error: browser error "description": "Error: browser error",
at useThrowError "environmentLabel": null,
at useErrorHook "label": "Unhandled Runtime Error",
at Page "source": "app/browser/uncaught/page.js (5:11) @ useThrowError
at react-stack-bottom-frame > 5 | throw new Error('browser error')
at renderWithHooks | ^",
at updateFunctionComponent "stack": [
at beginWork "useThrowError app/browser/uncaught/page.js (5:11)",
at runWithFiberInDEV "useErrorHook app/browser/uncaught/page.js (10:3)",
at performUnitOfWork "Page app/browser/uncaught/page.js (14:3)",
at workLoopSync ],
at renderRootSync }
at performWorkOnRoot
at performWorkOnRootViaSchedulerTask
at MessagePort.performWorkUntilDeadline The above error occurred in the <Page> component. It was handled by the <AppDevOverlayErrorBoundary> error boundary."
`) `)
} else {
expect(normalizeStackTrace(errorLog)).toMatchInlineSnapshot(` expect(normalizeBrowserConsoleStackTrace(errorStack))
"%o .toMatchInlineSnapshot(`
%s Error: browser error "Error: browser error
at useThrowError at useThrowError
at useErrorHook at useErrorHook
at Page at Page
at react-stack-bottom-frame at ClientPageRoot"
at renderWithHooks
at updateFunctionComponent
at beginWork
at runWithFiberInDEV
at performUnitOfWork
at workLoopSync
at renderRootSync
at performWorkOnRoot
at performWorkOnRootViaSchedulerTask
at MessagePort.performWorkUntilDeadline The above error occurred in the <Page> component. It was handled by the <AppDevOverlayErrorBoundary> error boundary."
`) `)
}
}) })
it('should log stitched error for browser caught errors', async () => { it('should log stitched error for browser caught errors', async () => {
...@@ -119,19 +90,26 @@ describe('app-dir - owner-stack', () => { ...@@ -119,19 +90,26 @@ describe('app-dir - owner-stack', () => {
return log.message.includes('Error: browser error') return log.message.includes('Error: browser error')
}).message }).message
await openRedbox(browser) await expect(browser).toDisplayCollapsedRedbox(`
{
const stackFramesContent = await getStackFramesContent(browser) "count": 1,
"description": "Error: browser error",
expect(stackFramesContent).toMatchInlineSnapshot(` "environmentLabel": null,
"at useThrowError (app/browser/caught/page.js (34:11)) "label": "Unhandled Runtime Error",
at useErrorHook (app/browser/caught/page.js (39:3)) "source": "app/browser/caught/page.js (34:11) @ useThrowError
at Thrower (app/browser/caught/page.js (29:3)) > 34 | throw new Error('browser error')
at Inner (app/browser/caught/page.js (23:7)) | ^",
at Page (app/browser/caught/page.js (43:10))" "stack": [
"useThrowError app/browser/caught/page.js (34:11)",
"useErrorHook app/browser/caught/page.js (39:3)",
"Thrower app/browser/caught/page.js (29:3)",
"Inner app/browser/caught/page.js (23:7)",
"Page app/browser/caught/page.js (43:10)",
],
}
`) `)
expect(normalizeStackTrace(errorLog)).toMatchInlineSnapshot(` expect(normalizeBrowserConsoleStackTrace(errorLog)).toMatchInlineSnapshot(`
"%o "%o
%s Error: browser error %s Error: browser error
at useThrowError at useThrowError
...@@ -152,52 +130,55 @@ describe('app-dir - owner-stack', () => { ...@@ -152,52 +130,55 @@ describe('app-dir - owner-stack', () => {
}) })
it('should log stitched error for SSR errors', async () => { it('should log stitched error for SSR errors', async () => {
const browser = await next.browser('/ssr') let errorStack: string | undefined
const browser = await next.browser('/ssr', {
await assertHasRedbox(browser) beforePageLoad: (page) => {
page.on('pageerror', (error: unknown) => {
errorStack = (error as any).stack
})
},
})
const stackFramesContent = await getStackFramesContent(browser) // TODO(veil): Should only display one error.
expect(stackFramesContent).toMatchInlineSnapshot(` await expect(browser).toDisplayRedbox(`
"at useThrowError (app/ssr/page.js (4:9)) {
at useErrorHook (app/ssr/page.js (8:3)) "count": 2,
at Page (app/ssr/page.js (12:3))" "description": "Error: ssr error",
"environmentLabel": null,
"label": "Unhandled Runtime Error",
"source": "app/ssr/page.js (4:9) @ useThrowError
> 4 | throw new Error('ssr error')
| ^",
"stack": [
"useThrowError app/ssr/page.js (4:9)",
"useErrorHook app/ssr/page.js (8:3)",
"Page app/ssr/page.js (12:3)",
],
}
`) `)
const logs = await browser.log() expect(normalizeBrowserConsoleStackTrace(errorStack))
const errorLog = logs.find((log) => { .toMatchInlineSnapshot(`
return log.message.includes('Error: ssr error') "Error: ssr error
}).message
expect(normalizeStackTrace(errorLog)).toMatchInlineSnapshot(`
"%o
%s Error: ssr error
at useThrowError at useThrowError
at useErrorHook at useErrorHook
at Page at Page
at react-stack-bottom-frame at ClientPageRoot"
at renderWithHooks
at updateFunctionComponent
at beginWork
at runWithFiberInDEV
at performUnitOfWork
at workLoopSync
at renderRootSync
at performWorkOnRoot
at performWorkOnRootViaSchedulerTask
at MessagePort.performWorkUntilDeadline The above error occurred in the <Page> component. It was handled by the <AppDevOverlayErrorBoundary> error boundary."
`) `)
}) })
it('should capture unhandled promise rejections', async () => { it('should capture unhandled promise rejections', async () => {
const browser = await next.browser('/browser/reject-promise') const browser = await next.browser('/browser/reject-promise')
await openRedbox(browser) await expect(browser).toDisplayCollapsedRedbox(`
{
const description = await getRedboxDescription(browser) "count": 1,
expect(description).toMatchInlineSnapshot(`"string in rejected promise"`) "description": "string in rejected promise",
"environmentLabel": null,
// Promise rejection has no owner stack "label": "Console Error",
const stackFramesContent = await getStackFramesContent(browser) "source": null,
expect(stackFramesContent).toMatchInlineSnapshot(`""`) "stack": [],
}
`)
}) })
}) })
/* eslint-env jest */ /* eslint-env jest */
import { import { assertNoRedbox, fetchViaHTTP, waitFor, check } from 'next-test-utils'
assertHasRedbox,
assertNoRedbox,
fetchViaHTTP,
getRedboxSource,
getRedboxHeader,
waitFor,
check,
} from 'next-test-utils'
import webdriver, { BrowserInterface } from 'next-webdriver' import webdriver, { BrowserInterface } from 'next-webdriver'
import path from 'path' import path from 'path'
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
...@@ -16,7 +8,7 @@ import { nextTestSetup } from 'e2e-utils' ...@@ -16,7 +8,7 @@ import { nextTestSetup } from 'e2e-utils'
const isReact18 = parseInt(process.env.NEXT_TEST_REACT_VERSION) === 18 const isReact18 = parseInt(process.env.NEXT_TEST_REACT_VERSION) === 18
describe('Client Navigation', () => { describe('Client Navigation', () => {
const { next } = nextTestSetup({ const { isTurbopack, next } = nextTestSetup({
files: path.join(__dirname, 'fixture'), files: path.join(__dirname, 'fixture'),
env: { env: {
TEST_STRICT_NEXT_HEAD: String(true), TEST_STRICT_NEXT_HEAD: String(true),
...@@ -281,10 +273,16 @@ describe('Client Navigation', () => { ...@@ -281,10 +273,16 @@ describe('Client Navigation', () => {
}, },
}) })
await browser.elementByCss('#empty-props').click() await browser.elementByCss('#empty-props').click()
await assertHasRedbox(browser) await expect(browser).toDisplayRedbox(`
expect(await getRedboxHeader(browser)).toMatch( {
/should resolve to an object\. But found "null" instead\./ "count": 1,
) "description": "Error: "EmptyInitialPropsPage.getInitialProps()" should resolve to an object. But found "null" instead.",
"environmentLabel": null,
"label": "Unhandled Runtime Error",
"source": null,
"stack": [],
}
`)
expect(pageErrors).toEqual([ expect(pageErrors).toEqual([
expect.objectContaining({ expect.objectContaining({
message: message:
...@@ -1393,11 +1391,20 @@ describe('Client Navigation', () => { ...@@ -1393,11 +1391,20 @@ describe('Client Navigation', () => {
}) })
}, },
}) })
await assertHasRedbox(browser) await expect(browser).toDisplayRedbox(`
const text = await getRedboxSource(browser) {
expect(text).toMatch(/An Expected error occurred/) "count": 1,
expect(text).toMatch(/pages[\\/]error-inside-browser-page\.js \(5:13\)/) "description": "Error: An Expected error occurred",
"environmentLabel": null,
"label": "Unhandled Runtime Error",
"source": "pages/error-inside-browser-page.js (5:13) @ ErrorInRenderPage.render
> 5 | throw new Error('An Expected error occurred')
| ^",
"stack": [
"ErrorInRenderPage.render pages/error-inside-browser-page.js (5:13)",
],
}
`)
expect(pageErrors).toEqual( expect(pageErrors).toEqual(
isReact18 isReact18
? [ ? [
...@@ -1437,10 +1444,42 @@ describe('Client Navigation', () => { ...@@ -1437,10 +1444,42 @@ describe('Client Navigation', () => {
}, },
} }
) )
await assertHasRedbox(browser)
const text = await getRedboxSource(browser) if (isTurbopack) {
expect(text).toMatch(/An Expected error occurred/) await expect(browser).toDisplayRedbox(`
expect(text).toMatch(/error-in-the-browser-global-scope\.js \(2:9\)/) {
"count": 1,
"description": "Error: An Expected error occurred",
"environmentLabel": null,
"label": "Unhandled Runtime Error",
"source": "pages/error-in-the-browser-global-scope.js (2:9) @ [project]/pages/error-in-the-browser-global-scope.js [client] (ecmascript)
> 2 | throw new Error('An Expected error occurred')
| ^",
"stack": [
"[project]/pages/error-in-the-browser-global-scope.js [client] (ecmascript) pages/error-in-the-browser-global-scope.js (2:9)",
],
}
`)
} else {
await expect(browser).toDisplayRedbox(`
{
"count": 1,
"description": "Error: An Expected error occurred",
"environmentLabel": null,
"label": "Unhandled Runtime Error",
"source": "pages/error-in-the-browser-global-scope.js (2:9) @ eval
> 2 | throw new Error('An Expected error occurred')
| ^",
"stack": [
"eval pages/error-in-the-browser-global-scope.js (2:9)",
"<FIXME-file-protocol>",
"<FIXME-file-protocol>",
"<FIXME-file-protocol>",
"<FIXME-file-protocol>",
],
}
`)
}
expect(pageErrors).toEqual([ expect(pageErrors).toEqual([
expect.objectContaining({ message: 'An Expected error occurred' }), expect.objectContaining({ message: 'An Expected error occurred' }),
]) ])
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { assertHasRedbox, getRedboxHeader, retry } from 'next-test-utils' import { retry } from 'next-test-utils'
import stripAnsi from 'strip-ansi' import stripAnsi from 'strip-ansi'
describe('app-dir - errors', () => { describe('app-dir - errors', () => {
...@@ -174,8 +174,20 @@ describe('app-dir - errors', () => { ...@@ -174,8 +174,20 @@ describe('app-dir - errors', () => {
await browser.elementByCss('#error-trigger-button').click() await browser.elementByCss('#error-trigger-button').click()
if (isNextDev) { if (isNextDev) {
await assertHasRedbox(browser) await expect(browser).toDisplayRedbox(`
expect(await getRedboxHeader(browser)).toMatch(/this is a test/) {
"count": 1,
"description": "Error: this is a test",
"environmentLabel": null,
"label": "Unhandled Runtime Error",
"source": "app/global-error-boundary/client/page.js (8:11) @ Page
> 8 | throw new Error('this is a test')
| ^",
"stack": [
"Page app/global-error-boundary/client/page.js (8:11)",
],
}
`)
} else { } else {
expect( expect(
await browser.waitForElementByCss('body').elementByCss('h2').text() await browser.waitForElementByCss('body').elementByCss('h2').text()
...@@ -184,8 +196,11 @@ describe('app-dir - errors', () => { ...@@ -184,8 +196,11 @@ describe('app-dir - errors', () => {
) )
} }
// FIXME(veil): Should contain thrown error. expect(pageErrors).toEqual([
expect(pageErrors).toEqual([]) expect.objectContaining({
message: 'this is a test',
}),
])
}) })
it('should display error digest for error in server component with default error boundary', async () => { it('should display error digest for error in server component with default error boundary', async () => {
...@@ -199,8 +214,20 @@ describe('app-dir - errors', () => { ...@@ -199,8 +214,20 @@ describe('app-dir - errors', () => {
}) })
if (isNextDev) { if (isNextDev) {
await assertHasRedbox(browser) await expect(browser).toDisplayRedbox(`
expect(await getRedboxHeader(browser)).toMatch(/custom server error/) {
"count": 1,
"description": "Error: custom server error",
"environmentLabel": "Server",
"label": "Unhandled Runtime Error",
"source": "app/global-error-boundary/server/page.js (2:9) @ Page
> 2 | throw Error('custom server error')
| ^",
"stack": [
"Page app/global-error-boundary/server/page.js (2:9)",
],
}
`)
} else { } else {
expect( expect(
await browser.waitForElementByCss('body').elementByCss('h2').text() await browser.waitForElementByCss('body').elementByCss('h2').text()
...@@ -212,8 +239,15 @@ describe('app-dir - errors', () => { ...@@ -212,8 +239,15 @@ describe('app-dir - errors', () => {
).toMatch(/Digest: \w+/) ).toMatch(/Digest: \w+/)
} }
// FIXME(veil): Should contain thrown error. expect(pageErrors).toEqual([
expect(pageErrors).toEqual([]) expect.objectContaining({
message: isNextDev
? 'custom server error'
: 'An error occurred in the Server Components render. ' +
'The specific message is omitted in production builds to avoid leaking sensitive details. ' +
'A digest property is included on this error instance which may provide additional details about the nature of the error.',
}),
])
}) })
// production tests // production tests
...@@ -244,13 +278,17 @@ describe('app-dir - errors', () => { ...@@ -244,13 +278,17 @@ describe('app-dir - errors', () => {
}) })
it('should hydrate empty shell to handle server-side rendering errors', async () => { it('should hydrate empty shell to handle server-side rendering errors', async () => {
const browser = await next.browser('/ssr-error-client-component') const pageErrors: unknown[] = []
const logs = await browser.log() await next.browser('/ssr-error-client-component', {
const errors = logs beforePageLoad: (page) => {
.filter((x) => x.source === 'error') page.on('pageerror', (error: unknown) => {
.map((x) => x.message) pageErrors.push(error)
.join('\n') })
expect(errors).toInclude('Error during SSR') },
})
expect(pageErrors).toEqual([
expect.objectContaining({ message: 'Error during SSR' }),
])
}) })
it('should log the original RSC error trace in production', async () => { it('should log the original RSC error trace in production', async () => {
......
...@@ -30,6 +30,7 @@ declare global { ...@@ -30,6 +30,7 @@ declare global {
* Unintented content in the snapshot should be reported to the Next.js DX team. * Unintented content in the snapshot should be reported to the Next.js DX team.
* `<FIXME-internal-frame>` in the snapshot would be unintended. * `<FIXME-internal-frame>` in the snapshot would be unintended.
* `<FIXME-project-root>` in the snapshot would be unintended. * `<FIXME-project-root>` in the snapshot would be unintended.
* `<FIXME-file-protocol>` in the snapshot would be unintended.
* Any node_modules in the snapshot would be unintended. * Any node_modules in the snapshot would be unintended.
* Differences in the snapshot between Turbopack and Webpack would be unintended. * Differences in the snapshot between Turbopack and Webpack would be unintended.
* *
...@@ -48,6 +49,7 @@ declare global { ...@@ -48,6 +49,7 @@ declare global {
* Unintented content in the snapshot should be reported to the Next.js DX team. * Unintented content in the snapshot should be reported to the Next.js DX team.
* `<FIXME-internal-frame>` in the snapshot would be unintended. * `<FIXME-internal-frame>` in the snapshot would be unintended.
* `<FIXME-project-root>` in the snapshot would be unintended. * `<FIXME-project-root>` in the snapshot would be unintended.
* `<FIXME-file-protocol>` in the snapshot would be unintended.
* Any node_modules in the snapshot would be unintended. * Any node_modules in the snapshot would be unintended.
* Differences in the snapshot between Turbopack and Webpack would be unintended. * Differences in the snapshot between Turbopack and Webpack would be unintended.
* *
......
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