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
Expand Up @@ -5,7 +5,9 @@ import { useState } from 'react'
export default function Page() {
const [clicked, setClicked] = useState(false)
if (clicked) {
throw new Error('this is a test')
const e = new Error('this is a test')
e.digest = 'CUSTOM_DIGEST'
huozhi marked this conversation as resolved.
Show resolved Hide resolved
throw e
}
return (
<button
Expand Down
8 changes: 4 additions & 4 deletions test/e2e/app-dir/index.test.ts
Expand Up @@ -2111,13 +2111,13 @@ 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).'
)
expect(
await browser.waitForElementByCss('body').elementByCss('p').text()
).toBe('Digest: CUSTOM_DIGEST')
}
})

Expand Down