Skip to content

Commit

Permalink
Switch to binding the console with badging instead of calling it dire…
Browse files Browse the repository at this point in the history
…ctly (#30461)

This is a major nit but this avoids an extra stack frame when we're
replaying logs.

Normally the `printToConsole` frame doesn't show up because it'd be
ignore listed.

<img width="421" alt="Screenshot 2024-07-25 at 11 49 39 AM"
src="https://github.com/user-attachments/assets/81334c2f-e19e-476a-871e-c4db9dee294e">

When you expand to show ignore listed frames a ton of other frames show
up.

<img width="516" alt="Screenshot 2024-07-25 at 11 49 47 AM"
src="https://github.com/user-attachments/assets/2ab8bdfb-464c-408d-9176-ee2fabc114b6">

The annoying thing about this frame is that it's at the top of the stack
where as typically framework stuff ends up at the bottom and something
you can ignore. The user space stack comes first.

With this fix there's no longer any `printToConsole` frame.

<img width="590" alt="Screenshot 2024-07-25 at 12 09 09 PM"
src="https://github.com/user-attachments/assets/b8365d53-31f3-43df-abce-172d608d3c9c">

Am I wiling to eat the added complexity and slightly slower performance
for this nit? Definitely.

DiffTrain build for commit e8df0cf.
  • Loading branch information
sebmarkbage committed Jul 25, 2024
1 parent 4609b0b commit f902e21
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 60 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-14a4699f-20240725
19.0.0-native-fb-e8df0cf9-20240725
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<f9399cb065edf5442d1eee766d19ca1e>>
* @generated SignedSource<<98ac9676f8d7a74c7c8caff92163b015>>
*/

"use strict";
Expand Down Expand Up @@ -1102,23 +1102,23 @@ __DEV__ &&
child = parentInstance.children.indexOf(child);
parentInstance.children.splice(child, 1);
}
function printToConsole(methodName, args, badgeName) {
function bindToConsole(methodName, args, badgeName) {
var offset = 0;
switch (methodName) {
case "dir":
case "dirxml":
case "groupEnd":
case "table":
console[methodName].apply(console, args);
return;
return bind.apply(console[methodName], [console].concat(args));
case "assert":
offset = 1;
}
args = args.slice(0);
"string" === typeof args[offset]
? args.splice(offset, 1, "[%s] " + args[offset], " " + badgeName + " ")
: args.splice(offset, 0, "[%s] ", " " + badgeName + " ");
console[methodName].apply(console, args);
args.unshift(console);
return bind.apply(console[methodName], args);
}
function createCursor(defaultValue) {
return { current: defaultValue };
Expand Down Expand Up @@ -5502,7 +5502,7 @@ __DEV__ &&
"object" === typeof error$1 &&
null !== error$1 &&
"string" === typeof error$1.environmentName
? printToConsole(
? bindToConsole(
"error",
[
"%o\n\n%s\n\n%s\n",
Expand All @@ -5511,7 +5511,7 @@ __DEV__ &&
recreateMessage
],
error$1.environmentName
)
)()
: error$jscomp$0(
"%o\n\n%s\n\n%s\n",
error$1,
Expand Down Expand Up @@ -13142,6 +13142,7 @@ __DEV__ &&
appendChildToContainer = appendChild,
insertInContainerBefore = insertBefore,
removeChildFromContainer = removeChild,
bind = Function.prototype.bind,
valueStack = [];
var fiberStack = [];
var index$jscomp$0 = -1;
Expand Down Expand Up @@ -15117,14 +15118,14 @@ __DEV__ &&
scheduleRoot: scheduleRoot,
setRefreshHandler: setRefreshHandler,
getCurrentFiber: getCurrentFiberForDevTools,
reconcilerVersion: "19.0.0-native-fb-14a4699f-20240725"
reconcilerVersion: "19.0.0-native-fb-e8df0cf9-20240725"
});
})({
findFiberByHostInstance: function () {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 1,
version: "19.0.0-native-fb-14a4699f-20240725",
version: "19.0.0-native-fb-e8df0cf9-20240725",
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<<eeda2335f11ef85ccbd49c18671110ee>>
* @generated SignedSource<<e4df5caa5d2ad2b1d87e2155ae1307df>>
*/

"use strict";
Expand Down Expand Up @@ -9328,7 +9328,7 @@ var devToolsConfig$jscomp$inline_1035 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "19.0.0-native-fb-14a4699f-20240725",
version: "19.0.0-native-fb-e8df0cf9-20240725",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1211 = {
Expand Down Expand Up @@ -9359,7 +9359,7 @@ var internals$jscomp$inline_1211 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "19.0.0-native-fb-14a4699f-20240725"
reconcilerVersion: "19.0.0-native-fb-e8df0cf9-20240725"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1212 = __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<<866410222c049479f0ced248f85b5afd>>
* @generated SignedSource<<7183b18d6271bf4f860edfb728d037e6>>
*/

"use strict";
Expand Down Expand Up @@ -9952,7 +9952,7 @@ var devToolsConfig$jscomp$inline_1119 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "19.0.0-native-fb-14a4699f-20240725",
version: "19.0.0-native-fb-e8df0cf9-20240725",
rendererPackageName: "react-test-renderer"
};
(function (internals) {
Expand Down Expand Up @@ -9996,7 +9996,7 @@ var devToolsConfig$jscomp$inline_1119 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "19.0.0-native-fb-14a4699f-20240725"
reconcilerVersion: "19.0.0-native-fb-e8df0cf9-20240725"
});
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<<12d77382367d15fcee6da70361208e5c>>
* @generated SignedSource<<2361bda7ee812079297a128e1ca9b170>>
*/

"use strict";
Expand Down Expand Up @@ -1701,7 +1701,7 @@ __DEV__ &&
exports.useTransition = function () {
return resolveDispatcher().useTransition();
};
exports.version = "19.0.0-native-fb-14a4699f-20240725";
exports.version = "19.0.0-native-fb-e8df0cf9-20240725";
"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<<6b48cfd703c9f1aca729a8d96b4961f0>>
* @generated SignedSource<<b19a14166bb831f0c1cd2f999b0fc34b>>
*/

"use strict";
Expand Down Expand Up @@ -576,4 +576,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-native-fb-14a4699f-20240725";
exports.version = "19.0.0-native-fb-e8df0cf9-20240725";
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<6c568ee97d8f132e27587080bf466246>>
* @generated SignedSource<<4a75b879479f7ea594492fdfb6cdfc6c>>
*/

"use strict";
Expand Down Expand Up @@ -580,7 +580,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-native-fb-14a4699f-20240725";
exports.version = "19.0.0-native-fb-e8df0cf9-20240725";
"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 @@
14a4699ff173936a30ec453f7b94d47105bbb252
e8df0cf9f7c7f641192f19841db9bf34b6a0abf7
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<8ca97b6b640a79df906c09e2bb4e588a>>
* @generated SignedSource<<2dce248ab8a579e879df9ff05ebd2bd8>>
*/

"use strict";
Expand Down Expand Up @@ -2013,23 +2013,23 @@ __DEV__ &&
}
return !1;
}
function printToConsole(methodName, args, badgeName) {
function bindToConsole(methodName, args, badgeName) {
var offset = 0;
switch (methodName) {
case "dir":
case "dirxml":
case "groupEnd":
case "table":
console[methodName].apply(console, args);
return;
return bind.apply(console[methodName], [console].concat(args));
case "assert":
offset = 1;
}
args = args.slice(0);
"string" === typeof args[offset]
? args.splice(offset, 1, "[%s] " + args[offset], " " + badgeName + " ")
: args.splice(offset, 0, "[%s] ", " " + badgeName + " ");
console[methodName].apply(console, args);
args.unshift(console);
return bind.apply(console[methodName], args);
}
function createCursor(defaultValue) {
return { current: defaultValue };
Expand Down Expand Up @@ -6490,7 +6490,7 @@ __DEV__ &&
"object" === typeof error$1 &&
null !== error$1 &&
"string" === typeof error$1.environmentName
? printToConsole(
? bindToConsole(
"error",
[
"%o\n\n%s\n\n%s\n",
Expand All @@ -6499,7 +6499,7 @@ __DEV__ &&
recreateMessage
],
error$1.environmentName
)
)()
: error$jscomp$0(
"%o\n\n%s\n\n%s\n",
error$1,
Expand Down Expand Up @@ -14848,7 +14848,8 @@ __DEV__ &&
);
}
});
var valueStack = [];
var bind = Function.prototype.bind,
valueStack = [];
var fiberStack = [];
var index$jscomp$0 = -1;
var warnedAboutMissingGetChildContext = {};
Expand Down Expand Up @@ -16723,12 +16724,12 @@ __DEV__ &&
scheduleRoot: scheduleRoot,
setRefreshHandler: setRefreshHandler,
getCurrentFiber: getCurrentFiberForDevTools,
reconcilerVersion: "19.0.0-native-fb-14a4699f-20240725"
reconcilerVersion: "19.0.0-native-fb-e8df0cf9-20240725"
});
})({
findFiberByHostInstance: getInstanceFromNode,
bundleType: 1,
version: "19.0.0-native-fb-14a4699f-20240725",
version: "19.0.0-native-fb-e8df0cf9-20240725",
rendererPackageName: "react-native-renderer",
rendererConfig: {
getInspectorDataForInstance: getInspectorDataForInstance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<a7172b99cf59d998da1e4bf8ffb9b764>>
* @generated SignedSource<<ac7dc069b2a1224a1f7fd1216583739a>>
*/

"use strict";
Expand Down Expand Up @@ -10550,7 +10550,7 @@ var roots = new Map(),
devToolsConfig$jscomp$inline_1138 = {
findFiberByHostInstance: getInstanceFromNode,
bundleType: 0,
version: "19.0.0-native-fb-14a4699f-20240725",
version: "19.0.0-native-fb-e8df0cf9-20240725",
rendererPackageName: "react-native-renderer",
rendererConfig: {
getInspectorDataForInstance: getInspectorDataForInstance,
Expand Down Expand Up @@ -10593,7 +10593,7 @@ var internals$jscomp$inline_1352 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "19.0.0-native-fb-14a4699f-20240725"
reconcilerVersion: "19.0.0-native-fb-e8df0cf9-20240725"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1353 = __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<<ba0fca74cfa043ddd5644b5721012ca0>>
* @generated SignedSource<<16c03bf8f92344a478f9519951e7f47b>>
*/

"use strict";
Expand Down Expand Up @@ -11264,7 +11264,7 @@ var roots = new Map(),
devToolsConfig$jscomp$inline_1220 = {
findFiberByHostInstance: getInstanceFromNode,
bundleType: 0,
version: "19.0.0-native-fb-14a4699f-20240725",
version: "19.0.0-native-fb-e8df0cf9-20240725",
rendererPackageName: "react-native-renderer",
rendererConfig: {
getInspectorDataForInstance: getInspectorDataForInstance,
Expand Down Expand Up @@ -11320,7 +11320,7 @@ var roots = new Map(),
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "19.0.0-native-fb-14a4699f-20240725"
reconcilerVersion: "19.0.0-native-fb-e8df0cf9-20240725"
});
exports.createPortal = function (children, containerTag) {
return createPortal$1(
Expand Down
Loading

0 comments on commit f902e21

Please sign in to comment.