Skip to content

Commit

Permalink
Add unknown location information to component stacks (#30290)
Browse files Browse the repository at this point in the history
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 commit df783f9.
  • Loading branch information
sebmarkbage committed Jul 8, 2024
1 parent 9187f28 commit e99785f
Show file tree
Hide file tree
Showing 16 changed files with 148 additions and 64 deletions.
2 changes: 1 addition & 1 deletion compiled-rn/VERSION_NATIVE_FB
Original file line number Diff line number Diff line change
@@ -1 +1 @@
19.0.0-native-fb-58af67a8f8-20240628
19.0.0-native-fb-df783f9ea1-20240708
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<7755eee04e60a5a5be47a6764dd66aef>>
* @generated SignedSource<<b79bb3a4890e5e05b0b98d095f5ec6a9>>
*/

"use strict";
Expand Down Expand Up @@ -357,8 +357,14 @@ __DEV__ &&
} catch (x) {
var match = x.stack.trim().match(/\n( *(at )?)/);
prefix = (match && match[1]) || "";
suffix =
-1 < x.stack.indexOf("\n at")
? " (<anonymous>)"
: -1 < x.stack.indexOf("@")
? "@unknown:0:0"
: "";
}
return "\n" + prefix + name;
return "\n" + prefix + name + suffix;
}
function describeNativeComponentFrame(fn, construct) {
if (!fn || reentry) return "";
Expand Down Expand Up @@ -572,7 +578,7 @@ __DEV__ &&
var JSCompiler_temp_const = info,
env = entry.env;
var JSCompiler_inline_result = describeBuiltInComponentFrame(
entry.name + (env ? " (" + env + ")" : "")
entry.name + (env ? " [" + env + "]" : "")
);
info = JSCompiler_temp_const + JSCompiler_inline_result;
}
Expand Down Expand Up @@ -13149,6 +13155,7 @@ __DEV__ &&
prevGroupEnd;
disabledLog.__reactDisabledLog = !0;
var prefix,
suffix,
reentry = !1;
var componentFrameCache = new (
"function" === typeof WeakMap ? WeakMap : Map
Expand Down Expand Up @@ -15072,14 +15079,14 @@ __DEV__ &&
scheduleRoot: scheduleRoot,
setRefreshHandler: setRefreshHandler,
getCurrentFiber: getCurrentFiberForDevTools,
reconcilerVersion: "19.0.0-native-fb-58af67a8f8-20240628"
reconcilerVersion: "19.0.0-native-fb-df783f9ea1-20240708"
});
})({
findFiberByHostInstance: function () {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 1,
version: "19.0.0-native-fb-58af67a8f8-20240628",
version: "19.0.0-native-fb-df783f9ea1-20240708",
rendererPackageName: "react-test-renderer"
});
exports._Scheduler = Scheduler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<a230f61eab876a1bf3f5a22ff087160a>>
* @generated SignedSource<<9dcd7685e1640c17fbdf82a52a452035>>
*/

"use strict";
Expand Down Expand Up @@ -167,16 +167,23 @@ function getComponentNameFromFiber(fiber) {
}
var ReactSharedInternals =
React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,
prefix;
prefix,
suffix;
function describeBuiltInComponentFrame(name) {
if (void 0 === prefix)
try {
throw Error();
} catch (x) {
var match = x.stack.trim().match(/\n( *(at )?)/);
prefix = (match && match[1]) || "";
suffix =
-1 < x.stack.indexOf("\n at")
? " (<anonymous>)"
: -1 < x.stack.indexOf("@")
? "@unknown:0:0"
: "";
}
return "\n" + prefix + name;
return "\n" + prefix + name + suffix;
}
var reentry = !1;
function describeNativeComponentFrame(fn, construct) {
Expand Down Expand Up @@ -9377,7 +9384,7 @@ var devToolsConfig$jscomp$inline_1053 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "19.0.0-native-fb-58af67a8f8-20240628",
version: "19.0.0-native-fb-df783f9ea1-20240708",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1240 = {
Expand Down Expand Up @@ -9408,7 +9415,7 @@ var internals$jscomp$inline_1240 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "19.0.0-native-fb-58af67a8f8-20240628"
reconcilerVersion: "19.0.0-native-fb-df783f9ea1-20240708"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1241 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<8b0fcf879d182dc10c942f445a24f780>>
* @generated SignedSource<<661fb6132400bc6cbf49596db0acc720>>
*/

"use strict";
Expand Down Expand Up @@ -167,16 +167,23 @@ function getComponentNameFromFiber(fiber) {
}
var ReactSharedInternals =
React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,
prefix;
prefix,
suffix;
function describeBuiltInComponentFrame(name) {
if (void 0 === prefix)
try {
throw Error();
} catch (x) {
var match = x.stack.trim().match(/\n( *(at )?)/);
prefix = (match && match[1]) || "";
suffix =
-1 < x.stack.indexOf("\n at")
? " (<anonymous>)"
: -1 < x.stack.indexOf("@")
? "@unknown:0:0"
: "";
}
return "\n" + prefix + name;
return "\n" + prefix + name + suffix;
}
var reentry = !1;
function describeNativeComponentFrame(fn, construct) {
Expand Down Expand Up @@ -9997,7 +10004,7 @@ var devToolsConfig$jscomp$inline_1136 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "19.0.0-native-fb-58af67a8f8-20240628",
version: "19.0.0-native-fb-df783f9ea1-20240708",
rendererPackageName: "react-test-renderer"
};
(function (internals) {
Expand Down Expand Up @@ -10041,7 +10048,7 @@ var devToolsConfig$jscomp$inline_1136 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "19.0.0-native-fb-58af67a8f8-20240628"
reconcilerVersion: "19.0.0-native-fb-df783f9ea1-20240708"
});
exports._Scheduler = Scheduler;
exports.act = act;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<a7dfd81316b971431720d69e9f261fbf>>
* @generated SignedSource<<2e4bfe3b6770b799c0ba60be06b0baca>>
*/

"use strict";
Expand Down Expand Up @@ -165,8 +165,14 @@ __DEV__ &&
} catch (x) {
var match = x.stack.trim().match(/\n( *(at )?)/);
prefix = (match && match[1]) || "";
suffix =
-1 < x.stack.indexOf("\n at")
? " (<anonymous>)"
: -1 < x.stack.indexOf("@")
? "@unknown:0:0"
: "";
}
return "\n" + prefix + name;
return "\n" + prefix + name + suffix;
}
function describeNativeComponentFrame(fn, construct) {
if (!fn || reentry) return "";
Expand Down Expand Up @@ -670,6 +676,7 @@ __DEV__ &&
prevGroupEnd;
disabledLog.__reactDisabledLog = !0;
var prefix,
suffix,
reentry = !1;
var componentFrameCache = new (
"function" === typeof WeakMap ? WeakMap : Map
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<1e831dc318079da75149235e0e09d92d>>
* @generated SignedSource<<7ad8e11753e71d86731728e561f85039>>
*/

"use strict";
Expand Down Expand Up @@ -165,8 +165,14 @@ __DEV__ &&
} catch (x) {
var match = x.stack.trim().match(/\n( *(at )?)/);
prefix = (match && match[1]) || "";
suffix =
-1 < x.stack.indexOf("\n at")
? " (<anonymous>)"
: -1 < x.stack.indexOf("@")
? "@unknown:0:0"
: "";
}
return "\n" + prefix + name;
return "\n" + prefix + name + suffix;
}
function describeNativeComponentFrame(fn, construct) {
if (!fn || reentry) return "";
Expand Down Expand Up @@ -670,6 +676,7 @@ __DEV__ &&
prevGroupEnd;
disabledLog.__reactDisabledLog = !0;
var prefix,
suffix,
reentry = !1;
var componentFrameCache = new (
"function" === typeof WeakMap ? WeakMap : Map
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<63806b4788513932e73deffcc14466b6>>
* @generated SignedSource<<eee457cdc760bc83f6841edabd786565>>
*/

"use strict";
Expand Down Expand Up @@ -245,8 +245,14 @@ __DEV__ &&
} catch (x) {
var match = x.stack.trim().match(/\n( *(at )?)/);
prefix = (match && match[1]) || "";
suffix =
-1 < x.stack.indexOf("\n at")
? " (<anonymous>)"
: -1 < x.stack.indexOf("@")
? "@unknown:0:0"
: "";
}
return "\n" + prefix + name;
return "\n" + prefix + name + suffix;
}
function describeNativeComponentFrame(fn, construct) {
if (!fn || reentry) return "";
Expand Down Expand Up @@ -1125,6 +1131,7 @@ __DEV__ &&
prevGroupEnd;
disabledLog.__reactDisabledLog = !0;
var prefix,
suffix,
reentry = !1;
var componentFrameCache = new (
"function" === typeof WeakMap ? WeakMap : Map
Expand Down Expand Up @@ -1741,7 +1748,7 @@ __DEV__ &&
exports.useTransition = function () {
return resolveDispatcher().useTransition();
};
exports.version = "19.0.0-native-fb-58af67a8f8-20240628";
exports.version = "19.0.0-native-fb-df783f9ea1-20240708";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<6e39ee5928417fc3a4496375cf39d2ca>>
* @generated SignedSource<<7c12730813cc8752d34681669dee99a2>>
*/

"use strict";
Expand Down Expand Up @@ -604,4 +604,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-native-fb-58af67a8f8-20240628";
exports.version = "19.0.0-native-fb-df783f9ea1-20240708";
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<507175890e1729117769a5cffe8b37a0>>
* @generated SignedSource<<157ac3b6e8ae340940bc85ec2c3806cc>>
*/

"use strict";
Expand Down Expand Up @@ -608,7 +608,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-native-fb-58af67a8f8-20240628";
exports.version = "19.0.0-native-fb-df783f9ea1-20240708";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
58af67a8f8761e56b5d02486a304c96edc547760
df783f9ea1b6f95e05f830602da1de5ffb325d30
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<b26df307c5e29739cf9da04a9ae90101>>
* @generated SignedSource<<cb3e48516a63e1d432c10d2a36d40a98>>
*/

"use strict";
Expand Down Expand Up @@ -225,8 +225,14 @@ __DEV__ &&
} catch (x) {
var match = x.stack.trim().match(/\n( *(at )?)/);
prefix = (match && match[1]) || "";
suffix =
-1 < x.stack.indexOf("\n at")
? " (<anonymous>)"
: -1 < x.stack.indexOf("@")
? "@unknown:0:0"
: "";
}
return "\n" + prefix + name;
return "\n" + prefix + name + suffix;
}
function describeNativeComponentFrame(fn, construct) {
if (!fn || reentry) return "";
Expand Down Expand Up @@ -440,7 +446,7 @@ __DEV__ &&
var JSCompiler_temp_const = info,
env = entry.env;
var JSCompiler_inline_result = describeBuiltInComponentFrame(
entry.name + (env ? " (" + env + ")" : "")
entry.name + (env ? " [" + env + "]" : "")
);
info = JSCompiler_temp_const + JSCompiler_inline_result;
}
Expand Down Expand Up @@ -14163,6 +14169,7 @@ __DEV__ &&
prevGroupEnd;
disabledLog.__reactDisabledLog = !0;
var prefix,
suffix,
reentry = !1;
var componentFrameCache = new (
"function" === typeof WeakMap ? WeakMap : Map
Expand Down Expand Up @@ -16679,12 +16686,12 @@ __DEV__ &&
scheduleRoot: scheduleRoot,
setRefreshHandler: setRefreshHandler,
getCurrentFiber: getCurrentFiberForDevTools,
reconcilerVersion: "19.0.0-native-fb-58af67a8f8-20240628"
reconcilerVersion: "19.0.0-native-fb-df783f9ea1-20240708"
});
})({
findFiberByHostInstance: getInstanceFromNode,
bundleType: 1,
version: "19.0.0-native-fb-58af67a8f8-20240628",
version: "19.0.0-native-fb-df783f9ea1-20240708",
rendererPackageName: "react-native-renderer",
rendererConfig: {
getInspectorDataForInstance: getInspectorDataForInstance,
Expand Down
Loading

0 comments on commit e99785f

Please sign in to comment.