Skip to content

Commit

Permalink
[Flight] Allow <anonymous> stack frames to be serialized if opt-in (#…
Browse files Browse the repository at this point in the history
…31329)

Normally we filter out stack frames with missing `filename` because they
can be noisy and not ignore listed. However, it's up to the
filterStackFrame function to determine whether to do it. This lets us
match `<anonymous>` stack frames in V8 parsing (they don't have line
numbers).
  • Loading branch information
sebmarkbage authored Oct 23, 2024
1 parent 2dc5beb commit b3e0a11
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/react-client/src/ReactFlightClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -2281,6 +2281,8 @@ function createFakeFunction<T>(
code += '\n//# sourceMappingURL=' + sourceMap;
} else if (filename) {
code += '\n//# sourceURL=' + filename;
} else {
code += '\n//# sourceURL=<anonymous>';
}

let fn: FakeFunction<T>;
Expand Down
19 changes: 17 additions & 2 deletions packages/react-client/src/__tests__/ReactFlight-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,8 @@ describe('ReactFlight', () => {
' at file:///testing.js:42:3',
// async anon function (https://github.com/ChromeDevTools/devtools-frontend/blob/831be28facb4e85de5ee8c1acc4d98dfeda7a73b/test/unittests/front_end/panels/console/ErrorStackParser_test.ts#L130C9-L130C41)
' at async file:///testing.js:42:3',
// host component in parent stack
' at div (<anonymous>)',
...originalStackLines.slice(2),
].join('\n');
throw error;
Expand Down Expand Up @@ -1328,6 +1330,15 @@ describe('ReactFlight', () => {
}
return `digest(${String(x)})`;
},
filterStackFrame(filename, functionName) {
if (!filename) {
// Allow anonymous
return functionName === 'div';
}
return (
!filename.startsWith('node:') && !filename.includes('node_modules')
);
},
});

await act(() => {
Expand Down Expand Up @@ -1355,14 +1366,16 @@ describe('ReactFlight', () => {
' at eval (eval at testFunction (eval at createFakeFunction (**), <anonymous>:1:35)\n' +
' at ServerComponentError (file://~/(some)(really)(exotic-directory)/ReactFlight-test.js:1166:19)\n' +
' at <anonymous> (file:///testing.js:42:3)\n' +
' at <anonymous> (file:///testing.js:42:3)\n',
' at <anonymous> (file:///testing.js:42:3)\n' +
' at div (<anonymous>',
)
: expect.stringContaining(
'Error: This is an error\n' +
' at eval (eval at testFunction (inspected-page.html:29:11), <anonymous>:1:10)\n' +
' at ServerComponentError (file://~/(some)(really)(exotic-directory)/ReactFlight-test.js:1166:19)\n' +
' at file:///testing.js:42:3\n' +
' at file:///testing.js:42:3',
' at file:///testing.js:42:3\n' +
' at div (<anonymous>',
),
digest: 'a dev digest',
environmentName: 'Server',
Expand All @@ -1379,6 +1392,7 @@ describe('ReactFlight', () => {
'Server',
],
['file:///testing.js', 'Server'],
['', 'Server'],
[__filename, 'Server'],
]
: gate(flags => flags.enableServerComponentLogs)
Expand All @@ -1390,6 +1404,7 @@ describe('ReactFlight', () => {
'Server',
],
['file:///testing.js', 'Server'],
['', 'Server'],
]
: [],
});
Expand Down
2 changes: 1 addition & 1 deletion packages/react-server/src/ReactFlightStackConfigV8.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function getStack(error: Error): string {
// at filename:0:0
// at async filename:0:0
const frameRegExp =
/^ {3} at (?:(.+) \((.+):(\d+):(\d+)\)|(?:async )?(.+):(\d+):(\d+))$/;
/^ {3} at (?:(.+) \((?:(.+):(\d+):(\d+)|\<anonymous\>)\)|(?:async )?(.+):(\d+):(\d+)|\<anonymous\>)$/;

export function parseStackTrace(
error: Error,
Expand Down

0 comments on commit b3e0a11

Please sign in to comment.