Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
7440b66d
Commit
7440b66d
authored
Feb 08, 2026
by
devjiwonchoi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add componentStack and ownerStack test case
parent
c57f14e4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
96 additions
and
2 deletions
+96
-2
error-boundary.tsx
packages/next/src/client/components/error-boundary.tsx
+1
-1
error.js
test/e2e/app-dir/errors/app/client-component/error.js
+9
-1
index.test.ts
test/e2e/app-dir/errors/index.test.ts
+86
-0
No files found.
packages/next/src/client/components/error-boundary.tsx
View file @
7440b66d
...
...
@@ -70,7 +70,7 @@ export class ErrorBoundaryHandler extends React.Component<
componentDidCatch
(
_error
:
Error
,
errorInfo
:
React
.
ErrorInfo
):
void
{
this
.
setState
({
componentStack
:
errorInfo
.
componentStack
??
undefined
,
componentStack
:
errorInfo
.
componentStack
,
})
}
...
...
test/e2e/app-dir/errors/app/client-component/error.js
View file @
7440b66d
...
...
@@ -2,10 +2,18 @@
import
styles
from
'./style.module.css'
export
default
function
ErrorBoundary
({
error
,
reset
,
retry
})
{
export
default
function
ErrorBoundary
({
error
,
reset
,
retry
,
componentStack
,
ownerStack
,
})
{
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
>
...
...
test/e2e/app-dir/errors/index.test.ts
View file @
7440b66d
...
...
@@ -2,6 +2,15 @@ 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
,
...
...
@@ -244,6 +253,83 @@ 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 InnerScrollAndFocusHandler",
"at ScrollAndFocusHandler",
"at RenderFromTemplateContext",
"at SegmentStateProvider",
"at OuterLayoutRouter",
"at InnerLayoutRouter",
"at RedirectErrorBoundary",
"at RedirectBoundary",
"at HTTPAccessFallbackErrorBoundary",
"at HTTPAccessFallbackBoundary",
"at LoadingBoundary",
"at ErrorBoundary",
"at InnerScrollAndFocusHandler",
"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
()
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment