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
b9ca95c6
Unverified
Commit
b9ca95c6
authored
Apr 09, 2026
by
Sebastian "Sebbie" Silbermann
Committed by
GitHub
Apr 09, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't swallow strings thrown in Server Components (#92592)
parent
904905cc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
28 deletions
+60
-28
create-error-handler.tsx
packages/next/src/server/app-render/create-error-handler.tsx
+8
-10
index.test.ts
test/e2e/app-dir/errors/index.test.ts
+52
-18
No files found.
packages/next/src/server/app-render/create-error-handler.tsx
View file @
b9ca95c6
...
@@ -60,11 +60,6 @@ export function createReactServerErrorHandler(
...
@@ -60,11 +60,6 @@ export function createReactServerErrorHandler(
spanToRecordOn
?:
any
spanToRecordOn
?:
any
):
RSCErrorHandler
{
):
RSCErrorHandler
{
return
(
thrownValue
:
unknown
)
=>
{
return
(
thrownValue
:
unknown
)
=>
{
if
(
typeof
thrownValue
===
'string'
)
{
// TODO-APP: look at using webcrypto instead. Requires a promise to be awaited.
return
stringHash
(
thrownValue
).
toString
()
}
// If the response was closed, we don't need to log the error.
// If the response was closed, we don't need to log the error.
if
(
isAbortError
(
thrownValue
))
return
if
(
isAbortError
(
thrownValue
))
return
...
@@ -103,11 +98,14 @@ export function createReactServerErrorHandler(
...
@@ -103,11 +98,14 @@ export function createReactServerErrorHandler(
// but has a digest from other means. Keep the error as-is.
// but has a digest from other means. Keep the error as-is.
}
}
}
else
{
}
else
{
err
.
digest
=
createDigestWithErrorCode
(
// TODO-APP: look at using webcrypto instead of string-hash. Requires a promise to be awaited.
err
,
err
.
digest
=
// TODO-APP: look at using webcrypto instead. Requires a promise to be awaited.
typeof
thrownValue
===
'string'
stringHash
(
err
.
message
+
(
err
.
stack
||
''
)).
toString
()
?
stringHash
(
thrownValue
).
toString
()
)
:
createDigestWithErrorCode
(
err
,
stringHash
(
err
.
message
+
(
err
.
stack
||
''
)).
toString
()
)
}
}
// @TODO by putting this here and not at the top it is possible that
// @TODO by putting this here and not at the top it is possible that
...
...
test/e2e/app-dir/errors/index.test.ts
View file @
b9ca95c6
...
@@ -94,6 +94,7 @@ describe('app-dir - errors', () => {
...
@@ -94,6 +94,7 @@ describe('app-dir - errors', () => {
})
})
it
(
'should trigger error component when undefined is thrown during server components rendering'
,
async
()
=>
{
it
(
'should trigger error component when undefined is thrown during server components rendering'
,
async
()
=>
{
const
outputIndex
=
next
.
cliOutput
.
length
const
browser
=
await
next
.
browser
(
'/server-component/throw-undefined'
)
const
browser
=
await
next
.
browser
(
'/server-component/throw-undefined'
)
expect
(
expect
(
...
@@ -107,16 +108,28 @@ describe('app-dir - errors', () => {
...
@@ -107,16 +108,28 @@ describe('app-dir - errors', () => {
await
browser
.
waitForElementByCss
(
'#error-boundary-digest'
).
text
()
await
browser
.
waitForElementByCss
(
'#error-boundary-digest'
).
text
()
// Digest of the error message should be stable.
// Digest of the error message should be stable.
).
not
.
toBe
(
''
)
).
not
.
toBe
(
''
)
expect
(
stripAnsi
(
next
.
cliOutput
)).
toEqual
(
const
cleanCliOutput
=
stripAnsi
(
expect
.
stringMatching
(
next
.
cliOutput
.
slice
(
outputIndex
)
isNextDev
).
replaceAll
(
/digest: '
\d
+
(
@E
\d
+
)
'/g
,
"digest: '<digest>$1'"
)
?
/Error: An undefined error was thrown.*digest: '
\d
+@E
\d
+'/
s
if
(
isNextDev
)
{
:
/Error: undefined.*digest: '
\d
+@E
\d
+'/
s
expect
(
cleanCliOutput
).
toEqual
(
expect
.
stringMatching
(
/Error: An undefined error was thrown.*digest: '<digest>@E98'/
s
)
)
)
)
}
else
{
expect
(
cleanCliOutput
).
toMatchInlineSnapshot
(
`
"⨯ Error: undefined
at stringify (<anonymous>) {
digest: '<digest>@E394'
}
"
`
)
}
})
})
it
(
'should trigger error component when null is thrown during server components rendering'
,
async
()
=>
{
it
(
'should trigger error component when null is thrown during server components rendering'
,
async
()
=>
{
const
outputIndex
=
next
.
cliOutput
.
length
const
browser
=
await
next
.
browser
(
'/server-component/throw-null'
)
const
browser
=
await
next
.
browser
(
'/server-component/throw-null'
)
expect
(
expect
(
...
@@ -130,16 +143,28 @@ describe('app-dir - errors', () => {
...
@@ -130,16 +143,28 @@ describe('app-dir - errors', () => {
await
browser
.
waitForElementByCss
(
'#error-boundary-digest'
).
text
()
await
browser
.
waitForElementByCss
(
'#error-boundary-digest'
).
text
()
// Digest of the error message should be stable.
// Digest of the error message should be stable.
).
not
.
toBe
(
''
)
).
not
.
toBe
(
''
)
expect
(
stripAnsi
(
next
.
cliOutput
)).
toEqual
(
const
cleanCliOutput
=
stripAnsi
(
expect
.
stringMatching
(
next
.
cliOutput
.
slice
(
outputIndex
)
isNextDev
).
replaceAll
(
/digest: '
\d
+
(
@E
\d
+
)
'/g
,
"digest: '<digest>$1'"
)
?
/Error: A null error was thrown.*digest: '
\d
+@E
\d
+'/
s
if
(
isNextDev
)
{
:
/Error: null.*digest: '
\d
+@E
\d
+'/
s
expect
(
cleanCliOutput
).
toEqual
(
expect
.
stringMatching
(
/Error: A null error was thrown.*digest: '<digest>@E336'/
s
)
)
)
)
}
else
{
expect
(
cleanCliOutput
).
toMatchInlineSnapshot
(
`
"⨯ Error: null
at stringify (<anonymous>) {
digest: '<digest>@E394'
}
"
`
)
}
})
})
it
(
'should trigger error component when a string is thrown during server components rendering'
,
async
()
=>
{
it
(
'should trigger error component when a string is thrown during server components rendering'
,
async
()
=>
{
const
outputIndex
=
next
.
cliOutput
.
length
const
browser
=
await
next
.
browser
(
'/server-component/throw-string'
)
const
browser
=
await
next
.
browser
(
'/server-component/throw-string'
)
expect
(
expect
(
...
@@ -153,13 +178,22 @@ describe('app-dir - errors', () => {
...
@@ -153,13 +178,22 @@ describe('app-dir - errors', () => {
await
browser
.
waitForElementByCss
(
'#error-boundary-digest'
).
text
()
await
browser
.
waitForElementByCss
(
'#error-boundary-digest'
).
text
()
// Digest of the error message should be stable.
// Digest of the error message should be stable.
).
not
.
toBe
(
''
)
).
not
.
toBe
(
''
)
expect
(
stripAnsi
(
next
.
cliOutput
)).
toEqual
(
const
cleanCliOutput
=
stripAnsi
(
expect
.
stringMatching
(
next
.
cliOutput
.
slice
(
outputIndex
)
isNextDev
).
replaceAll
(
/digest: '
\d
+'/g
,
"digest: '<digest>'"
)
?
/Error: this is a test.*digest: '
\d
+'/
s
if
(
isNextDev
)
{
:
/Error: An error occurred in the Server Components render.*digest: '
\d
+'/
s
expect
(
cleanCliOutput
).
toEqual
(
expect
.
stringMatching
(
/Error: this is a test.*digest: '<digest>'/
s
)
)
)
)
}
else
{
expect
(
cleanCliOutput
).
toMatchInlineSnapshot
(
`
"⨯ Error: this is a test
at stringify (<anonymous>) {
digest: '<digest>'
}
"
`
)
}
})
})
it
(
'should use default error boundary for prod and overlay for dev when no error component specified'
,
async
()
=>
{
it
(
'should use default error boundary for prod and overlay for dev when no error component specified'
,
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