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

[dev-overlay] Show error overlay on any thrown value in /app (#79658)

May have been a leftover from earlier. 

We always consider any throw. Even without a sync stack, we might still have an async stack to show. And even if we have no stack at all, the message is still relevant. Basically, never hide errors.
parent d55e2f84
---
'next': patch
---
[dev-overlay] Show error overlay on any thrown value
We used to only show the error overlay on thrown values with a stack property.
On other thrown values we kept the overlay collapsed.
...@@ -8,11 +8,10 @@ import DefaultGlobalError, { ...@@ -8,11 +8,10 @@ import DefaultGlobalError, {
type AppDevOverlayErrorBoundaryProps = { type AppDevOverlayErrorBoundaryProps = {
children: React.ReactNode children: React.ReactNode
globalError: [GlobalErrorComponent, React.ReactNode] globalError: [GlobalErrorComponent, React.ReactNode]
onError: (value: boolean) => void onError: () => void
} }
type AppDevOverlayErrorBoundaryState = { type AppDevOverlayErrorBoundaryState = {
isReactError: boolean
reactError: unknown reactError: unknown
} }
...@@ -43,33 +42,28 @@ export class AppDevOverlayErrorBoundary extends PureComponent< ...@@ -43,33 +42,28 @@ export class AppDevOverlayErrorBoundary extends PureComponent<
AppDevOverlayErrorBoundaryProps, AppDevOverlayErrorBoundaryProps,
AppDevOverlayErrorBoundaryState AppDevOverlayErrorBoundaryState
> { > {
state = { isReactError: false, reactError: null } state = { reactError: null }
static getDerivedStateFromError(error: Error) { static getDerivedStateFromError(error: Error) {
if (!error.stack) {
return { isReactError: false, reactError: null }
}
RuntimeErrorHandler.hadRuntimeError = true RuntimeErrorHandler.hadRuntimeError = true
return { return {
isReactError: true,
reactError: error, reactError: error,
} }
} }
componentDidCatch() { componentDidCatch() {
this.props.onError(this.state.isReactError) this.props.onError()
} }
render() { render() {
const { children, globalError } = this.props const { children, globalError } = this.props
const { isReactError, reactError } = this.state const { reactError } = this.state
const fallback = ( const fallback = (
<ErroredHtml globalError={globalError} error={reactError} /> <ErroredHtml globalError={globalError} error={reactError} />
) )
return isReactError ? fallback : children return reactError !== null ? fallback : children
} }
} }
...@@ -86,7 +86,7 @@ export function AppDevOverlay({ ...@@ -86,7 +86,7 @@ export function AppDevOverlay({
<> <>
<AppDevOverlayErrorBoundary <AppDevOverlayErrorBoundary
globalError={globalError} globalError={globalError}
onError={setIsErrorOverlayOpen} onError={openOverlay}
> >
<ReplaySsrOnlyErrors onBlockingError={openOverlay} /> <ReplaySsrOnlyErrors onBlockingError={openOverlay} />
{children} {children}
......
...@@ -210,7 +210,7 @@ describe('Error overlay for hydration errors in App router', () => { ...@@ -210,7 +210,7 @@ describe('Error overlay for hydration errors in App router', () => {
"componentStack": "... "componentStack": "...
<HotReload assetPrefix="" globalError={[...]}> <HotReload assetPrefix="" globalError={[...]}>
<AppDevOverlay state={{nextId:1, ...}} globalError={[...]}> <AppDevOverlay state={{nextId:1, ...}} globalError={[...]}>
<AppDevOverlayErrorBoundary globalError={[...]} onError={function bound dispatchSetState}> <AppDevOverlayErrorBoundary globalError={[...]} onError={function}>
<ReplaySsrOnlyErrors> <ReplaySsrOnlyErrors>
<DevRootHTTPAccessFallbackBoundary> <DevRootHTTPAccessFallbackBoundary>
<HTTPAccessFallbackBoundary notFound={<NotAllowedRootHTTPFallbackError>}> <HTTPAccessFallbackBoundary notFound={<NotAllowedRootHTTPFallbackError>}>
...@@ -246,7 +246,7 @@ describe('Error overlay for hydration errors in App router', () => { ...@@ -246,7 +246,7 @@ describe('Error overlay for hydration errors in App router', () => {
"componentStack": "... "componentStack": "...
<HotReload assetPrefix="" globalError={[...]}> <HotReload assetPrefix="" globalError={[...]}>
<AppDevOverlay state={{nextId:1, ...}} globalError={[...]}> <AppDevOverlay state={{nextId:1, ...}} globalError={[...]}>
<AppDevOverlayErrorBoundary globalError={[...]} onError={function bound dispatchSetState}> <AppDevOverlayErrorBoundary globalError={[...]} onError={function}>
<ReplaySsrOnlyErrors> <ReplaySsrOnlyErrors>
<DevRootHTTPAccessFallbackBoundary> <DevRootHTTPAccessFallbackBoundary>
<HTTPAccessFallbackBoundary notFound={<NotAllowedRootHTTPFallbackError>}> <HTTPAccessFallbackBoundary notFound={<NotAllowedRootHTTPFallbackError>}>
...@@ -1046,7 +1046,7 @@ describe('Error overlay for hydration errors in App router', () => { ...@@ -1046,7 +1046,7 @@ describe('Error overlay for hydration errors in App router', () => {
"componentStack": "... "componentStack": "...
<HotReload assetPrefix="" globalError={[...]}> <HotReload assetPrefix="" globalError={[...]}>
<AppDevOverlay state={{nextId:1, ...}} globalError={[...]}> <AppDevOverlay state={{nextId:1, ...}} globalError={[...]}>
<AppDevOverlayErrorBoundary globalError={[...]} onError={function bound dispatchSetState}> <AppDevOverlayErrorBoundary globalError={[...]} onError={function}>
<ReplaySsrOnlyErrors> <ReplaySsrOnlyErrors>
<DevRootHTTPAccessFallbackBoundary> <DevRootHTTPAccessFallbackBoundary>
<HTTPAccessFallbackBoundary notFound={<NotAllowedRootHTTPFallbackError>}> <HTTPAccessFallbackBoundary notFound={<NotAllowedRootHTTPFallbackError>}>
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { assertNoRedbox } from 'next-test-utils'
describe('serialize-circular-error', () => { describe('serialize-circular-error', () => {
const { next } = nextTestSetup({ const { next } = nextTestSetup({
...@@ -27,9 +26,16 @@ describe('serialize-circular-error', () => { ...@@ -27,9 +26,16 @@ describe('serialize-circular-error', () => {
it('should serialize the object from client component in console correctly', async () => { it('should serialize the object from client component in console correctly', async () => {
const browser = await next.browser('/client') const browser = await next.browser('/client')
// It's not a valid error object, it will display the global-error instead of the error overlay // TODO: Format arbitrary messages in Redbox
// TODO: handle the error object in the client-side await expect(browser).toDisplayRedbox(`
await assertNoRedbox(browser) {
"description": "[object Object]",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
}
`)
const bodyText = await browser.elementByCss('body').text() const bodyText = await browser.elementByCss('body').text()
expect(bodyText).toContain( expect(bodyText).toContain(
......
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