Skip to content

Commit c505a4c

Browse files
authored
exclude AppDevOverlayErrorBoundary from prod build (#76568)
**Test** Generate a prod build, and search `AppDevOverlayErrorBoundary` in the build output. --- Before the change, `main-app` has an occurrence of `AppDevOverlayErrorBoundary`. ![image.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/rKSEEwxbNzdFs9t0yyxN/85112448-fd0f-40f1-a948-79e69a97d4ff.png) After the change, there should be 0 occurrences: ![image.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/rKSEEwxbNzdFs9t0yyxN/492605a8-3a23-459d-80a6-4f818ac8ef4d.png)
1 parent 91684ee commit c505a4c

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

packages/next/src/client/react-client-callbacks/error-boundary-callbacks.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { isNextRouterError } from '../components/is-next-router-error'
77
import { isBailoutToCSRError } from '../../shared/lib/lazy-dynamic/bailout-to-csr'
88
import { reportGlobalError } from './report-global-error'
99
import { originConsoleError } from '../components/globals/intercept-console-error'
10-
import { AppDevOverlayErrorBoundary } from '../components/react-dev-overlay/app/app-dev-overlay-error-boundary'
1110
import {
1211
ErrorBoundaryHandler,
1312
GlobalError as DefaultErrorBoundary,
@@ -19,12 +18,22 @@ export function onCaughtError(
1918
) {
2019
const errorBoundaryComponent = errorInfo.errorBoundary?.constructor
2120

22-
const isImplicitErrorBoundary =
23-
(process.env.NODE_ENV !== 'production' &&
24-
errorBoundaryComponent === AppDevOverlayErrorBoundary) ||
21+
let isImplicitErrorBoundary
22+
23+
if (process.env.NODE_ENV !== 'production') {
24+
const { AppDevOverlayErrorBoundary } =
25+
require('../components/react-dev-overlay/app/app-dev-overlay-error-boundary') as typeof import('../components/react-dev-overlay/app/app-dev-overlay-error-boundary')
26+
27+
isImplicitErrorBoundary =
28+
errorBoundaryComponent === AppDevOverlayErrorBoundary
29+
}
30+
31+
isImplicitErrorBoundary =
32+
isImplicitErrorBoundary ||
2533
(errorBoundaryComponent === ErrorBoundaryHandler &&
2634
(errorInfo.errorBoundary! as InstanceType<typeof ErrorBoundaryHandler>)
2735
.props.errorComponent === DefaultErrorBoundary)
36+
2837
if (isImplicitErrorBoundary) {
2938
// We don't consider errors caught unless they're caught by an explicit error
3039
// boundary. The built-in ones are considered implicit.

0 commit comments

Comments
 (0)