Unverified Commit b2c751f4 authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[devtools] Remove unused `componentStackFrames` field (#82395)

parent 333489d8
...@@ -4,10 +4,7 @@ import './app-webpack' ...@@ -4,10 +4,7 @@ import './app-webpack'
import { renderAppDevOverlay } from 'next/dist/compiled/next-devtools' import { renderAppDevOverlay } from 'next/dist/compiled/next-devtools'
import { appBootstrap } from './app-bootstrap' import { appBootstrap } from './app-bootstrap'
import { import { getOwnerStack } from '../next-devtools/userspace/app/errors/stitched-error'
getComponentStack,
getOwnerStack,
} from '../next-devtools/userspace/app/errors/stitched-error'
import { isRecoverableError } from './react-client-callbacks/on-recoverable-error' import { isRecoverableError } from './react-client-callbacks/on-recoverable-error'
// eslint-disable-next-line @next/internal/typechecked-require // eslint-disable-next-line @next/internal/typechecked-require
...@@ -18,6 +15,6 @@ appBootstrap(() => { ...@@ -18,6 +15,6 @@ appBootstrap(() => {
try { try {
hydrate(instrumentationHooks) hydrate(instrumentationHooks)
} finally { } finally {
renderAppDevOverlay(getComponentStack, getOwnerStack, isRecoverableError) renderAppDevOverlay(getOwnerStack, isRecoverableError)
} }
}) })
...@@ -13,11 +13,11 @@ appBootstrap(() => { ...@@ -13,11 +13,11 @@ appBootstrap(() => {
hydrate(instrumentationHooks) hydrate(instrumentationHooks)
} finally { } finally {
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
const { getComponentStack, getOwnerStack } = const { getOwnerStack } =
require('../next-devtools/userspace/app/errors/stitched-error') as typeof import('../next-devtools/userspace/app/errors/stitched-error') require('../next-devtools/userspace/app/errors/stitched-error') as typeof import('../next-devtools/userspace/app/errors/stitched-error')
const { renderAppDevOverlay } = const { renderAppDevOverlay } =
require('next/dist/compiled/next-devtools') as typeof import('next/dist/compiled/next-devtools') require('next/dist/compiled/next-devtools') as typeof import('next/dist/compiled/next-devtools')
renderAppDevOverlay(getComponentStack, getOwnerStack, isRecoverableError) renderAppDevOverlay(getOwnerStack, isRecoverableError)
} }
} }
}) })
...@@ -54,7 +54,7 @@ export function onCaughtError( ...@@ -54,7 +54,7 @@ export function onCaughtError(
// We don't consider errors caught unless they're caught by an explicit error // We don't consider errors caught unless they're caught by an explicit error
// boundary. The built-in ones are considered implicit. // boundary. The built-in ones are considered implicit.
// This mimics how the same app would behave without Next.js. // This mimics how the same app would behave without Next.js.
return onUncaughtError(thrownValue, errorInfo) return onUncaughtError(thrownValue)
} }
// Skip certain custom errors which are not expected to be reported on client // Skip certain custom errors which are not expected to be reported on client
...@@ -84,7 +84,7 @@ export function onCaughtError( ...@@ -84,7 +84,7 @@ export function onCaughtError(
: `The above error occurred in one of your components.` : `The above error occurred in one of your components.`
const errorLocation = `${componentErrorMessage} ${errorBoundaryMessage}` const errorLocation = `${componentErrorMessage} ${errorBoundaryMessage}`
const error = devToolErrorMod.decorateDevError(thrownValue, errorInfo) const error = devToolErrorMod.decorateDevError(thrownValue)
// Log and report the error with location but without modifying the error stack // Log and report the error with location but without modifying the error stack
devToolErrorMod.originConsoleError('%o\n\n%s', thrownValue, errorLocation) devToolErrorMod.originConsoleError('%o\n\n%s', thrownValue, errorLocation)
...@@ -95,15 +95,12 @@ export function onCaughtError( ...@@ -95,15 +95,12 @@ export function onCaughtError(
} }
} }
export function onUncaughtError( export function onUncaughtError(thrownValue: unknown) {
thrownValue: unknown,
errorInfo: React.ErrorInfo
) {
// Skip certain custom errors which are not expected to be reported on client // Skip certain custom errors which are not expected to be reported on client
if (isBailoutToCSRError(thrownValue) || isNextRouterError(thrownValue)) return if (isBailoutToCSRError(thrownValue) || isNextRouterError(thrownValue)) return
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
const error = devToolErrorMod.decorateDevError(thrownValue, errorInfo) const error = devToolErrorMod.decorateDevError(thrownValue)
// TODO: Add an adendum to the overlay telling people about custom error boundaries. // TODO: Add an adendum to the overlay telling people about custom error boundaries.
reportGlobalError(error) reportGlobalError(error)
......
...@@ -12,8 +12,7 @@ export function isRecoverableError(error: Error): boolean { ...@@ -12,8 +12,7 @@ export function isRecoverableError(error: Error): boolean {
} }
export const onRecoverableError: HydrationOptions['onRecoverableError'] = ( export const onRecoverableError: HydrationOptions['onRecoverableError'] = (
error, error
errorInfo
) => { ) => {
// x-ref: https://github.com/facebook/react/pull/28736 // x-ref: https://github.com/facebook/react/pull/28736
let cause = isError(error) && 'cause' in error ? error.cause : error let cause = isError(error) && 'cause' in error ? error.cause : error
...@@ -23,7 +22,7 @@ export const onRecoverableError: HydrationOptions['onRecoverableError'] = ( ...@@ -23,7 +22,7 @@ export const onRecoverableError: HydrationOptions['onRecoverableError'] = (
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
const { decorateDevError } = const { decorateDevError } =
require('../../next-devtools/userspace/app/errors/stitched-error') as typeof import('../../next-devtools/userspace/app/errors/stitched-error') require('../../next-devtools/userspace/app/errors/stitched-error') as typeof import('../../next-devtools/userspace/app/errors/stitched-error')
const causeError = decorateDevError(cause, errorInfo) const causeError = decorateDevError(cause)
recoverableErrors.add(causeError) recoverableErrors.add(causeError)
cause = causeError cause = causeError
} }
......
...@@ -185,13 +185,11 @@ function replayQueuedEvents(dispatch: NonNullable<typeof maybeDispatch>) { ...@@ -185,13 +185,11 @@ function replayQueuedEvents(dispatch: NonNullable<typeof maybeDispatch>) {
} }
function DevOverlayRoot({ function DevOverlayRoot({
getComponentStack,
getOwnerStack, getOwnerStack,
getSquashedHydrationErrorDetails, getSquashedHydrationErrorDetails,
isRecoverableError, isRecoverableError,
routerType, routerType,
}: { }: {
getComponentStack: (error: Error) => string | undefined
getOwnerStack: (error: Error) => string | null | undefined getOwnerStack: (error: Error) => string | null | undefined
getSquashedHydrationErrorDetails: (error: Error) => HydrationErrorState | null getSquashedHydrationErrorDetails: (error: Error) => HydrationErrorState | null
isRecoverableError: (error: Error) => boolean isRecoverableError: (error: Error) => boolean
...@@ -199,7 +197,6 @@ function DevOverlayRoot({ ...@@ -199,7 +197,6 @@ function DevOverlayRoot({
}) { }) {
const [state, dispatch] = useErrorOverlayReducer( const [state, dispatch] = useErrorOverlayReducer(
routerType, routerType,
getComponentStack,
getOwnerStack, getOwnerStack,
isRecoverableError isRecoverableError
) )
...@@ -254,7 +251,6 @@ function getSquashedHydrationErrorDetailsApp() { ...@@ -254,7 +251,6 @@ function getSquashedHydrationErrorDetailsApp() {
} }
export function renderAppDevOverlay( export function renderAppDevOverlay(
getComponentStack: (error: Error) => string | undefined,
getOwnerStack: (error: Error) => string | null | undefined, getOwnerStack: (error: Error) => string | null | undefined,
isRecoverableError: (error: Error) => boolean isRecoverableError: (error: Error) => boolean
): void { ): void {
...@@ -293,7 +289,6 @@ export function renderAppDevOverlay( ...@@ -293,7 +289,6 @@ export function renderAppDevOverlay(
// At least it won't unmount any user code if it errors. // At least it won't unmount any user code if it errors.
root.render( root.render(
<DevOverlayRoot <DevOverlayRoot
getComponentStack={getComponentStack}
getOwnerStack={getOwnerStack} getOwnerStack={getOwnerStack}
getSquashedHydrationErrorDetails={getSquashedHydrationErrorDetailsApp} getSquashedHydrationErrorDetails={getSquashedHydrationErrorDetailsApp}
isRecoverableError={isRecoverableError} isRecoverableError={isRecoverableError}
...@@ -307,7 +302,6 @@ export function renderAppDevOverlay( ...@@ -307,7 +302,6 @@ export function renderAppDevOverlay(
} }
export function renderPagesDevOverlay( export function renderPagesDevOverlay(
getComponentStack: (error: Error) => string | undefined,
getOwnerStack: (error: Error) => string | null | undefined, getOwnerStack: (error: Error) => string | null | undefined,
getSquashedHydrationErrorDetails: ( getSquashedHydrationErrorDetails: (
error: Error error: Error
...@@ -357,7 +351,6 @@ export function renderPagesDevOverlay( ...@@ -357,7 +351,6 @@ export function renderPagesDevOverlay(
// At least it won't unmount any user code if it errors. // At least it won't unmount any user code if it errors.
root.render( root.render(
<DevOverlayRoot <DevOverlayRoot
getComponentStack={getComponentStack}
getOwnerStack={getOwnerStack} getOwnerStack={getOwnerStack}
getSquashedHydrationErrorDetails={getSquashedHydrationErrorDetails} getSquashedHydrationErrorDetails={getSquashedHydrationErrorDetails}
isRecoverableError={isRecoverableError} isRecoverableError={isRecoverableError}
......
...@@ -21,7 +21,6 @@ export const Default: Story = { ...@@ -21,7 +21,6 @@ export const Default: Story = {
runtime: true, runtime: true,
error: new Error('First error message'), error: new Error('First error message'),
frames: () => Promise.resolve([]), frames: () => Promise.resolve([]),
componentStackFrames: undefined,
type: 'runtime', type: 'runtime',
}, },
{ {
...@@ -29,7 +28,6 @@ export const Default: Story = { ...@@ -29,7 +28,6 @@ export const Default: Story = {
runtime: true, runtime: true,
error: new Error('Second error message'), error: new Error('Second error message'),
frames: () => Promise.resolve([]), frames: () => Promise.resolve([]),
componentStackFrames: undefined,
type: 'runtime', type: 'runtime',
}, },
{ {
...@@ -37,7 +35,6 @@ export const Default: Story = { ...@@ -37,7 +35,6 @@ export const Default: Story = {
runtime: true, runtime: true,
error: new Error('Third error message'), error: new Error('Third error message'),
frames: () => Promise.resolve([]), frames: () => Promise.resolve([]),
componentStackFrames: undefined,
type: 'runtime', type: 'runtime',
}, },
], ],
......
...@@ -22,7 +22,6 @@ const mockErrors: ReadyRuntimeError[] = [ ...@@ -22,7 +22,6 @@ const mockErrors: ReadyRuntimeError[] = [
runtime: true as const, runtime: true as const,
error: new Error('First error'), error: new Error('First error'),
frames: () => Promise.resolve([]), frames: () => Promise.resolve([]),
componentStackFrames: undefined,
type: 'runtime', type: 'runtime',
}, },
{ {
...@@ -30,7 +29,6 @@ const mockErrors: ReadyRuntimeError[] = [ ...@@ -30,7 +29,6 @@ const mockErrors: ReadyRuntimeError[] = [
runtime: true as const, runtime: true as const,
error: new Error('Second error'), error: new Error('Second error'),
frames: () => Promise.resolve([]), frames: () => Promise.resolve([]),
componentStackFrames: undefined,
type: 'runtime', type: 'runtime',
}, },
{ {
...@@ -38,7 +36,6 @@ const mockErrors: ReadyRuntimeError[] = [ ...@@ -38,7 +36,6 @@ const mockErrors: ReadyRuntimeError[] = [
runtime: true as const, runtime: true as const,
error: new Error('Third error'), error: new Error('Third error'),
frames: () => Promise.resolve([]), frames: () => Promise.resolve([]),
componentStackFrames: undefined,
type: 'runtime', type: 'runtime',
}, },
] ]
......
...@@ -89,22 +89,6 @@ export const WithHydrationWarning: Story = { ...@@ -89,22 +89,6 @@ export const WithHydrationWarning: Story = {
}, },
}, },
]), ]),
componentStackFrames: [
{
component: 'MyComponent',
file: 'app/page.tsx',
line1: 10,
column1: 5,
canOpenInEditor: true,
},
{
component: 'ParentComponent',
file: 'app/layout.tsx',
line1: 20,
column1: 3,
canOpenInEditor: true,
},
],
type: 'runtime', type: 'runtime',
}, },
], ],
......
...@@ -6,14 +6,12 @@ import { ...@@ -6,14 +6,12 @@ import {
getErrorByType, getErrorByType,
type ReadyRuntimeError, type ReadyRuntimeError,
} from '../../utils/get-error-by-type' } from '../../utils/get-error-by-type'
import type { ComponentStackFrame } from '../../utils/parse-component-stack'
import { usePersistentCacheErrorDetection } from '../../components/errors/error-overlay-toolbar/restart-server-button' import { usePersistentCacheErrorDetection } from '../../components/errors/error-overlay-toolbar/restart-server-button'
export type SupportedErrorEvent = { export type SupportedErrorEvent = {
id: number id: number
error: Error error: Error
frames: readonly StackFrame[] frames: readonly StackFrame[]
componentStackFrames?: readonly ComponentStackFrame[]
type: 'runtime' | 'recoverable' | 'console' type: 'runtime' | 'recoverable' | 'console'
} }
......
...@@ -2,7 +2,6 @@ import { useReducer } from 'react' ...@@ -2,7 +2,6 @@ import { useReducer } from 'react'
import type { VersionInfo } from '../../server/dev/parse-version-info' import type { VersionInfo } from '../../server/dev/parse-version-info'
import type { SupportedErrorEvent } from './container/runtime-error/render-error' import type { SupportedErrorEvent } from './container/runtime-error/render-error'
import { parseComponentStack } from './utils/parse-component-stack'
import type { DebugInfo } from '../shared/types' import type { DebugInfo } from '../shared/types'
import type { DevIndicatorServerState } from '../../server/dev/dev-indicator-server-state' import type { DevIndicatorServerState } from '../../server/dev/dev-indicator-server-state'
import { parseStack } from '../../server/lib/parse-stack' import { parseStack } from '../../server/lib/parse-stack'
...@@ -319,7 +318,6 @@ function getInitialState( ...@@ -319,7 +318,6 @@ function getInitialState(
export function useErrorOverlayReducer( export function useErrorOverlayReducer(
routerType: 'pages' | 'app', routerType: 'pages' | 'app',
getComponentStack: (error: Error) => string | undefined,
getOwnerStack: (error: Error) => string | null | undefined, getOwnerStack: (error: Error) => string | null | undefined,
isRecoverableError: (error: Error) => boolean isRecoverableError: (error: Error) => boolean
) { ) {
...@@ -328,18 +326,12 @@ export function useErrorOverlayReducer( ...@@ -328,18 +326,12 @@ export function useErrorOverlayReducer(
id: number, id: number,
error: Error error: Error
): readonly SupportedErrorEvent[] { ): readonly SupportedErrorEvent[] {
const componentStack = getComponentStack(error)
const componentStackFrames =
componentStack === undefined
? undefined
: parseComponentStack(componentStack)
const ownerStack = getOwnerStack(error) const ownerStack = getOwnerStack(error)
const frames = parseStack((error.stack || '') + (ownerStack || '')) const frames = parseStack((error.stack || '') + (ownerStack || ''))
const pendingEvent: SupportedErrorEvent = { const pendingEvent: SupportedErrorEvent = {
id, id,
error, error,
frames, frames,
componentStackFrames,
type: isRecoverableError(error) type: isRecoverableError(error)
? 'recoverable' ? 'recoverable'
: isConsoleError(error) : isConsoleError(error)
......
...@@ -62,15 +62,6 @@ export const errors: SupportedErrorEvent[] = [ ...@@ -62,15 +62,6 @@ export const errors: SupportedErrorEvent[] = [
error: Object.assign(new Error('First error message'), { error: Object.assign(new Error('First error message'), {
__NEXT_ERROR_CODE: 'E001', __NEXT_ERROR_CODE: 'E001',
}), }),
componentStackFrames: [
{
file: 'app/page.tsx',
component: 'Home',
line1: 10,
column1: 5,
canOpenInEditor: true,
},
],
frames: [ frames: [
{ {
file: 'app/page.tsx', file: 'app/page.tsx',
...@@ -126,7 +117,6 @@ export const runtimeErrors: ReadyRuntimeError[] = [ ...@@ -126,7 +117,6 @@ export const runtimeErrors: ReadyRuntimeError[] = [
}, },
...Array(20).fill(ignoredFrame), ...Array(20).fill(ignoredFrame),
]), ]),
componentStackFrames: undefined,
type: 'runtime', type: 'runtime',
}, },
{ {
...@@ -145,7 +135,6 @@ export const runtimeErrors: ReadyRuntimeError[] = [ ...@@ -145,7 +135,6 @@ export const runtimeErrors: ReadyRuntimeError[] = [
originalCodeFrame: originalCodeFrame('Second error message'), originalCodeFrame: originalCodeFrame('Second error message'),
}, },
]), ]),
componentStackFrames: undefined,
type: 'console', type: 'console',
}, },
{ {
...@@ -164,7 +153,6 @@ export const runtimeErrors: ReadyRuntimeError[] = [ ...@@ -164,7 +153,6 @@ export const runtimeErrors: ReadyRuntimeError[] = [
originalCodeFrame: originalCodeFrame('Third error message'), originalCodeFrame: originalCodeFrame('Third error message'),
}, },
]), ]),
componentStackFrames: undefined,
type: 'recoverable', type: 'recoverable',
}, },
{ {
...@@ -183,7 +171,6 @@ export const runtimeErrors: ReadyRuntimeError[] = [ ...@@ -183,7 +171,6 @@ export const runtimeErrors: ReadyRuntimeError[] = [
originalCodeFrame: originalCodeFrame('typeof window !== undefined'), originalCodeFrame: originalCodeFrame('typeof window !== undefined'),
}, },
]), ]),
componentStackFrames: undefined,
type: 'runtime', type: 'runtime',
}, },
{ {
...@@ -208,7 +195,6 @@ export const runtimeErrors: ReadyRuntimeError[] = [ ...@@ -208,7 +195,6 @@ export const runtimeErrors: ReadyRuntimeError[] = [
originalCodeFrame: originalCodeFrame('Fifth error message'), originalCodeFrame: originalCodeFrame('Fifth error message'),
}, },
]), ]),
componentStackFrames: undefined,
type: 'console', type: 'console',
}, },
{ {
...@@ -227,7 +213,6 @@ export const runtimeErrors: ReadyRuntimeError[] = [ ...@@ -227,7 +213,6 @@ export const runtimeErrors: ReadyRuntimeError[] = [
originalCodeFrame: originalCodeFrame('Sixth error message'), originalCodeFrame: originalCodeFrame('Sixth error message'),
}, },
]), ]),
componentStackFrames: undefined,
type: 'recoverable', type: 'recoverable',
}, },
{ {
...@@ -246,7 +231,6 @@ export const runtimeErrors: ReadyRuntimeError[] = [ ...@@ -246,7 +231,6 @@ export const runtimeErrors: ReadyRuntimeError[] = [
originalCodeFrame: originalCodeFrame('Sixth error message'), originalCodeFrame: originalCodeFrame('Sixth error message'),
}, },
]), ]),
componentStackFrames: undefined,
type: 'runtime', type: 'runtime',
}, },
{ {
...@@ -265,7 +249,6 @@ export const runtimeErrors: ReadyRuntimeError[] = [ ...@@ -265,7 +249,6 @@ export const runtimeErrors: ReadyRuntimeError[] = [
originalCodeFrame: originalCodeFrame('Eighth error message'), originalCodeFrame: originalCodeFrame('Eighth error message'),
}, },
]), ]),
componentStackFrames: undefined,
type: 'runtime', type: 'runtime',
}, },
{ {
...@@ -284,7 +267,6 @@ export const runtimeErrors: ReadyRuntimeError[] = [ ...@@ -284,7 +267,6 @@ export const runtimeErrors: ReadyRuntimeError[] = [
originalCodeFrame: originalCodeFrame('Ninth error message'), originalCodeFrame: originalCodeFrame('Ninth error message'),
}, },
]), ]),
componentStackFrames: undefined,
type: 'runtime', type: 'runtime',
}, },
{ {
...@@ -303,7 +285,6 @@ export const runtimeErrors: ReadyRuntimeError[] = [ ...@@ -303,7 +285,6 @@ export const runtimeErrors: ReadyRuntimeError[] = [
originalCodeFrame: originalCodeFrame('Tenth error message'), originalCodeFrame: originalCodeFrame('Tenth error message'),
}, },
]), ]),
componentStackFrames: undefined,
type: 'runtime', type: 'runtime',
}, },
] ]
import type { SupportedErrorEvent } from '../container/runtime-error/render-error' import type { SupportedErrorEvent } from '../container/runtime-error/render-error'
import { getOriginalStackFrames } from '../../shared/stack-frame' import { getOriginalStackFrames } from '../../shared/stack-frame'
import type { OriginalStackFrame } from '../../shared/stack-frame' import type { OriginalStackFrame } from '../../shared/stack-frame'
import type { ComponentStackFrame } from './parse-component-stack'
import { getErrorSource } from '../../../shared/lib/error-source' import { getErrorSource } from '../../../shared/lib/error-source'
import React from 'react' import React from 'react'
...@@ -12,7 +11,6 @@ export type ReadyRuntimeError = { ...@@ -12,7 +11,6 @@ export type ReadyRuntimeError = {
frames: frames:
| readonly OriginalStackFrame[] | readonly OriginalStackFrame[]
| (() => Promise<readonly OriginalStackFrame[]>) | (() => Promise<readonly OriginalStackFrame[]>)
componentStackFrames: readonly ComponentStackFrame[] | undefined
type: 'runtime' | 'console' | 'recoverable' type: 'runtime' | 'console' | 'recoverable'
} }
...@@ -51,7 +49,6 @@ export async function getErrorByType( ...@@ -51,7 +49,6 @@ export async function getErrorByType(
runtime: true, runtime: true,
error: event.error, error: event.error,
type: event.type, type: event.type,
componentStackFrames: event.componentStackFrames,
} as const } as const
if ('use' in React) { if ('use' in React) {
......
export type ComponentStackFrame = {
canOpenInEditor: boolean
component: string
file: string | null
line1: number | null
column1: number | null
}
enum LocationType {
FILE = 'file',
WEBPACK_INTERNAL = 'webpack-internal',
HTTP = 'http',
PROTOCOL_RELATIVE = 'protocol-relative',
UNKNOWN = 'unknown',
}
/**
* Get the type of frame line based on the location
*/
function getLocationType(location: string): LocationType {
if (location.startsWith('file://')) {
return LocationType.FILE
}
if (location.includes('webpack-internal://')) {
return LocationType.WEBPACK_INTERNAL
}
if (location.startsWith('http://') || location.startsWith('https://')) {
return LocationType.HTTP
}
if (location.startsWith('//')) {
return LocationType.PROTOCOL_RELATIVE
}
return LocationType.UNKNOWN
}
function parseStackFrameLocation(
location: string
): Omit<ComponentStackFrame, 'component'> {
const locationType = getLocationType(location)
const modulePath = location?.replace(
/^(webpack-internal:\/\/\/|file:\/\/)(\(.*\)\/)?/,
''
)
const [, file, line1, column1] = modulePath?.match(/^(.+):(\d+):(\d+)/) ?? []
switch (locationType) {
case LocationType.FILE:
case LocationType.WEBPACK_INTERNAL:
return {
canOpenInEditor: true,
file,
line1: line1 ? Number(line1) : null,
column1: column1 ? Number(column1) : null,
}
// When the location is a URL we only show the file
// TODO: Resolve http(s) URLs through sourcemaps
case LocationType.HTTP:
case LocationType.PROTOCOL_RELATIVE:
case LocationType.UNKNOWN:
default: {
return {
canOpenInEditor: false,
file: null,
line1: null,
column1: null,
}
}
}
}
export function parseComponentStack(
componentStack: string
): ComponentStackFrame[] {
const componentStackFrames: ComponentStackFrame[] = []
for (const line of componentStack.trim().split('\n')) {
// TODO: support safari stack trace
// Get component and file from the component stack line
const match = /at ([^ ]+)( \((.*)\))?/.exec(line)
if (match?.[1]) {
const component = match[1]
const location = match[3]
if (!location) {
componentStackFrames.push({
canOpenInEditor: false,
component,
file: null,
line1: null,
column1: null,
})
continue
}
// Stop parsing the component stack if we reach a Next.js component
if (location?.includes('next/dist')) {
break
}
const frameLocation = parseStackFrameLocation(location)
componentStackFrames.push({
component,
...frameLocation,
})
}
}
return componentStackFrames
}
...@@ -2,14 +2,6 @@ import React from 'react' ...@@ -2,14 +2,6 @@ import React from 'react'
import isError from '../../../../lib/is-error' import isError from '../../../../lib/is-error'
const ownerStacks = new WeakMap<Error, string | null>() const ownerStacks = new WeakMap<Error, string | null>()
const componentStacks = new WeakMap<Error, string>()
export function getComponentStack(error: Error): string | undefined {
return componentStacks.get(error)
}
export function setComponentStack(error: Error, stack: string) {
componentStacks.set(error, stack)
}
export function getOwnerStack(error: Error): string | null | undefined { export function getOwnerStack(error: Error): string | null | undefined {
return ownerStacks.get(error) return ownerStacks.get(error)
...@@ -29,16 +21,8 @@ export function setOwnerStackIfAvailable(error: Error): void { ...@@ -29,16 +21,8 @@ export function setOwnerStackIfAvailable(error: Error): void {
} }
} }
export function decorateDevError( export function decorateDevError(thrownValue: unknown) {
thrownValue: unknown,
errorInfo: React.ErrorInfo
) {
const error = coerceError(thrownValue) const error = coerceError(thrownValue)
setOwnerStackIfAvailable(error) setOwnerStackIfAvailable(error)
// TODO: change to passing down errorInfo later
// In development mode, pass along the component stack to the error
if (errorInfo.componentStack) {
setComponentStack(error, errorInfo.componentStack)
}
return error return error
} }
...@@ -6,7 +6,7 @@ import { ...@@ -6,7 +6,7 @@ import {
storeHydrationErrorStateFromConsoleArgs, storeHydrationErrorStateFromConsoleArgs,
} from './hydration-error-state' } from './hydration-error-state'
import { Router } from '../../../client/router' import { Router } from '../../../client/router'
import { getComponentStack, getOwnerStack } from '../app/errors/stitched-error' import { getOwnerStack } from '../app/errors/stitched-error'
import { isRecoverableError } from '../../../client/react-client-callbacks/on-recoverable-error' import { isRecoverableError } from '../../../client/react-client-callbacks/on-recoverable-error'
import { getSquashedHydrationErrorDetails } from './hydration-error-state' import { getSquashedHydrationErrorDetails } from './hydration-error-state'
import { PagesDevOverlayErrorBoundary } from './pages-dev-overlay-error-boundary' import { PagesDevOverlayErrorBoundary } from './pages-dev-overlay-error-boundary'
...@@ -23,7 +23,6 @@ const usePagesDevOverlayBridge = () => { ...@@ -23,7 +23,6 @@ const usePagesDevOverlayBridge = () => {
// NDT uses a different React instance so it's not technically a state update // NDT uses a different React instance so it's not technically a state update
// scheduled from useInsertionEffect. // scheduled from useInsertionEffect.
renderPagesDevOverlay( renderPagesDevOverlay(
getComponentStack,
getOwnerStack, getOwnerStack,
getSquashedHydrationErrorDetails, getSquashedHydrationErrorDetails,
isRecoverableError isRecoverableError
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment