Skip to content

Commit bb40287

Browse files
authored
[Flight] Pass line/column to filterStackFrame (#33707)
1 parent 9a645e1 commit bb40287

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

packages/react-client/src/__tests__/ReactFlight-test.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,8 @@ describe('ReactFlight', () => {
13091309
// third-party RSC frame
13101310
// Ideally this would be a real frame produced by React not a mocked one.
13111311
' at ThirdParty (rsc://React/ThirdParty/file:///code/%5Broot%2520of%2520the%2520server%5D.js?42:1:1)',
1312+
// We'll later filter this out based on line/column in `filterStackFrame`.
1313+
' at ThirdPartyModule (file:///file-with-index-source-map.js:52656:16374)',
13121314
// host component in parent stack
13131315
' at div (<anonymous>)',
13141316
...originalStackLines.slice(2),
@@ -1357,7 +1359,10 @@ describe('ReactFlight', () => {
13571359
}
13581360
return `digest(${String(x)})`;
13591361
},
1360-
filterStackFrame(filename, functionName) {
1362+
filterStackFrame(filename, functionName, lineNumber, columnNumber) {
1363+
if (lineNumber === 52656 && columnNumber === 16374) {
1364+
return false;
1365+
}
13611366
if (!filename) {
13621367
// Allow anonymous
13631368
return functionName === 'div';
@@ -3682,7 +3687,7 @@ describe('ReactFlight', () => {
36823687
onError(x) {
36833688
return `digest("${x.message}")`;
36843689
},
3685-
filterStackFrame(url, functionName) {
3690+
filterStackFrame(url, functionName, lineNumber, columnNumber) {
36863691
return functionName !== 'intermediate';
36873692
},
36883693
},

packages/react-server/src/ReactFlightServer.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,13 @@ function findCalledFunctionNameFromStackTrace(
204204
const callsite = stack[i];
205205
const functionName = callsite[0];
206206
const url = devirtualizeURL(callsite[1]);
207+
const lineNumber = callsite[2];
208+
const columnNumber = callsite[3];
207209
if (functionName === 'new Promise') {
208210
// Ignore Promise constructors.
209211
} else if (url === 'node:internal/async_hooks') {
210212
// Ignore the stack frames from the async hooks themselves.
211-
} else if (filterStackFrame(url, functionName)) {
213+
} else if (filterStackFrame(url, functionName, lineNumber, columnNumber)) {
212214
if (bestMatch === '') {
213215
// If we had no good stack frames for internal calls, just use the last
214216
// first party function name.
@@ -236,7 +238,9 @@ function filterStackTrace(
236238
const callsite = stack[i];
237239
const functionName = callsite[0];
238240
const url = devirtualizeURL(callsite[1]);
239-
if (filterStackFrame(url, functionName)) {
241+
const lineNumber = callsite[2];
242+
const columnNumber = callsite[3];
243+
if (filterStackFrame(url, functionName, lineNumber, columnNumber)) {
240244
// Use a clone because the Flight protocol isn't yet resilient to deduping
241245
// objects in the debug info. TODO: Support deduping stacks.
242246
const clone: ReactCallSite = (callsite.slice(0): any);
@@ -466,7 +470,12 @@ export type Request = {
466470
// DEV-only
467471
completedDebugChunks: Array<Chunk | BinaryChunk>,
468472
environmentName: () => string,
469-
filterStackFrame: (url: string, functionName: string) => boolean,
473+
filterStackFrame: (
474+
url: string,
475+
functionName: string,
476+
lineNumber: number,
477+
columnNumber: number,
478+
) => boolean,
470479
didWarnForKey: null | WeakSet<ReactComponentInfo>,
471480
writtenDebugObjects: WeakMap<Reference, string>,
472481
deferredDebugObjects: null | DeferredDebugStore,
@@ -2180,7 +2189,14 @@ function visitAsyncNode(
21802189
const callsite = fullStack[firstFrame];
21812190
const functionName = callsite[0];
21822191
const url = devirtualizeURL(callsite[1]);
2183-
isAwaitInUserspace = filterStackFrame(url, functionName);
2192+
const lineNumber = callsite[2];
2193+
const columnNumber = callsite[3];
2194+
isAwaitInUserspace = filterStackFrame(
2195+
url,
2196+
functionName,
2197+
lineNumber,
2198+
columnNumber,
2199+
);
21842200
}
21852201
if (!isAwaitInUserspace) {
21862202
// If this await was fully filtered out, then it was inside third party code

0 commit comments

Comments
 (0)