Commit 02aca5c9 authored by devjiwonchoi's avatar devjiwonchoi

Add indirection components and stack assertions for server component errors

Add Container wrapper around the throwing server component so
componentStack and ownerStack reflect a realistic hierarchy. Render
componentStack/ownerStack in the server-component error boundary and
add inline snapshot assertions.

https://github.com/vercel/next.js/pull/89685#discussion_r2854290131
parent f686dd27
'use client' 'use client'
export default function ErrorBoundary({ error, reset, unstable_retry }) { export default function ErrorBoundary({
error,
reset,
unstable_retry,
componentStack,
ownerStack,
}) {
return ( return (
<> <>
<p id="error-boundary-message">{error.message}</p> <p id="error-boundary-message">{error.message}</p>
<p id="error-boundary-digest">{error.digest}</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()}> <button id="reset" onClick={() => reset()}>
Try again Try again
</button> </button>
......
...@@ -4,12 +4,18 @@ import { connection } from 'next/server' ...@@ -4,12 +4,18 @@ import { connection } from 'next/server'
export default function Page() { export default function Page() {
return ( return (
<Suspense> <Suspense>
<PageImpl /> <Container>
<Content />
</Container>
</Suspense> </Suspense>
) )
} }
async function PageImpl() { function Container({ children }) {
return <div>{children}</div>
}
async function Content() {
await connection() await connection()
if (!globalThis.__nextTestRecover) { if (!globalThis.__nextTestRecover) {
......
...@@ -193,6 +193,7 @@ describe('app-dir - errors', () => { ...@@ -193,6 +193,7 @@ describe('app-dir - errors', () => {
| ^", | ^",
"stack": [ "stack": [
"Page app/global-error-boundary/client/page.js (8:11)", "Page app/global-error-boundary/client/page.js (8:11)",
"ClientPageRoot ../../../packages/next/src/client/components/client-page.tsx (83:12)",
], ],
} }
`) `)
...@@ -424,6 +425,88 @@ describe('app-dir - errors', () => { ...@@ -424,6 +425,88 @@ 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.' : '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 // Signal the server to stop throwing before retrying
await next.fetch('/server-component/recover/set-recover') 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