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 [df783f9](df783f9)
  • Loading branch information
sebmarkbage committed Jul 8, 2024
1 parent ac28fa9 commit d255e1a
Show file tree
Hide file tree
Showing 38 changed files with 344 additions and 134 deletions.
9 changes: 8 additions & 1 deletion compiled/facebook-www/JSXDEVRuntime-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,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 @@ -853,6 +859,7 @@ __DEV__ &&
prevGroupEnd;
disabledLog.__reactDisabledLog = !0;
var prefix,
suffix,
reentry = !1;
var componentFrameCache = new (
"function" === typeof WeakMap ? WeakMap : Map
Expand Down
9 changes: 8 additions & 1 deletion compiled/facebook-www/JSXDEVRuntime-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,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 @@ -849,6 +855,7 @@ __DEV__ &&
prevGroupEnd;
disabledLog.__reactDisabledLog = !0;
var prefix,
suffix,
reentry = !1;
var componentFrameCache = new (
"function" === typeof WeakMap ? WeakMap : Map
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1b0132c05acabae5aebd32c2cadddfb16bda70bc
df783f9ea1b6f95e05f830602da1de5ffb325d30
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION_TRANSFORMS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1b0132c05acabae5aebd32c2cadddfb16bda70bc
df783f9ea1b6f95e05f830602da1de5ffb325d30
11 changes: 9 additions & 2 deletions compiled/facebook-www/React-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,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 @@ -1303,6 +1309,7 @@ __DEV__ &&
prevGroupEnd;
disabledLog.__reactDisabledLog = !0;
var prefix,
suffix,
reentry = !1;
var componentFrameCache = new (
"function" === typeof WeakMap ? WeakMap : Map
Expand Down Expand Up @@ -1991,7 +1998,7 @@ __DEV__ &&
exports.useTransition = function () {
return resolveDispatcher().useTransition();
};
exports.version = "19.0.0-www-classic-1b0132c05a-20240706";
exports.version = "19.0.0-www-classic-df783f9ea1-20240708";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
11 changes: 9 additions & 2 deletions compiled/facebook-www/React-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,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 @@ -1299,6 +1305,7 @@ __DEV__ &&
prevGroupEnd;
disabledLog.__reactDisabledLog = !0;
var prefix,
suffix,
reentry = !1;
var componentFrameCache = new (
"function" === typeof WeakMap ? WeakMap : Map
Expand Down Expand Up @@ -1971,7 +1978,7 @@ __DEV__ &&
exports.useTransition = function () {
return resolveDispatcher().useTransition();
};
exports.version = "19.0.0-www-modern-1b0132c05a-20240706";
exports.version = "19.0.0-www-modern-df783f9ea1-20240708";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -669,4 +669,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-www-classic-1b0132c05a-20240706";
exports.version = "19.0.0-www-classic-df783f9ea1-20240708";
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -669,4 +669,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-www-modern-1b0132c05a-20240706";
exports.version = "19.0.0-www-modern-df783f9ea1-20240708";
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-profiling.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-www-classic-1b0132c05a-20240706";
exports.version = "19.0.0-www-classic-df783f9ea1-20240708";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-profiling.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-www-modern-1b0132c05a-20240706";
exports.version = "19.0.0-www-modern-df783f9ea1-20240708";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
15 changes: 11 additions & 4 deletions compiled/facebook-www/ReactART-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,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 @@ -603,7 +609,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 @@ -14917,6 +14923,7 @@ __DEV__ &&
prevGroupEnd;
disabledLog.__reactDisabledLog = !0;
var prefix,
suffix,
reentry = !1;
var componentFrameCache = new (
"function" === typeof WeakMap ? WeakMap : Map
Expand Down Expand Up @@ -16934,14 +16941,14 @@ __DEV__ &&
scheduleRoot: scheduleRoot,
setRefreshHandler: setRefreshHandler,
getCurrentFiber: getCurrentFiberForDevTools,
reconcilerVersion: "19.0.0-www-classic-1b0132c05a-20240706"
reconcilerVersion: "19.0.0-www-classic-df783f9ea1-20240708"
});
})({
findFiberByHostInstance: function () {
return null;
},
bundleType: 1,
version: "19.0.0-www-classic-1b0132c05a-20240706",
version: "19.0.0-www-classic-df783f9ea1-20240708",
rendererPackageName: "react-art"
});
var ClippingRectangle = TYPES.CLIPPING_RECTANGLE,
Expand Down
15 changes: 11 additions & 4 deletions compiled/facebook-www/ReactART-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,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 @@ -600,7 +606,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 @@ -14353,6 +14359,7 @@ __DEV__ &&
prevGroupEnd;
disabledLog.__reactDisabledLog = !0;
var prefix,
suffix,
reentry = !1;
var componentFrameCache = new (
"function" === typeof WeakMap ? WeakMap : Map
Expand Down Expand Up @@ -16364,14 +16371,14 @@ __DEV__ &&
scheduleRoot: scheduleRoot,
setRefreshHandler: setRefreshHandler,
getCurrentFiber: getCurrentFiberForDevTools,
reconcilerVersion: "19.0.0-www-modern-1b0132c05a-20240706"
reconcilerVersion: "19.0.0-www-modern-df783f9ea1-20240708"
});
})({
findFiberByHostInstance: function () {
return null;
},
bundleType: 1,
version: "19.0.0-www-modern-1b0132c05a-20240706",
version: "19.0.0-www-modern-df783f9ea1-20240708",
rendererPackageName: "react-art"
});
var ClippingRectangle = TYPES.CLIPPING_RECTANGLE,
Expand Down
15 changes: 11 additions & 4 deletions compiled/facebook-www/ReactART-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,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 @@ -10711,7 +10718,7 @@ var slice = Array.prototype.slice,
return null;
},
bundleType: 0,
version: "19.0.0-www-classic-1b0132c05a-20240706",
version: "19.0.0-www-classic-df783f9ea1-20240708",
rendererPackageName: "react-art"
};
var internals$jscomp$inline_1386 = {
Expand Down Expand Up @@ -10742,7 +10749,7 @@ var internals$jscomp$inline_1386 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "19.0.0-www-classic-1b0132c05a-20240706"
reconcilerVersion: "19.0.0-www-classic-df783f9ea1-20240708"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1387 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
15 changes: 11 additions & 4 deletions compiled/facebook-www/ReactART-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,23 @@ function getIteratorFn(maybeIterable) {
Symbol.for("react.client.reference");
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 @@ -10164,7 +10171,7 @@ var slice = Array.prototype.slice,
return null;
},
bundleType: 0,
version: "19.0.0-www-modern-1b0132c05a-20240706",
version: "19.0.0-www-modern-df783f9ea1-20240708",
rendererPackageName: "react-art"
};
var internals$jscomp$inline_1372 = {
Expand Down Expand Up @@ -10195,7 +10202,7 @@ var internals$jscomp$inline_1372 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "19.0.0-www-modern-1b0132c05a-20240706"
reconcilerVersion: "19.0.0-www-modern-df783f9ea1-20240708"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1373 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Loading

0 comments on commit d255e1a

Please sign in to comment.