Skip to content

Commit f8889b9

Browse files
committed
recover the effects double logged error
1 parent 6a3e7c6 commit f8889b9

File tree

4 files changed

+59
-7
lines changed

4 files changed

+59
-7
lines changed

packages/next/src/client/components/react-dev-overlay/internal/helpers/stitched-error.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const REACT_ERROR_STACK_BOTTOM_FRAME_REGEX = new RegExp(
66
`(at ${REACT_ERROR_STACK_BOTTOM_FRAME} )|(${REACT_ERROR_STACK_BOTTOM_FRAME}\\@)`
77
)
88

9-
export function stripAfterReactBottomFrame(stack: string): string {
9+
function stripAfterReactBottomFrame(stack: string): string {
1010
const stackLines = stack.split('\n')
1111
const indexOfSplit = stackLines.findIndex((line) =>
1212
REACT_ERROR_STACK_BOTTOM_FRAME_REGEX.test(line)

packages/next/src/client/components/react-dev-overlay/internal/helpers/use-error-handler.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { formatConsoleArgs } from '../../../../lib/console'
66
import isError from '../../../../../lib/is-error'
77
import { createUnhandledError } from './console-error'
88
import { enqueueConsecutiveDedupedError } from './enqueue-client-error'
9-
import { stripAfterReactBottomFrame } from './stitched-error'
109

1110
export type ErrorHandler = (error: Error) => void
1211

@@ -27,7 +26,7 @@ export function handleClientError(
2726
error = createUnhandledError(formattedErrorMessage)
2827
// When the originStack is provided, strip the stack after the react-bottom-stack-frame
2928
if (originStack) {
30-
error.stack = stripAfterReactBottomFrame(originStack)
29+
error.stack = originStack
3130
}
3231
} else {
3332
error = originError
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use client'
2+
3+
export default function Page() {
4+
for (let i = 0; i < 3; i++) {
5+
console.error('trigger an console.error in loop of render')
6+
}
7+
return <p>render</p>
8+
}

test/development/app-dir/capture-console-error/capture-console-error.test.ts

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ describe('app-dir - capture-console-error', () => {
104104
expect(result).toMatchInlineSnapshot(`
105105
{
106106
"callStacks": null,
107-
"count": 1,
107+
"count": 2,
108108
"description": "trigger an console.error in render",
109109
"source": "app/browser/render/page.js (4:11) @ Page
110110
@@ -121,7 +121,52 @@ describe('app-dir - capture-console-error', () => {
121121
expect(result).toMatchInlineSnapshot(`
122122
{
123123
"callStacks": null,
124-
"count": 1,
124+
"count": 2,
125+
"description": "trigger an console.error in render",
126+
"source": "app/browser/render/page.js (4:11) @ error
127+
128+
2 |
129+
3 | export default function Page() {
130+
> 4 | console.error('trigger an console.error in render')
131+
| ^
132+
5 | return <p>render</p>
133+
6 | }
134+
7 |",
135+
}
136+
`)
137+
}
138+
})
139+
140+
it('should capture browser console error in render and dedupe when multi same errors logged', async () => {
141+
const browser = await next.browser('/browser/render')
142+
143+
await waitForAndOpenRuntimeError(browser)
144+
await assertHasRedbox(browser)
145+
146+
const result = await getRedboxResult(browser)
147+
148+
if (process.env.TURBOPACK) {
149+
expect(result).toMatchInlineSnapshot(`
150+
{
151+
"callStacks": null,
152+
"count": 2,
153+
"description": "trigger an console.error in render",
154+
"source": "app/browser/render/page.js (4:11) @ Page
155+
156+
2 |
157+
3 | export default function Page() {
158+
> 4 | console.error('trigger an console.error in render')
159+
| ^
160+
5 | return <p>render</p>
161+
6 | }
162+
7 |",
163+
}
164+
`)
165+
} else {
166+
expect(result).toMatchInlineSnapshot(`
167+
{
168+
"callStacks": null,
169+
"count": 2,
125170
"description": "trigger an console.error in render",
126171
"source": "app/browser/render/page.js (4:11) @ error
127172
@@ -149,7 +194,7 @@ describe('app-dir - capture-console-error', () => {
149194
expect(result).toMatchInlineSnapshot(`
150195
{
151196
"callStacks": null,
152-
"count": 1,
197+
"count": 2,
153198
"description": "ssr console error:client",
154199
"source": "app/ssr/page.js (4:11) @ Page
155200
@@ -166,7 +211,7 @@ describe('app-dir - capture-console-error', () => {
166211
expect(result).toMatchInlineSnapshot(`
167212
{
168213
"callStacks": null,
169-
"count": 1,
214+
"count": 2,
170215
"description": "ssr console error:client",
171216
"source": "app/ssr/page.js (4:11) @ error
172217

0 commit comments

Comments
 (0)