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
24da437c
Unverified
Commit
24da437c
authored
Oct 21, 2024
by
Jiachi Liu
Committed by
GitHub
Oct 21, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: dedupe consecutive captured console errors (#71483)
parent
e4d6cc8c
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
80 additions
and
14 deletions
+80
-14
enqueue-client-error.ts
...eact-dev-overlay/internal/helpers/enqueue-client-error.ts
+22
-0
use-error-handler.ts
...s/react-dev-overlay/internal/helpers/use-error-handler.ts
+2
-9
page.js
...t/app-dir/capture-console-error/app/browser/event/page.js
+0
-0
page.js
.../app-dir/capture-console-error/app/browser/render/page.js
+6
-0
capture-console-error.test.ts
...p-dir/capture-console-error/capture-console-error.test.ts
+50
-5
No files found.
packages/next/src/client/components/react-dev-overlay/internal/helpers/enqueue-client-error.ts
0 → 100644
View file @
24da437c
import
{
isHydrationError
}
from
'../../../is-hydration-error'
// Dedupe the two consecutive errors: If the previous one is same as current one, ignore the current one.
export
function
enqueueConsecutiveDedupedError
(
queue
:
Array
<
Error
>
,
error
:
Error
)
{
const
isFront
=
isHydrationError
(
error
)
const
previousError
=
isFront
?
queue
[
0
]
:
queue
[
queue
.
length
-
1
]
// Only check message to see if it's the same error, as message is representative display in the console.
if
(
previousError
&&
previousError
.
message
===
error
.
message
)
{
return
}
// TODO: change all to push error into errorQueue,
// currently there's a async api error is always erroring while hydration error showing up.
// Move hydration error to the front of the queue to unblock.
if
(
isFront
)
{
queue
.
unshift
(
error
)
}
else
{
queue
.
push
(
error
)
}
}
packages/next/src/client/components/react-dev-overlay/internal/helpers/use-error-handler.ts
View file @
24da437c
import
{
useEffect
}
from
'react'
import
{
useEffect
}
from
'react'
import
{
isHydrationError
}
from
'../../../is-hydration-error'
import
{
attachHydrationErrorState
}
from
'./attach-hydration-error-state'
import
{
attachHydrationErrorState
}
from
'./attach-hydration-error-state'
import
{
isNextRouterError
}
from
'../../../is-next-router-error'
import
{
isNextRouterError
}
from
'../../../is-next-router-error'
import
{
storeHydrationErrorStateFromConsoleArgs
}
from
'./hydration-error-info'
import
{
storeHydrationErrorStateFromConsoleArgs
}
from
'./hydration-error-info'
import
{
formatConsoleArgs
}
from
'../../../../lib/console'
import
{
formatConsoleArgs
}
from
'../../../../lib/console'
import
isError
from
'../../../../../lib/is-error'
import
isError
from
'../../../../../lib/is-error'
import
{
ConsoleError
}
from
'./console-error'
import
{
ConsoleError
}
from
'./console-error'
import
{
enqueueConsecutiveDedupedError
}
from
'./enqueue-client-error'
export
type
ErrorHandler
=
(
error
:
Error
)
=>
void
export
type
ErrorHandler
=
(
error
:
Error
)
=>
void
...
@@ -30,14 +30,7 @@ export function handleClientError(
...
@@ -30,14 +30,7 @@ export function handleClientError(
storeHydrationErrorStateFromConsoleArgs
(...
consoleErrorArgs
)
storeHydrationErrorStateFromConsoleArgs
(...
consoleErrorArgs
)
attachHydrationErrorState
(
error
)
attachHydrationErrorState
(
error
)
// TODO: change all to push error into errorQueue,
enqueueConsecutiveDedupedError
(
errorQueue
,
error
)
// currently there's a async api error is always erroring while hydration error showing up.
// Move hydration error to the front of the queue to unblock.
if
(
isHydrationError
(
error
))
{
errorQueue
.
unshift
(
error
)
}
else
{
errorQueue
.
push
(
error
)
}
for
(
const
handler
of
errorHandlers
)
{
for
(
const
handler
of
errorHandlers
)
{
handler
(
error
)
handler
(
error
)
}
}
...
...
test/development/app-dir/capture-console-error/app/browser/page.js
→
test/development/app-dir/capture-console-error/app/browser/
event/
page.js
View file @
24da437c
File moved
test/development/app-dir/capture-console-error/app/browser/render/page.js
0 → 100644
View file @
24da437c
'use client'
export
default
function
Page
()
{
console
.
error
(
'trigger an console.error in render'
)
return
<
p
>
render
<
/p
>
}
test/development/app-dir/capture-console-error/capture-console-error.test.ts
View file @
24da437c
...
@@ -28,7 +28,7 @@ describe('app-dir - capture-console-error', () => {
...
@@ -28,7 +28,7 @@ describe('app-dir - capture-console-error', () => {
})
})
it
(
'should capture browser console error and format the error message'
,
async
()
=>
{
it
(
'should capture browser console error and format the error message'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/browser'
)
const
browser
=
await
next
.
browser
(
'/browser
/event
'
)
await
browser
.
elementByCss
(
'button'
).
click
()
await
browser
.
elementByCss
(
'button'
).
click
()
await
waitForAndOpenRuntimeError
(
browser
)
await
waitForAndOpenRuntimeError
(
browser
)
...
@@ -42,7 +42,7 @@ describe('app-dir - capture-console-error', () => {
...
@@ -42,7 +42,7 @@ describe('app-dir - capture-console-error', () => {
"callStacks": "",
"callStacks": "",
"count": 1,
"count": 1,
"description": "trigger an console <error>",
"description": "trigger an console <error>",
"source": "app/browser/page.js (7:17) @ onClick
"source": "app/browser/
event/
page.js (7:17) @ onClick
5 | <button
5 | <button
6 | onClick={() => {
6 | onClick={() => {
...
@@ -59,7 +59,7 @@ describe('app-dir - capture-console-error', () => {
...
@@ -59,7 +59,7 @@ describe('app-dir - capture-console-error', () => {
"callStacks": "",
"callStacks": "",
"count": 1,
"count": 1,
"description": "trigger an console <error>",
"description": "trigger an console <error>",
"source": "app/browser/page.js (7:17) @ error
"source": "app/browser/
event/
page.js (7:17) @ error
5 | <button
5 | <button
6 | onClick={() => {
6 | onClick={() => {
...
@@ -73,6 +73,51 @@ describe('app-dir - capture-console-error', () => {
...
@@ -73,6 +73,51 @@ describe('app-dir - capture-console-error', () => {
}
}
})
})
it
(
'should capture browser console error in render and dedupe if necessary'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/browser/render'
)
await
waitForAndOpenRuntimeError
(
browser
)
await
assertHasRedbox
(
browser
)
const
result
=
await
getRedboxResult
(
browser
)
if
(
process
.
env
.
TURBOPACK
)
{
expect
(
result
).
toMatchInlineSnapshot
(
`
{
"callStacks": "",
"count": 1,
"description": "trigger an console.error in render",
"source": "app/browser/render/page.js (4:11) @ Page
2 |
3 | export default function Page() {
> 4 | console.error('trigger an console.error in render')
| ^
5 | return <p>render</p>
6 | }
7 |",
}
`
)
}
else
{
expect
(
result
).
toMatchInlineSnapshot
(
`
{
"callStacks": "",
"count": 1,
"description": "trigger an console.error in render",
"source": "app/browser/render/page.js (4:11) @ error
2 |
3 | export default function Page() {
> 4 | console.error('trigger an console.error in render')
| ^
5 | return <p>render</p>
6 | }
7 |",
}
`
)
}
})
it
(
'should capture server replay console error'
,
async
()
=>
{
it
(
'should capture server replay console error'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/ssr'
)
const
browser
=
await
next
.
browser
(
'/ssr'
)
...
@@ -85,7 +130,7 @@ describe('app-dir - capture-console-error', () => {
...
@@ -85,7 +130,7 @@ describe('app-dir - capture-console-error', () => {
expect
(
result
).
toMatchInlineSnapshot
(
`
expect
(
result
).
toMatchInlineSnapshot
(
`
{
{
"callStacks": "",
"callStacks": "",
"count":
2
,
"count":
1
,
"description": "ssr console error:client",
"description": "ssr console error:client",
"source": "app/ssr/page.js (4:11) @ Page
"source": "app/ssr/page.js (4:11) @ Page
...
@@ -102,7 +147,7 @@ describe('app-dir - capture-console-error', () => {
...
@@ -102,7 +147,7 @@ describe('app-dir - capture-console-error', () => {
expect
(
result
).
toMatchInlineSnapshot
(
`
expect
(
result
).
toMatchInlineSnapshot
(
`
{
{
"callStacks": "",
"callStacks": "",
"count":
2
,
"count":
1
,
"description": "ssr console error:client",
"description": "ssr console error:client",
"source": "app/ssr/page.js (4:11) @ error
"source": "app/ssr/page.js (4:11) @ error
...
...
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