Unverified Commit 56ea3061 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Display error digest if presented (#43742)

Co-authored-by: 's avatarShu Ding <g@shud.in>
Co-authored-by: 's avatarTim Neutkens <tim@timneutkens.nl>
Co-authored-by: 's avatarkodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
parent 2022fa6d
...@@ -70,7 +70,7 @@ export function ErrorBoundary({ ...@@ -70,7 +70,7 @@ export function ErrorBoundary({
return <>{children}</> return <>{children}</>
} }
const styles: { [k: string]: React.CSSProperties } = { const styles = {
error: { error: {
fontFamily: fontFamily:
'-apple-system, BlinkMacSystemFont, Roboto, "Segoe UI", "Fira Sans", Avenir, "Helvetica Neue", "Lucida Grande", sans-serif', '-apple-system, BlinkMacSystemFont, Roboto, "Segoe UI", "Fira Sans", Avenir, "Helvetica Neue", "Lucida Grande", sans-serif',
...@@ -81,7 +81,6 @@ const styles: { [k: string]: React.CSSProperties } = { ...@@ -81,7 +81,6 @@ const styles: { [k: string]: React.CSSProperties } = {
alignItems: 'center', alignItems: 'center',
justifyContent: 'center', justifyContent: 'center',
}, },
desc: { desc: {
display: 'inline-block', display: 'inline-block',
textAlign: 'left', textAlign: 'left',
...@@ -89,25 +88,29 @@ const styles: { [k: string]: React.CSSProperties } = { ...@@ -89,25 +88,29 @@ const styles: { [k: string]: React.CSSProperties } = {
height: '49px', height: '49px',
verticalAlign: 'middle', verticalAlign: 'middle',
}, },
h2: { text: {
fontSize: '14px', fontSize: '14px',
fontWeight: 'normal', fontWeight: 'normal',
lineHeight: '49px', lineHeight: '49px',
margin: 0, margin: 0,
padding: 0, padding: 0,
}, },
} } as const
export function GlobalErrorComponent() { export function GlobalErrorComponent({ error }: { error: any }) {
return ( return (
<html> <html>
<head></head>
<body> <body>
<div style={styles.error}> <div style={styles.error}>
<div style={styles.desc}> <div style={styles.desc}>
<h2 style={styles.h2}> <h2 style={styles.text}>
Application error: a client-side exception has occurred (see the Application error: a client-side exception has occurred (see the
browser console for more information). browser console for more information).
</h2> </h2>
{error?.digest && (
<p style={styles.text}>{`Digest: ${error.digest}`}</p>
)}
</div> </div>
</div> </div>
</body> </body>
......
export default function Page() {
throw Error('custom server error')
}
...@@ -2182,7 +2182,7 @@ describe('app dir', () => { ...@@ -2182,7 +2182,7 @@ describe('app dir', () => {
it('should use default error boundary for prod and overlay for dev when no error component specified', async () => { it('should use default error boundary for prod and overlay for dev when no error component specified', async () => {
const browser = await webdriver( const browser = await webdriver(
next.url, next.url,
'/error/global-error-boundary' '/error/global-error-boundary/client'
) )
await browser.elementByCss('#error-trigger-button').click() await browser.elementByCss('#error-trigger-button').click()
...@@ -2191,16 +2191,34 @@ describe('app dir', () => { ...@@ -2191,16 +2191,34 @@ describe('app dir', () => {
expect(await getRedboxHeader(browser)).toMatch(/this is a test/) expect(await getRedboxHeader(browser)).toMatch(/this is a test/)
} else { } else {
expect( expect(
await browser await browser.waitForElementByCss('body').elementByCss('h2').text()
.waitForElementByCss('body')
.elementByCss('body')
.text()
).toBe( ).toBe(
'Application error: a client-side exception has occurred (see the browser console for more information).' 'Application error: a client-side exception has occurred (see the browser console for more information).'
) )
} }
}) })
it('should display error digest for error in server component with default error boundary', async () => {
const browser = await webdriver(
next.url,
'/error/global-error-boundary/server'
)
if (isDev) {
expect(await hasRedbox(browser)).toBe(true)
expect(await getRedboxHeader(browser)).toMatch(/custom server error/)
} else {
expect(
await browser.waitForElementByCss('body').elementByCss('h2').text()
).toBe(
'Application error: a client-side exception has occurred (see the browser console for more information).'
)
expect(
await browser.waitForElementByCss('body').elementByCss('p').text()
).toMatch(/Digest: \w+/)
}
})
if (!isDev) { if (!isDev) {
it('should allow resetting error boundary', async () => { it('should allow resetting error boundary', async () => {
const browser = await webdriver(next.url, '/error/client-component') const browser = await webdriver(next.url, '/error/client-component')
......
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