Skip to content

Commit d255e1a

Browse files
committed
Add unknown location information to component stacks (#30290)
This is the same change as in #30289 but for the main runtime - e.g. parent stacks in errorInfo.componentStack, appended stacks to console.error coming from React itself and when we add virtual frames to owner stacks. Since we don't add location information these frames look weird to some stack parsers - such as the native one. This is an existing issue when you want to use some off-the-shelf parsers to parse production component stacks for example. While we won't add Error objects to logs ourselves necessarily, some third party could want to do the same thing we do in DevTools and so we should provide the same capability to just take this trace and print it using an Error object. DiffTrain build for [df783f9](df783f9)
1 parent ac28fa9 commit d255e1a

38 files changed

+344
-134
lines changed

compiled/facebook-www/JSXDEVRuntime-dev.classic.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,14 @@ __DEV__ &&
182182
} catch (x) {
183183
var match = x.stack.trim().match(/\n( *(at )?)/);
184184
prefix = (match && match[1]) || "";
185+
suffix =
186+
-1 < x.stack.indexOf("\n at")
187+
? " (<anonymous>)"
188+
: -1 < x.stack.indexOf("@")
189+
? "@unknown:0:0"
190+
: "";
185191
}
186-
return "\n" + prefix + name;
192+
return "\n" + prefix + name + suffix;
187193
}
188194
function describeNativeComponentFrame(fn, construct) {
189195
if (!fn || reentry) return "";
@@ -853,6 +859,7 @@ __DEV__ &&
853859
prevGroupEnd;
854860
disabledLog.__reactDisabledLog = !0;
855861
var prefix,
862+
suffix,
856863
reentry = !1;
857864
var componentFrameCache = new (
858865
"function" === typeof WeakMap ? WeakMap : Map

compiled/facebook-www/JSXDEVRuntime-dev.modern.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,14 @@ __DEV__ &&
182182
} catch (x) {
183183
var match = x.stack.trim().match(/\n( *(at )?)/);
184184
prefix = (match && match[1]) || "";
185+
suffix =
186+
-1 < x.stack.indexOf("\n at")
187+
? " (<anonymous>)"
188+
: -1 < x.stack.indexOf("@")
189+
? "@unknown:0:0"
190+
: "";
185191
}
186-
return "\n" + prefix + name;
192+
return "\n" + prefix + name + suffix;
187193
}
188194
function describeNativeComponentFrame(fn, construct) {
189195
if (!fn || reentry) return "";
@@ -849,6 +855,7 @@ __DEV__ &&
849855
prevGroupEnd;
850856
disabledLog.__reactDisabledLog = !0;
851857
var prefix,
858+
suffix,
852859
reentry = !1;
853860
var componentFrameCache = new (
854861
"function" === typeof WeakMap ? WeakMap : Map

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1b0132c05acabae5aebd32c2cadddfb16bda70bc
1+
df783f9ea1b6f95e05f830602da1de5ffb325d30
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1b0132c05acabae5aebd32c2cadddfb16bda70bc
1+
df783f9ea1b6f95e05f830602da1de5ffb325d30

compiled/facebook-www/React-dev.classic.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,14 @@ __DEV__ &&
268268
} catch (x) {
269269
var match = x.stack.trim().match(/\n( *(at )?)/);
270270
prefix = (match && match[1]) || "";
271+
suffix =
272+
-1 < x.stack.indexOf("\n at")
273+
? " (<anonymous>)"
274+
: -1 < x.stack.indexOf("@")
275+
? "@unknown:0:0"
276+
: "";
271277
}
272-
return "\n" + prefix + name;
278+
return "\n" + prefix + name + suffix;
273279
}
274280
function describeNativeComponentFrame(fn, construct) {
275281
if (!fn || reentry) return "";
@@ -1303,6 +1309,7 @@ __DEV__ &&
13031309
prevGroupEnd;
13041310
disabledLog.__reactDisabledLog = !0;
13051311
var prefix,
1312+
suffix,
13061313
reentry = !1;
13071314
var componentFrameCache = new (
13081315
"function" === typeof WeakMap ? WeakMap : Map
@@ -1991,7 +1998,7 @@ __DEV__ &&
19911998
exports.useTransition = function () {
19921999
return resolveDispatcher().useTransition();
19932000
};
1994-
exports.version = "19.0.0-www-classic-1b0132c05a-20240706";
2001+
exports.version = "19.0.0-www-classic-df783f9ea1-20240708";
19952002
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
19962003
"function" ===
19972004
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/React-dev.modern.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,14 @@ __DEV__ &&
268268
} catch (x) {
269269
var match = x.stack.trim().match(/\n( *(at )?)/);
270270
prefix = (match && match[1]) || "";
271+
suffix =
272+
-1 < x.stack.indexOf("\n at")
273+
? " (<anonymous>)"
274+
: -1 < x.stack.indexOf("@")
275+
? "@unknown:0:0"
276+
: "";
271277
}
272-
return "\n" + prefix + name;
278+
return "\n" + prefix + name + suffix;
273279
}
274280
function describeNativeComponentFrame(fn, construct) {
275281
if (!fn || reentry) return "";
@@ -1299,6 +1305,7 @@ __DEV__ &&
12991305
prevGroupEnd;
13001306
disabledLog.__reactDisabledLog = !0;
13011307
var prefix,
1308+
suffix,
13021309
reentry = !1;
13031310
var componentFrameCache = new (
13041311
"function" === typeof WeakMap ? WeakMap : Map
@@ -1971,7 +1978,7 @@ __DEV__ &&
19711978
exports.useTransition = function () {
19721979
return resolveDispatcher().useTransition();
19731980
};
1974-
exports.version = "19.0.0-www-modern-1b0132c05a-20240706";
1981+
exports.version = "19.0.0-www-modern-df783f9ea1-20240708";
19751982
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
19761983
"function" ===
19771984
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/React-prod.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,4 +669,4 @@ exports.useSyncExternalStore = function (
669669
exports.useTransition = function () {
670670
return ReactSharedInternals.H.useTransition();
671671
};
672-
exports.version = "19.0.0-www-classic-1b0132c05a-20240706";
672+
exports.version = "19.0.0-www-classic-df783f9ea1-20240708";

compiled/facebook-www/React-prod.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,4 +669,4 @@ exports.useSyncExternalStore = function (
669669
exports.useTransition = function () {
670670
return ReactSharedInternals.H.useTransition();
671671
};
672-
exports.version = "19.0.0-www-modern-1b0132c05a-20240706";
672+
exports.version = "19.0.0-www-modern-df783f9ea1-20240708";

compiled/facebook-www/React-profiling.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ exports.useSyncExternalStore = function (
673673
exports.useTransition = function () {
674674
return ReactSharedInternals.H.useTransition();
675675
};
676-
exports.version = "19.0.0-www-classic-1b0132c05a-20240706";
676+
exports.version = "19.0.0-www-classic-df783f9ea1-20240708";
677677
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
678678
"function" ===
679679
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/React-profiling.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ exports.useSyncExternalStore = function (
673673
exports.useTransition = function () {
674674
return ReactSharedInternals.H.useTransition();
675675
};
676-
exports.version = "19.0.0-www-modern-1b0132c05a-20240706";
676+
exports.version = "19.0.0-www-modern-df783f9ea1-20240708";
677677
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
678678
"function" ===
679679
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

0 commit comments

Comments
 (0)