Unverified Commit ff8d4c45 authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

Explicit header for SSR error (#12880)

parent 5da1dcf6
...@@ -14,6 +14,7 @@ import { ...@@ -14,6 +14,7 @@ import {
import { LeftRightDialogHeader } from '../components/LeftRightDialogHeader' import { LeftRightDialogHeader } from '../components/LeftRightDialogHeader'
import { Overlay } from '../components/Overlay' import { Overlay } from '../components/Overlay'
import { Toast } from '../components/Toast' import { Toast } from '../components/Toast'
import { isNodeError } from '../helpers/nodeStackFrames'
import { noop as css } from '../helpers/noop-template' import { noop as css } from '../helpers/noop-template'
import { import {
getOriginalStackFrames, getOriginalStackFrames,
...@@ -210,6 +211,7 @@ export const Errors: React.FC<ErrorsProps> = function Errors({ errors }) { ...@@ -210,6 +211,7 @@ export const Errors: React.FC<ErrorsProps> = function Errors({ errors }) {
) )
} }
const isServerError = isNodeError(activeError.error)
return ( return (
<Overlay> <Overlay>
<Dialog <Dialog
...@@ -231,10 +233,22 @@ export const Errors: React.FC<ErrorsProps> = function Errors({ errors }) { ...@@ -231,10 +233,22 @@ export const Errors: React.FC<ErrorsProps> = function Errors({ errors }) {
{readyErrors.length < 2 ? '' : 's'} {readyErrors.length < 2 ? '' : 's'}
</small> </small>
</LeftRightDialogHeader> </LeftRightDialogHeader>
<h1 id="nextjs__container_errors_label">Unhandled Runtime Error</h1> <h1 id="nextjs__container_errors_label">
{isServerError ? 'Server Error' : 'Unhandled Runtime Error'}
</h1>
<p id="nextjs__container_errors_desc"> <p id="nextjs__container_errors_desc">
{activeError.error.name}: {activeError.error.message} {activeError.error.name}: {activeError.error.message}
</p> </p>
{isServerError ? (
<div>
<small>
This error happened while generating the page. Any console
logs will be displayed in the terminal window.
</small>
</div>
) : (
undefined
)}
</DialogHeader> </DialogHeader>
<DialogBody className="nextjs-container-errors-body"> <DialogBody className="nextjs-container-errors-body">
<RuntimeError key={activeError.id.toString()} error={activeError} /> <RuntimeError key={activeError.id.toString()} error={activeError} />
...@@ -271,6 +285,10 @@ export const styles = css` ...@@ -271,6 +285,10 @@ export const styles = css`
color: var(--color-ansi-red); color: var(--color-ansi-red);
white-space: pre-wrap; white-space: pre-wrap;
} }
.nextjs-container-errors-header > div > small {
margin: 0;
margin-top: var(--size-gap-half);
}
.nextjs-container-errors-body > h5:not(:first-child) { .nextjs-container-errors-body > h5:not(:first-child) {
margin-top: calc(var(--size-gap-double) + var(--size-gap)); margin-top: calc(var(--size-gap-double) + var(--size-gap));
......
...@@ -19,6 +19,12 @@ export function getFilesystemFrame(frame: StackFrame): StackFrame { ...@@ -19,6 +19,12 @@ export function getFilesystemFrame(frame: StackFrame): StackFrame {
return f return f
} }
const symbolNodeError = Symbol('NextjsNodeError')
export function isNodeError(error: Error): boolean {
return symbolNodeError in error
}
export function getNodeError(error: Error): Error { export function getNodeError(error: Error): Error {
let n: Error let n: Error
try { try {
...@@ -50,5 +56,10 @@ export function getNodeError(error: Error): Error { ...@@ -50,5 +56,10 @@ export function getNodeError(error: Error): Error {
n.stack = error.stack n.stack = error.stack
} }
Object.defineProperty(n, symbolNodeError, {
writable: false,
enumerable: false,
configurable: false,
})
return n return n
} }
...@@ -201,10 +201,15 @@ export default (context, renderViaHTTP) => { ...@@ -201,10 +201,15 @@ export default (context, renderViaHTTP) => {
'export default {};\nexport const fn =' 'export default {};\nexport const fn ='
) )
await check( expect(await hasRedbox(browser)).toBe(true)
() => getRedboxHeader(browser), expect(await getRedboxHeader(browser)).toMatchInlineSnapshot(`
/The default export is not a React Component/ " 1 of 1 unhandled error
) Server Error
Error: The default export is not a React Component in page: \\"/hmr/about5\\"
This error happened while generating the page. Any console logs will be displayed in the terminal window."
`)
aboutPage.restore() aboutPage.restore()
...@@ -241,10 +246,22 @@ export default (context, renderViaHTTP) => { ...@@ -241,10 +246,22 @@ export default (context, renderViaHTTP) => {
'export default () => /search/;\nexport const fn =' 'export default () => /search/;\nexport const fn ='
) )
await check( expect(await hasRedbox(browser)).toBe(true)
() => getRedboxHeader(browser), expect(await getRedboxHeader(browser)).toMatchInlineSnapshot(`
/Objects are not valid as a React child/ " 1 of 1 unhandled error
) Server Error
Error: Objects are not valid as a React child (found: /search/). If you meant to render a collection of children, use an array instead.
in Unknown
in App
in Unknown
in Context.Provider
in Context.Provider
in Context.Provider
in AppContainer
This error happened while generating the page. Any console logs will be displayed in the terminal window."
`)
aboutPage.restore() aboutPage.restore()
...@@ -281,14 +298,20 @@ export default (context, renderViaHTTP) => { ...@@ -281,14 +298,20 @@ export default (context, renderViaHTTP) => {
'export default undefined;\nexport const fn =' 'export default undefined;\nexport const fn ='
) )
await check(async () => { expect(await hasRedbox(browser)).toBe(true)
const txt = await getRedboxHeader(browser) expect(await getRedboxHeader(browser)).toMatchInlineSnapshot(`
return txt " 1 of 1 unhandled error
}, /The default export is not a React Component/) Server Error
Error: The default export is not a React Component in page: \\"/hmr/about7\\"
This error happened while generating the page. Any console logs will be displayed in the terminal window."
`)
aboutPage.restore() aboutPage.restore()
await check(() => getBrowserBodyText(browser), /This is the about page/) await check(() => getBrowserBodyText(browser), /This is the about page/)
expect(await hasRedbox(browser, false)).toBe(false)
} catch (err) { } catch (err) {
aboutPage.restore() aboutPage.restore()
...@@ -317,9 +340,12 @@ export default (context, renderViaHTTP) => { ...@@ -317,9 +340,12 @@ export default (context, renderViaHTTP) => {
await browser.elementByCss('#error-in-gip-link').click() await browser.elementByCss('#error-in-gip-link').click()
expect(await hasRedbox(browser)).toBe(true) expect(await hasRedbox(browser)).toBe(true)
expect(await getRedboxSource(browser)).toMatch( expect(await getRedboxHeader(browser)).toMatchInlineSnapshot(`
/an-expected-error-in-gip/ " 1 of 1 unhandled error
) Unhandled Runtime Error
Error: an-expected-error-in-gip"
`)
erroredPage.replace('throw error', 'return {}') erroredPage.replace('throw error', 'return {}')
...@@ -356,9 +382,14 @@ export default (context, renderViaHTTP) => { ...@@ -356,9 +382,14 @@ export default (context, renderViaHTTP) => {
browser = await webdriver(context.appPort, '/hmr/error-in-gip') browser = await webdriver(context.appPort, '/hmr/error-in-gip')
expect(await hasRedbox(browser)).toBe(true) expect(await hasRedbox(browser)).toBe(true)
expect(await getRedboxSource(browser)).toMatch( expect(await getRedboxHeader(browser)).toMatchInlineSnapshot(`
/an-expected-error-in-gip/ " 1 of 1 unhandled error
) Server Error
Error: an-expected-error-in-gip
This error happened while generating the page. Any console logs will be displayed in the terminal window."
`)
const erroredPage = new File( const erroredPage = new File(
join(__dirname, '../', 'pages', 'hmr', 'error-in-gip.js') join(__dirname, '../', 'pages', 'hmr', 'error-in-gip.js')
......
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