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 &&

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,14 @@ __DEV__ &&
388388
} catch (x) {
389389
var match = x.stack.trim().match(/\n( *(at )?)/);
390390
prefix = (match && match[1]) || "";
391+
suffix =
392+
-1 < x.stack.indexOf("\n at")
393+
? " (<anonymous>)"
394+
: -1 < x.stack.indexOf("@")
395+
? "@unknown:0:0"
396+
: "";
391397
}
392-
return "\n" + prefix + name;
398+
return "\n" + prefix + name + suffix;
393399
}
394400
function describeNativeComponentFrame(fn, construct) {
395401
if (!fn || reentry) return "";
@@ -603,7 +609,7 @@ __DEV__ &&
603609
var JSCompiler_temp_const = info,
604610
env = entry.env;
605611
var JSCompiler_inline_result = describeBuiltInComponentFrame(
606-
entry.name + (env ? " (" + env + ")" : "")
612+
entry.name + (env ? " [" + env + "]" : "")
607613
);
608614
info = JSCompiler_temp_const + JSCompiler_inline_result;
609615
}
@@ -14917,6 +14923,7 @@ __DEV__ &&
1491714923
prevGroupEnd;
1491814924
disabledLog.__reactDisabledLog = !0;
1491914925
var prefix,
14926+
suffix,
1492014927
reentry = !1;
1492114928
var componentFrameCache = new (
1492214929
"function" === typeof WeakMap ? WeakMap : Map
@@ -16934,14 +16941,14 @@ __DEV__ &&
1693416941
scheduleRoot: scheduleRoot,
1693516942
setRefreshHandler: setRefreshHandler,
1693616943
getCurrentFiber: getCurrentFiberForDevTools,
16937-
reconcilerVersion: "19.0.0-www-classic-1b0132c05a-20240706"
16944+
reconcilerVersion: "19.0.0-www-classic-df783f9ea1-20240708"
1693816945
});
1693916946
})({
1694016947
findFiberByHostInstance: function () {
1694116948
return null;
1694216949
},
1694316950
bundleType: 1,
16944-
version: "19.0.0-www-classic-1b0132c05a-20240706",
16951+
version: "19.0.0-www-classic-df783f9ea1-20240708",
1694516952
rendererPackageName: "react-art"
1694616953
});
1694716954
var ClippingRectangle = TYPES.CLIPPING_RECTANGLE,

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,14 @@ __DEV__ &&
385385
} catch (x) {
386386
var match = x.stack.trim().match(/\n( *(at )?)/);
387387
prefix = (match && match[1]) || "";
388+
suffix =
389+
-1 < x.stack.indexOf("\n at")
390+
? " (<anonymous>)"
391+
: -1 < x.stack.indexOf("@")
392+
? "@unknown:0:0"
393+
: "";
388394
}
389-
return "\n" + prefix + name;
395+
return "\n" + prefix + name + suffix;
390396
}
391397
function describeNativeComponentFrame(fn, construct) {
392398
if (!fn || reentry) return "";
@@ -600,7 +606,7 @@ __DEV__ &&
600606
var JSCompiler_temp_const = info,
601607
env = entry.env;
602608
var JSCompiler_inline_result = describeBuiltInComponentFrame(
603-
entry.name + (env ? " (" + env + ")" : "")
609+
entry.name + (env ? " [" + env + "]" : "")
604610
);
605611
info = JSCompiler_temp_const + JSCompiler_inline_result;
606612
}
@@ -14353,6 +14359,7 @@ __DEV__ &&
1435314359
prevGroupEnd;
1435414360
disabledLog.__reactDisabledLog = !0;
1435514361
var prefix,
14362+
suffix,
1435614363
reentry = !1;
1435714364
var componentFrameCache = new (
1435814365
"function" === typeof WeakMap ? WeakMap : Map
@@ -16364,14 +16371,14 @@ __DEV__ &&
1636416371
scheduleRoot: scheduleRoot,
1636516372
setRefreshHandler: setRefreshHandler,
1636616373
getCurrentFiber: getCurrentFiberForDevTools,
16367-
reconcilerVersion: "19.0.0-www-modern-1b0132c05a-20240706"
16374+
reconcilerVersion: "19.0.0-www-modern-df783f9ea1-20240708"
1636816375
});
1636916376
})({
1637016377
findFiberByHostInstance: function () {
1637116378
return null;
1637216379
},
1637316380
bundleType: 1,
16374-
version: "19.0.0-www-modern-1b0132c05a-20240706",
16381+
version: "19.0.0-www-modern-df783f9ea1-20240708",
1637516382
rendererPackageName: "react-art"
1637616383
});
1637716384
var ClippingRectangle = TYPES.CLIPPING_RECTANGLE,

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,16 +243,23 @@ function getComponentNameFromFiber(fiber) {
243243
}
244244
var ReactSharedInternals =
245245
React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,
246-
prefix;
246+
prefix,
247+
suffix;
247248
function describeBuiltInComponentFrame(name) {
248249
if (void 0 === prefix)
249250
try {
250251
throw Error();
251252
} catch (x) {
252253
var match = x.stack.trim().match(/\n( *(at )?)/);
253254
prefix = (match && match[1]) || "";
255+
suffix =
256+
-1 < x.stack.indexOf("\n at")
257+
? " (<anonymous>)"
258+
: -1 < x.stack.indexOf("@")
259+
? "@unknown:0:0"
260+
: "";
254261
}
255-
return "\n" + prefix + name;
262+
return "\n" + prefix + name + suffix;
256263
}
257264
var reentry = !1;
258265
function describeNativeComponentFrame(fn, construct) {
@@ -10711,7 +10718,7 @@ var slice = Array.prototype.slice,
1071110718
return null;
1071210719
},
1071310720
bundleType: 0,
10714-
version: "19.0.0-www-classic-1b0132c05a-20240706",
10721+
version: "19.0.0-www-classic-df783f9ea1-20240708",
1071510722
rendererPackageName: "react-art"
1071610723
};
1071710724
var internals$jscomp$inline_1386 = {
@@ -10742,7 +10749,7 @@ var internals$jscomp$inline_1386 = {
1074210749
scheduleRoot: null,
1074310750
setRefreshHandler: null,
1074410751
getCurrentFiber: null,
10745-
reconcilerVersion: "19.0.0-www-classic-1b0132c05a-20240706"
10752+
reconcilerVersion: "19.0.0-www-classic-df783f9ea1-20240708"
1074610753
};
1074710754
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1074810755
var hook$jscomp$inline_1387 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,23 @@ function getIteratorFn(maybeIterable) {
117117
Symbol.for("react.client.reference");
118118
var ReactSharedInternals =
119119
React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,
120-
prefix;
120+
prefix,
121+
suffix;
121122
function describeBuiltInComponentFrame(name) {
122123
if (void 0 === prefix)
123124
try {
124125
throw Error();
125126
} catch (x) {
126127
var match = x.stack.trim().match(/\n( *(at )?)/);
127128
prefix = (match && match[1]) || "";
129+
suffix =
130+
-1 < x.stack.indexOf("\n at")
131+
? " (<anonymous>)"
132+
: -1 < x.stack.indexOf("@")
133+
? "@unknown:0:0"
134+
: "";
128135
}
129-
return "\n" + prefix + name;
136+
return "\n" + prefix + name + suffix;
130137
}
131138
var reentry = !1;
132139
function describeNativeComponentFrame(fn, construct) {
@@ -10164,7 +10171,7 @@ var slice = Array.prototype.slice,
1016410171
return null;
1016510172
},
1016610173
bundleType: 0,
10167-
version: "19.0.0-www-modern-1b0132c05a-20240706",
10174+
version: "19.0.0-www-modern-df783f9ea1-20240708",
1016810175
rendererPackageName: "react-art"
1016910176
};
1017010177
var internals$jscomp$inline_1372 = {
@@ -10195,7 +10202,7 @@ var internals$jscomp$inline_1372 = {
1019510202
scheduleRoot: null,
1019610203
setRefreshHandler: null,
1019710204
getCurrentFiber: null,
10198-
reconcilerVersion: "19.0.0-www-modern-1b0132c05a-20240706"
10205+
reconcilerVersion: "19.0.0-www-modern-df783f9ea1-20240708"
1019910206
};
1020010207
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1020110208
var hook$jscomp$inline_1373 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

0 commit comments

Comments
 (0)