Commit 5cd92063 authored by devjiwonchoi's avatar devjiwonchoi

Revert componentStack and ownerStack from error.js

The ownerStack captured in the error boundary returns the error
boundary's owner stack instead of the errored component's.
Remove componentStack and ownerStack from error.js props to
address them separately with a correct capture strategy.
parent 02aca5c9
......@@ -8,9 +8,6 @@ export type GlobalErrorComponent = React.ComponentType<{
error: any
reset: () => void
unstable_retry: () => void
componentStack: React.ErrorInfo['componentStack']
/** Only available in dev builds; `null` otherwise. */
ownerStack: ReturnType<typeof React.captureOwnerStack>
}>
function DefaultGlobalError({ error }: { error: any }) {
......
......@@ -18,9 +18,6 @@ export type ErrorComponent = React.ComponentType<{
error: Error
reset: () => void
unstable_retry: () => void
componentStack: React.ErrorInfo['componentStack']
/** Only available in dev builds; `null` otherwise. */
ownerStack: ReturnType<typeof React.captureOwnerStack>
}>
export interface ErrorBoundaryProps {
......@@ -38,8 +35,6 @@ interface ErrorBoundaryHandlerProps extends ErrorBoundaryProps {
interface ErrorBoundaryHandlerState {
error: Error | null
previousPathname: string | null
componentStack: React.ErrorInfo['componentStack']
ownerStack: ReturnType<typeof React.captureOwnerStack>
}
export class ErrorBoundaryHandler extends React.Component<
......@@ -54,8 +49,6 @@ export class ErrorBoundaryHandler extends React.Component<
this.state = {
error: null,
previousPathname: this.props.pathname,
componentStack: undefined,
ownerStack: null,
}
}
......@@ -66,18 +59,7 @@ export class ErrorBoundaryHandler extends React.Component<
throw error
}
let ownerStack: string | null = null
if ('captureOwnerStack' in React) {
ownerStack = React.captureOwnerStack()
}
return { error, ownerStack }
}
componentDidCatch(_error: Error, errorInfo: React.ErrorInfo): void {
this.setState({
componentStack: errorInfo.componentStack,
})
return { error }
}
static getDerivedStateFromProps(
......@@ -96,8 +78,6 @@ export class ErrorBoundaryHandler extends React.Component<
return {
error: null,
previousPathname: props.pathname,
componentStack: undefined,
ownerStack: null,
}
}
}
......@@ -112,24 +92,16 @@ export class ErrorBoundaryHandler extends React.Component<
return {
error: null,
previousPathname: props.pathname,
componentStack: undefined,
ownerStack: null,
}
}
return {
error: state.error,
previousPathname: props.pathname,
componentStack: state.componentStack,
ownerStack: state.ownerStack,
}
}
reset = () => {
this.setState({
error: null,
componentStack: undefined,
ownerStack: null,
})
this.setState({ error: null })
}
unstable_retry = () => {
......@@ -153,8 +125,6 @@ export class ErrorBoundaryHandler extends React.Component<
error={this.state.error}
reset={this.reset}
unstable_retry={this.unstable_retry}
componentStack={this.state.componentStack}
ownerStack={this.state.ownerStack}
/>
</>
)
......
......@@ -17,9 +17,6 @@ type AppDevOverlayErrorBoundaryProps = {
type AppDevOverlayErrorBoundaryState = {
reactError: unknown
componentStack: React.ErrorInfo['componentStack']
/** Only available in dev builds; `null` otherwise. */
ownerStack: ReturnType<typeof React.captureOwnerStack>
}
function ErroredHtml({
......@@ -27,15 +24,11 @@ function ErroredHtml({
error,
reset,
unstable_retry,
componentStack,
ownerStack,
}: {
globalError: GlobalErrorState
error: unknown
reset: () => void
unstable_retry: () => void
componentStack: React.ErrorInfo['componentStack']
ownerStack: ReturnType<typeof React.captureOwnerStack>
}) {
if (!error) {
return (
......@@ -52,8 +45,6 @@ function ErroredHtml({
error={error}
reset={reset}
unstable_retry={unstable_retry}
componentStack={componentStack}
ownerStack={ownerStack}
/>
</ErrorBoundary>
)
......@@ -68,34 +59,23 @@ export class AppDevOverlayErrorBoundary extends PureComponent<
state: AppDevOverlayErrorBoundaryState = {
reactError: null,
componentStack: undefined,
ownerStack: null,
}
static getDerivedStateFromError(error: Error) {
RuntimeErrorHandler.hadRuntimeError = true
let ownerStack: string | null = null
if ('captureOwnerStack' in React) {
ownerStack = React.captureOwnerStack()
}
return {
reactError: error,
ownerStack,
}
}
componentDidCatch(err: Error, errorInfo: React.ErrorInfo) {
componentDidCatch(err: Error) {
if (
process.env.NODE_ENV === 'development' &&
err.message === SEGMENT_EXPLORER_SIMULATED_ERROR_MESSAGE
) {
return
}
this.setState({
componentStack: errorInfo.componentStack,
})
dispatcher.openErrorOverlay()
}
......@@ -107,16 +87,12 @@ export class AppDevOverlayErrorBoundary extends PureComponent<
}
reset = () => {
this.setState({
reactError: null,
componentStack: undefined,
ownerStack: null,
})
this.setState({ reactError: null })
}
render() {
const { children, globalError } = this.props
const { reactError, componentStack, ownerStack } = this.state
const { reactError } = this.state
const fallback = (
<ErroredHtml
......@@ -124,8 +100,6 @@ export class AppDevOverlayErrorBoundary extends PureComponent<
error={reactError}
reset={this.reset}
unstable_retry={this.unstable_retry}
componentStack={componentStack}
ownerStack={ownerStack}
/>
)
......
......@@ -2,18 +2,10 @@
import styles from './style.module.css'
export default function ErrorBoundary({
error,
reset,
unstable_retry,
componentStack,
ownerStack,
}) {
export default function ErrorBoundary({ error, reset, unstable_retry }) {
return (
<>
<p id="error-boundary-message">An error occurred: {error.message}</p>
<p id="error-component-stack">{componentStack}</p>
<p id="error-owner-stack">{ownerStack}</p>
<button id="reset" onClick={() => reset()} className={styles.button}>
Try again
</button>
......
'use client'
export default function ErrorBoundary({
error,
reset,
unstable_retry,
componentStack,
ownerStack,
}) {
export default function ErrorBoundary({ error, reset, unstable_retry }) {
return (
<>
<p id="error-boundary-message">{error.message}</p>
<p id="error-boundary-digest">{error.digest}</p>
<p id="error-component-stack">{componentStack}</p>
<p id="error-owner-stack">{ownerStack}</p>
<button id="reset" onClick={() => reset()}>
Try again
</button>
......
......@@ -2,15 +2,6 @@ import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils'
import stripAnsi from 'strip-ansi'
/**
* Normalize a React component stack string into an array of component names.
* Strips URLs, line numbers, and other dynamic parts.
*/
function normalizeComponentStack(stack: string): string[] {
// Match "at ComponentName" patterns, optionally with [Server] tag
return stack.match(/at \w+(?:\s+\[Server\])?/g) || []
}
describe('app-dir - errors', () => {
const { next, isNextDev, isNextStart, skipped } = nextTestSetup({
files: __dirname,
......@@ -254,83 +245,6 @@ describe('app-dir - errors', () => {
])
})
it('should pass componentStack and ownerStack to error component', async () => {
const browser = await next.browser('/client-component')
await browser
.elementByCss('#error-trigger-button')
.click()
.waitForElementByCss('#error-component-stack')
if (isNextDev) {
expect(
normalizeComponentStack(
await browser.elementByCss('#error-component-stack').text()
)
).toMatchInlineSnapshot(`
[
"at Page",
"at ClientPageRoot",
"at SegmentViewNode",
"at InnerLayoutRouter",
"at RedirectErrorBoundary",
"at RedirectBoundary",
"at HTTPAccessFallbackBoundary",
"at LoadingBoundary",
"at ErrorBoundaryHandler",
"at ErrorBoundary",
"at InnerScrollAndFocusHandlerOld",
"at ScrollAndFocusHandler",
"at RenderFromTemplateContext",
"at SegmentStateProvider",
"at OuterLayoutRouter",
"at InnerLayoutRouter",
"at RedirectErrorBoundary",
"at RedirectBoundary",
"at HTTPAccessFallbackErrorBoundary",
"at HTTPAccessFallbackBoundary",
"at LoadingBoundary",
"at ErrorBoundary",
"at InnerScrollAndFocusHandlerOld",
"at ScrollAndFocusHandler",
"at RenderFromTemplateContext",
"at SegmentStateProvider",
"at OuterLayoutRouter",
"at body",
"at html",
"at RootLayout [Server]",
"at SegmentViewNode",
"at __next_root_layout_boundary__",
"at RedirectErrorBoundary",
"at RedirectBoundary",
"at HTTPAccessFallbackErrorBoundary",
"at HTTPAccessFallbackBoundary",
"at DevRootHTTPAccessFallbackBoundary",
"at AppDevOverlayErrorBoundary",
"at HotReload",
"at Router",
"at ErrorBoundaryHandler",
"at ErrorBoundary",
"at RootErrorBoundary",
"at AppRouter",
"at ServerRoot",
"at Root",
]
`)
expect(
normalizeComponentStack(
await browser.elementByCss('#error-owner-stack').text()
)
).toMatchInlineSnapshot(`
[
"at ErrorBoundary",
"at OuterLayoutRouter",
]
`)
}
})
// production tests
if (isNextStart) {
it('should allow resetting error boundary', async () => {
......@@ -425,88 +339,6 @@ describe('app-dir - errors', () => {
: 'An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.'
)
if (isNextDev) {
expect(
normalizeComponentStack(
await browser.elementByCss('#error-component-stack').text()
)
).toMatchInlineSnapshot(`
[
"at Content",
"at div",
"at Container [Server]",
"at Suspense",
"at Page",
"at SegmentViewNode",
"at InnerLayoutRouter",
"at RedirectErrorBoundary",
"at RedirectBoundary",
"at HTTPAccessFallbackBoundary",
"at LoadingBoundary",
"at ErrorBoundary",
"at InnerScrollAndFocusHandlerOld",
"at ScrollAndFocusHandler",
"at RenderFromTemplateContext",
"at SegmentStateProvider",
"at OuterLayoutRouter",
"at InnerLayoutRouter",
"at RedirectErrorBoundary",
"at RedirectBoundary",
"at HTTPAccessFallbackBoundary",
"at LoadingBoundary",
"at ErrorBoundaryHandler",
"at ErrorBoundary",
"at InnerScrollAndFocusHandlerOld",
"at ScrollAndFocusHandler",
"at RenderFromTemplateContext",
"at SegmentStateProvider",
"at OuterLayoutRouter",
"at InnerLayoutRouter",
"at RedirectErrorBoundary",
"at RedirectBoundary",
"at HTTPAccessFallbackErrorBoundary",
"at HTTPAccessFallbackBoundary",
"at LoadingBoundary",
"at ErrorBoundary",
"at InnerScrollAndFocusHandlerOld",
"at ScrollAndFocusHandler",
"at RenderFromTemplateContext",
"at SegmentStateProvider",
"at OuterLayoutRouter",
"at body",
"at html",
"at RootLayout [Server]",
"at SegmentViewNode",
"at __next_root_layout_boundary__",
"at RedirectErrorBoundary",
"at RedirectBoundary",
"at HTTPAccessFallbackErrorBoundary",
"at HTTPAccessFallbackBoundary",
"at DevRootHTTPAccessFallbackBoundary",
"at AppDevOverlayErrorBoundary",
"at HotReload",
"at Router",
"at ErrorBoundaryHandler",
"at ErrorBoundary",
"at RootErrorBoundary",
"at AppRouter",
"at ServerRoot",
"at Root",
]
`)
expect(
normalizeComponentStack(
await browser.elementByCss('#error-owner-stack').text()
)
).toMatchInlineSnapshot(`
[
"at ErrorBoundary",
"at OuterLayoutRouter",
]
`)
}
// Signal the server to stop throwing before retrying
await next.fetch('/server-component/recover/set-recover')
......
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