Skip to content

Commit c20afd3

Browse files
committed
revert unrelated changes
1 parent bcc5530 commit c20afd3

File tree

4 files changed

+40
-92
lines changed

4 files changed

+40
-92
lines changed

packages/next/src/client/components/globals/intercept-console-error.ts

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import { isNextRouterError } from '../is-next-router-error'
33
import { captureStackTrace } from '../react-dev-overlay/internal/helpers/capture-stack-trace'
44
import { handleClientError } from '../react-dev-overlay/internal/helpers/use-error-handler'
55

6-
const NEXT_CONSOLE_STACK_FRAME = 'next-console-stack-frame'
7-
86
export const originConsoleError = window.console.error
97

108
// Patch console.error to collect information about hydration errors
@@ -13,48 +11,41 @@ export function patchConsoleError() {
1311
if (typeof window === 'undefined') {
1412
return
1513
}
14+
window.console.error = function error(...args: any[]) {
15+
let maybeError: unknown
16+
let isReplayedError = false
1617

17-
const namedLoggerInstance = {
18-
[NEXT_CONSOLE_STACK_FRAME](...args: any[]) {
19-
let maybeError: unknown
20-
let isReplayedError = false
21-
22-
if (process.env.NODE_ENV !== 'production') {
23-
const replayedError = matchReplayedError(...args)
24-
if (replayedError) {
25-
isReplayedError = true
26-
maybeError = replayedError
27-
} else {
28-
// See https://github.com/facebook/react/blob/d50323eb845c5fde0d720cae888bf35dedd05506/packages/react-reconciler/src/ReactFiberErrorLogger.js#L78
29-
maybeError = args[1]
30-
}
18+
if (process.env.NODE_ENV !== 'production') {
19+
const replayedError = matchReplayedError(...args)
20+
if (replayedError) {
21+
isReplayedError = true
22+
maybeError = replayedError
3123
} else {
32-
maybeError = args[0]
24+
// See https://github.com/facebook/react/blob/d50323eb845c5fde0d720cae888bf35dedd05506/packages/react-reconciler/src/ReactFiberErrorLogger.js#L78
25+
maybeError = args[1]
3326
}
27+
} else {
28+
maybeError = args[0]
29+
}
3430

35-
if (!isNextRouterError(maybeError)) {
36-
if (process.env.NODE_ENV !== 'production') {
37-
// Create an origin stack that pointing to the origin location of the error
38-
if (!isReplayedError && isError(maybeError)) {
39-
captureStackTrace(maybeError)
40-
}
41-
42-
handleClientError(
43-
// replayed errors have their own complex format string that should be used,
44-
// but if we pass the error directly, `handleClientError` will ignore it
45-
maybeError,
46-
args
47-
)
31+
if (!isNextRouterError(maybeError)) {
32+
if (process.env.NODE_ENV !== 'production') {
33+
// Create an origin stack that pointing to the origin location of the error
34+
if (!isReplayedError && isError(maybeError)) {
35+
captureStackTrace(maybeError)
4836
}
4937

50-
originConsoleError.apply(window.console, args)
38+
handleClientError(
39+
// replayed errors have their own complex format string that should be used,
40+
// but if we pass the error directly, `handleClientError` will ignore it
41+
maybeError,
42+
args
43+
)
5144
}
52-
},
53-
}
5445

55-
window.console.error = namedLoggerInstance[NEXT_CONSOLE_STACK_FRAME].bind(
56-
window.console
57-
)
46+
originConsoleError.apply(window.console, args)
47+
}
48+
}
5849
}
5950

6051
function matchReplayedError(...args: unknown[]): Error | null {

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
import React from 'react'
22
import isError from '../../../../../lib/is-error'
3-
import { stripReactStackTrace } from './strip-stack-frame'
3+
4+
const REACT_ERROR_STACK_BOTTOM_FRAME = 'react-stack-bottom-frame'
5+
const REACT_ERROR_STACK_BOTTOM_FRAME_REGEX = new RegExp(
6+
`(at ${REACT_ERROR_STACK_BOTTOM_FRAME} )|(${REACT_ERROR_STACK_BOTTOM_FRAME}\\@)`
7+
)
48

59
export function getReactStitchedError<T = unknown>(err: T): Error | T {
610
if (typeof (React as any).captureOwnerStack !== 'function') {
711
return err
812
}
9-
1013
const isErrorInstance = isError(err)
1114
const originStack = isErrorInstance ? err.stack || '' : ''
1215
const originMessage = isErrorInstance ? err.message : ''
13-
let newStack = stripReactStackTrace(originStack)
16+
const stackLines = originStack.split('\n')
17+
const indexOfSplit = stackLines.findIndex((line) =>
18+
REACT_ERROR_STACK_BOTTOM_FRAME_REGEX.test(line)
19+
)
20+
const isOriginalReactError = indexOfSplit >= 0 // has the react-stack-bottom-frame
21+
let newStack = isOriginalReactError
22+
? stackLines.slice(0, indexOfSplit).join('\n')
23+
: originStack
1424

1525
const newError = new Error(originMessage)
1626
// Copy all enumerable properties, e.g. digest

packages/next/src/client/components/react-dev-overlay/internal/helpers/strip-stack-frame.test.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

packages/next/src/client/components/react-dev-overlay/internal/helpers/strip-stack-frame.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)