Skip to content

Commit 31cf6a7

Browse files
motiz88facebook-github-bot
authored andcommitted
Use Metro support for auto-collapsing internal stack frames (#25839)
Summary: Pull Request resolved: #25839 Changes `ExceptionsManager` to respect the `collapse` field in each symbolicated stack frame returned from Metro, in preference to the client-side regex. This is ultimately driven by a Metro config option (now also set in the RN new project template). Note that the client-side regex is intentionally ignored for any frame where `collapse` is present ( = all of them if using the latest Metro). Also updates the client-side regex to match the new renderer paths. This is part of a redesign of work done originally in #24662; we will eventually remove the client-side regex from RN. Reviewed By: cpojer Differential Revision: D16500277 fbshipit-source-id: 557f93129d334b719200dc8603cc2345ffb45102
1 parent 59db059 commit 31cf6a7

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

Libraries/Core/ExceptionsManager.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212

1313
import type {ExtendedError} from './Devtools/parseErrorStack';
1414

15+
// NOTE: Deprecated in favor of driving this from the symbolication endpoint
16+
// instead.
17+
// See Metro config option `symbolicator.customizeFrame`.
1518
const INTERNAL_CALLSITES_REGEX = new RegExp(
1619
[
17-
'/Libraries/Renderer/oss/ReactNativeRenderer-dev\\.js$',
20+
'/Libraries/Renderer/implementations/.+\\.js$',
1821
'/Libraries/BatchedBridge/MessageQueue\\.js$',
1922
].join('|'),
2023
);
@@ -50,11 +53,15 @@ function reportException(e: ExtendedError, isFatal: boolean) {
5053
symbolicateStackTrace(stack)
5154
.then(prettyStack => {
5255
if (prettyStack) {
53-
const stackWithoutInternalCallsites = prettyStack.filter(
54-
frame =>
56+
const stackWithoutInternalCallsites = prettyStack.filter(frame => {
57+
if (typeof frame.collapse === 'boolean') {
58+
return !frame.collapse;
59+
}
60+
return (
5561
frame.file &&
56-
frame.file.match(INTERNAL_CALLSITES_REGEX) === null,
57-
);
62+
frame.file.match(INTERNAL_CALLSITES_REGEX) === null
63+
);
64+
});
5865
NativeExceptionsManager.updateExceptionMessage(
5966
message,
6067
stackWithoutInternalCallsites,

Libraries/Core/NativeExceptionsManager.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export type StackFrame = {|
1818
file: string,
1919
lineNumber: number,
2020
methodName: string,
21+
collapse?: boolean,
2122
|};
2223

2324
export type ExceptionData = {

Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,7 @@ namespace JS {
912912
NSString *file() const;
913913
double lineNumber() const;
914914
NSString *methodName() const;
915+
folly::Optional<bool> collapse() const;
915916

916917
StackFrame(NSDictionary *const v) : _v(v) {}
917918
private:
@@ -2649,6 +2650,11 @@ inline NSString *JS::NativeExceptionsManager::StackFrame::methodName() const
26492650
id const p = _v[@"methodName"];
26502651
return RCTBridgingToString(p);
26512652
}
2653+
inline folly::Optional<bool> JS::NativeExceptionsManager::StackFrame::collapse() const
2654+
{
2655+
id const p = _v[@"collapse"];
2656+
return RCTBridgingToOptionalBool(p);
2657+
}
26522658

26532659
inline NSString *JS::NativeExceptionsManager::ExceptionData::message() const
26542660
{

template/metro.config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,22 @@
55
* @format
66
*/
77

8+
const INTERNAL_CALLSITES_REGEX = new RegExp(
9+
[
10+
'/Libraries/Renderer/implementations/.+\\.js$',
11+
'/Libraries/BatchedBridge/MessageQueue\\.js$',
12+
].join('|'),
13+
);
14+
815
module.exports = {
16+
symbolicator: {
17+
customizeFrame: frame => {
18+
const collapse = Boolean(
19+
frame.file && INTERNAL_CALLSITES_REGEX.test(frame.file),
20+
);
21+
return {collapse};
22+
},
23+
},
924
transformer: {
1025
getTransformOptions: async () => ({
1126
transform: {

0 commit comments

Comments
 (0)