Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display error digest if presented #43742

Merged
merged 9 commits into from Dec 7, 2022
15 changes: 9 additions & 6 deletions packages/next/client/components/error-boundary.tsx
Expand Up @@ -70,7 +70,7 @@ export function ErrorBoundary({
return <>{children}</>
}

const styles: { [k: string]: React.CSSProperties } = {
const styles = {
error: {
fontFamily:
'-apple-system, BlinkMacSystemFont, Roboto, "Segoe UI", "Fira Sans", Avenir, "Helvetica Neue", "Lucida Grande", sans-serif',
Expand All @@ -81,33 +81,36 @@ const styles: { [k: string]: React.CSSProperties } = {
alignItems: 'center',
justifyContent: 'center',
},

desc: {
display: 'inline-block',
textAlign: 'left',
lineHeight: '49px',
height: '49px',
verticalAlign: 'middle',
},
h2: {
text: {
fontSize: '14px',
fontWeight: 'normal',
lineHeight: '49px',
margin: 0,
padding: 0,
},
}
} as const

export function GlobalErrorComponent() {
export function GlobalErrorComponent({ error }: { error: any }) {
return (
<html>
<head></head>
<body>
<div style={styles.error}>
<div style={styles.desc}>
<h2 style={styles.h2}>
<h2 style={styles.text}>
Application error: a client-side exception has occurred (see the
browser console for more information).
</h2>
{error?.digest && (
<p style={styles.text}>{`Digest: ${error.digest}`}</p>
)}
</div>
</div>
</body>
Expand Down
@@ -0,0 +1,3 @@
export default function Page() {
throw Error('custom server error')
}
28 changes: 23 additions & 5 deletions test/e2e/app-dir/index.test.ts
Expand Up @@ -2123,7 +2123,7 @@ describe('app dir', () => {
it('should use default error boundary for prod and overlay for dev when no error component specified', async () => {
const browser = await webdriver(
next.url,
'/error/global-error-boundary'
'/error/global-error-boundary/client'
)
await browser.elementByCss('#error-trigger-button').click()

Expand All @@ -2132,16 +2132,34 @@ describe('app dir', () => {
expect(await getRedboxHeader(browser)).toMatch(/this is a test/)
} else {
expect(
await browser
.waitForElementByCss('body')
.elementByCss('body')
.text()
await browser.waitForElementByCss('body').elementByCss('h2').text()
).toBe(
'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) {
it('should allow resetting error boundary', async () => {
const browser = await webdriver(next.url, '/error/client-component')
Expand Down