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

[devtools] Stop sending codeframes for ignored frames (#90577)

Co-authored-by: 's avatarCursor Agent <cursoragent@cursor.com>
parent 1cf02b2c
...@@ -4,6 +4,7 @@ import { ...@@ -4,6 +4,7 @@ import {
createOriginalStackFrame, createOriginalStackFrame,
getIgnoredSources, getIgnoredSources,
} from '../../../../server/dev/middleware-webpack' } from '../../../../server/dev/middleware-webpack'
import isInternal from '../../../../shared/lib/is-internal'
import type { webpack } from 'next/dist/compiled/webpack/webpack' import type { webpack } from 'next/dist/compiled/webpack/webpack'
import type { RawSourceMap } from 'next/dist/compiled/source-map08' import type { RawSourceMap } from 'next/dist/compiled/source-map08'
...@@ -89,10 +90,22 @@ async function getSourceFrame( ...@@ -89,10 +90,22 @@ async function getSourceFrame(
}, },
}) })
if (result === null || result.originalStackFrame === null) {
return {
column1: '',
frame: '',
line1: '',
}
}
const originalStackFrame = result.originalStackFrame
return { return {
frame: result?.originalCodeFrame ?? '', frame:
line1: result?.originalStackFrame?.line1?.toString() ?? '', (!isInternal(originalStackFrame.file)
column1: result?.originalStackFrame?.column1?.toString() ?? '', ? result.originalCodeFrame
: null) ?? '',
line1: originalStackFrame.line1?.toString() ?? '',
column1: originalStackFrame.column1?.toString() ?? '',
} }
} }
} catch {} } catch {}
......
import { codeFrameColumns } from 'next/dist/compiled/babel/code-frame' import { codeFrameColumns } from 'next/dist/compiled/babel/code-frame'
import isInternal from '../../shared/lib/is-internal'
import type { StackFrame } from '../../server/lib/parse-stack' import type { StackFrame } from '../../server/lib/parse-stack'
import { ignoreListAnonymousStackFramesIfSandwiched as ignoreListAnonymousStackFramesIfSandwichedGeneric } from '../../server/lib/source-maps' import { ignoreListAnonymousStackFramesIfSandwiched as ignoreListAnonymousStackFramesIfSandwichedGeneric } from '../../server/lib/source-maps'
...@@ -68,7 +67,7 @@ export function getOriginalCodeFrame( ...@@ -68,7 +67,7 @@ export function getOriginalCodeFrame(
source: string | null, source: string | null,
colors: boolean = process.stdout.isTTY colors: boolean = process.stdout.isTTY
): string | null { ): string | null {
if (!source || isInternal(frame.file)) { if (!source) {
return null return null
} }
......
...@@ -307,16 +307,25 @@ async function createOriginalStackFrame( ...@@ -307,16 +307,25 @@ async function createOriginalStackFrame(
) )
} }
/** undefined = not yet computed */
let originalCodeFrame: string | null | undefined
const tracedFrame = traced.frame
return { return {
originalStackFrame: { originalStackFrame: {
arguments: traced.frame.arguments, arguments: tracedFrame.arguments,
file: normalizedStackFrameLocation, file: normalizedStackFrameLocation,
line1: traced.frame.line1, line1: tracedFrame.line1,
column1: traced.frame.column1, column1: tracedFrame.column1,
ignored: traced.frame.ignored, ignored: tracedFrame.ignored,
methodName: traced.frame.methodName, methodName: tracedFrame.methodName,
},
get originalCodeFrame() {
if (originalCodeFrame === undefined) {
originalCodeFrame = getOriginalCodeFrame(tracedFrame, traced.source)
}
return originalCodeFrame
}, },
originalCodeFrame: getOriginalCodeFrame(traced.frame, traced.source),
} }
} }
...@@ -507,7 +516,18 @@ export async function getOriginalStackFrames({ ...@@ -507,7 +516,18 @@ export async function getOriginalStackFrames({
reason: 'Failed to create original stack frame', reason: 'Failed to create original stack frame',
} }
} }
return { status: 'fulfilled', value: stackFrame } const originalStackFrame = stackFrame.originalStackFrame
return {
status: 'fulfilled',
value: {
originalStackFrame,
originalCodeFrame:
(originalStackFrame?.ignored ?? true)
? null
: // TODO: Don't get all codeframes of non-ignored frames eagerly.
stackFrame.originalCodeFrame,
},
}
} catch (error) { } catch (error) {
return { return {
status: 'rejected', status: 'rejected',
......
...@@ -254,9 +254,17 @@ export async function createOriginalStackFrame({ ...@@ -254,9 +254,17 @@ export async function createOriginalStackFrame({
ignored, ignored,
} }
/** undefined = not yet computed */
let originalCodeFrame: string | null | undefined
return { return {
originalStackFrame: traced, originalStackFrame: traced,
originalCodeFrame: getOriginalCodeFrame(traced, sourceContent), get originalCodeFrame() {
if (originalCodeFrame === undefined) {
originalCodeFrame = getOriginalCodeFrame(traced, sourceContent)
}
return originalCodeFrame
},
} }
} }
...@@ -530,7 +538,15 @@ async function getOriginalStackFrame({ ...@@ -530,7 +538,15 @@ async function getOriginalStackFrame({
} }
} }
return originalStackFrameResponse const originalStackFrame = originalStackFrameResponse.originalStackFrame
return {
originalStackFrame,
originalCodeFrame:
(originalStackFrame?.ignored ?? true)
? null
: // TODO: Don't get all codeframes of non-ignored frames eagerly.
originalStackFrameResponse.originalCodeFrame,
}
} }
export function getOverlayMiddleware(options: { export function getOverlayMiddleware(options: {
......
...@@ -303,33 +303,27 @@ function getSourcemappedFrameIfPossible( ...@@ -303,33 +303,27 @@ function getSourcemappedFrameIfPossible(
ignored, ignored,
} }
/** undefined = not yet computed*/ /** undefined = not yet computed */
let codeFrame: string | null | undefined let codeFrame: string | null | undefined
return Object.defineProperty( return {
{ stack: originalFrame,
stack: originalFrame, get code() {
code: null, if (codeFrame === undefined) {
const sourceContent: string | null =
sourceMapConsumer.sourceContentFor(
sourcePosition.source,
/* returnNullOnMissing */ true
) ?? null
codeFrame = getOriginalCodeFrame(
originalFrame,
sourceContent,
inspectOptions.colors
)
}
return codeFrame
}, },
'code', }
{
get: () => {
if (codeFrame === undefined) {
const sourceContent: string | null =
sourceMapConsumer.sourceContentFor(
sourcePosition.source,
/* returnNullOnMissing */ true
) ?? null
codeFrame = getOriginalCodeFrame(
originalFrame,
sourceContent,
inspectOptions.colors
)
}
return codeFrame
},
}
)
} }
function parseAndSourceMap( function parseAndSourceMap(
......
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