Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/smooth-bears-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'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.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import DefaultGlobalError, {
type AppDevOverlayErrorBoundaryProps = {
children: React.ReactNode
globalError: [GlobalErrorComponent, React.ReactNode]
onError: (value: boolean) => void
onError: () => void
}

type AppDevOverlayErrorBoundaryState = {
isReactError: boolean
reactError: unknown
}

Expand Down Expand Up @@ -43,33 +42,28 @@ export class AppDevOverlayErrorBoundary extends PureComponent<
AppDevOverlayErrorBoundaryProps,
AppDevOverlayErrorBoundaryState
> {
state = { isReactError: false, reactError: null }
state = { reactError: null }

static getDerivedStateFromError(error: Error) {
if (!error.stack) {
return { isReactError: false, reactError: null }
}

RuntimeErrorHandler.hadRuntimeError = true

return {
isReactError: true,
reactError: error,
}
}

componentDidCatch() {
this.props.onError(this.state.isReactError)
this.props.onError()
}

render() {
const { children, globalError } = this.props
const { isReactError, reactError } = this.state
const { reactError } = this.state

const fallback = (
<ErroredHtml globalError={globalError} error={reactError} />
)

return isReactError ? fallback : children
return reactError !== null ? fallback : children
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export function AppDevOverlay({
<>
<AppDevOverlayErrorBoundary
globalError={globalError}
onError={setIsErrorOverlayOpen}
onError={openOverlay}
>
<ReplaySsrOnlyErrors onBlockingError={openOverlay} />
{children}
Expand Down
6 changes: 3 additions & 3 deletions test/development/acceptance-app/hydration-error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ describe('Error overlay for hydration errors in App router', () => {
"componentStack": "...
<HotReload assetPrefix="" globalError={[...]}>
<AppDevOverlay state={{nextId:1, ...}} globalError={[...]}>
<AppDevOverlayErrorBoundary globalError={[...]} onError={function bound dispatchSetState}>
<AppDevOverlayErrorBoundary globalError={[...]} onError={function}>
<ReplaySsrOnlyErrors>
<DevRootHTTPAccessFallbackBoundary>
<HTTPAccessFallbackBoundary notFound={<NotAllowedRootHTTPFallbackError>}>
Expand Down Expand Up @@ -246,7 +246,7 @@ describe('Error overlay for hydration errors in App router', () => {
"componentStack": "...
<HotReload assetPrefix="" globalError={[...]}>
<AppDevOverlay state={{nextId:1, ...}} globalError={[...]}>
<AppDevOverlayErrorBoundary globalError={[...]} onError={function bound dispatchSetState}>
<AppDevOverlayErrorBoundary globalError={[...]} onError={function}>
<ReplaySsrOnlyErrors>
<DevRootHTTPAccessFallbackBoundary>
<HTTPAccessFallbackBoundary notFound={<NotAllowedRootHTTPFallbackError>}>
Expand Down Expand Up @@ -1046,7 +1046,7 @@ describe('Error overlay for hydration errors in App router', () => {
"componentStack": "...
<HotReload assetPrefix="" globalError={[...]}>
<AppDevOverlay state={{nextId:1, ...}} globalError={[...]}>
<AppDevOverlayErrorBoundary globalError={[...]} onError={function bound dispatchSetState}>
<AppDevOverlayErrorBoundary globalError={[...]} onError={function}>
<ReplaySsrOnlyErrors>
<DevRootHTTPAccessFallbackBoundary>
<HTTPAccessFallbackBoundary notFound={<NotAllowedRootHTTPFallbackError>}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { nextTestSetup } from 'e2e-utils'
import { assertNoRedbox } from 'next-test-utils'

describe('serialize-circular-error', () => {
const { next } = nextTestSetup({
Expand Down Expand Up @@ -27,9 +26,16 @@ describe('serialize-circular-error', () => {
it('should serialize the object from client component in console correctly', async () => {
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: handle the error object in the client-side
await assertNoRedbox(browser)
// TODO: Format arbitrary messages in Redbox
await expect(browser).toDisplayRedbox(`
{
"description": "[object Object]",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
}
`)

const bodyText = await browser.elementByCss('body').text()
expect(bodyText).toContain(
Expand Down