Skip to content

Commit

Permalink
Remove developer tool guard for android
Browse files Browse the repository at this point in the history
Summary:
Debugging with not having Metro console.log() working in Venice is inconvenient.

After PeteTheHeat's fixes in diff series D26624224 the ground issues should be gone, so I tried removing the guard for Android and it worked.

The only issue I found is that when connected to Hermes Debugger in Flipper it keeps refreshing (reloading?), I posted here https://fb.workplace.com/groups/2308952995990093/permalink/2899448643607189/, with this found, I think it's a good start to iterate on since there are no crashes and this would help us a lot on Venice debugging.

Changelog:
[Android][Changed] - Remove developer tool guard for android

Reviewed By: PeteTheHeat

Differential Revision: D26779418

fbshipit-source-id: 96bb18771e01a25f84f845833a4f71e70433ef2b
  • Loading branch information
luluwu2032 authored and facebook-github-bot committed Mar 4, 2021
1 parent 542c7cc commit c7d28bc
Showing 1 changed file with 53 additions and 56 deletions.
109 changes: 53 additions & 56 deletions Libraries/Core/setUpDeveloperTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,66 +17,63 @@ declare var console: typeof console & {_isPolyfilled: boolean, ...};
* You can use this module directly, or just require InitializeCore.
*/
if (__DEV__) {
// TODO (T45803484) Enable devtools for bridgeless RN Android.
if (!global.RN$Bridgeless || Platform.OS === 'ios') {
if (!global.__RCTProfileIsProfiling) {
require('./setUpReactDevTools');
if (!global.__RCTProfileIsProfiling) {
require('./setUpReactDevTools');

// Set up inspector
const JSInspector = require('../JSInspector/JSInspector');
JSInspector.registerAgent(require('../JSInspector/NetworkAgent'));
}
// Set up inspector
const JSInspector = require('../JSInspector/JSInspector');
JSInspector.registerAgent(require('../JSInspector/NetworkAgent'));
}

// Note we can't check if console is "native" because it would appear "native" in JSC and Hermes.
// We also can't check any properties that don't exist in the Chrome worker environment.
// So we check a navigator property that's set to a particular value ("Netscape") in all real browsers.
const isLikelyARealBrowser =
global.navigator != null &&
/* _
* | |
* _ __ ___| |_ ___ ___ __ _ _ __ ___
* | '_ \ / _ \ __/ __|/ __/ _` | '_ \ / _ \
* | | | | __/ |_\__ \ (_| (_| | |_) | __/
* |_| |_|\___|\__|___/\___\__,_| .__/ \___|
* | |
* |_|
*/
global.navigator.appName === 'Netscape'; // Any real browser
// Note we can't check if console is "native" because it would appear "native" in JSC and Hermes.
// We also can't check any properties that don't exist in the Chrome worker environment.
// So we check a navigator property that's set to a particular value ("Netscape") in all real browsers.
const isLikelyARealBrowser =
global.navigator != null &&
/* _
* | |
* _ __ ___| |_ ___ ___ __ _ _ __ ___
* | '_ \ / _ \ __/ __|/ __/ _` | '_ \ / _ \
* | | | | __/ |_\__ \ (_| (_| | |_) | __/
* |_| |_|\___|\__|___/\___\__,_| .__/ \___|
* | |
* |_|
*/
global.navigator.appName === 'Netscape'; // Any real browser

if (!Platform.isTesting) {
const HMRClient = require('../Utilities/HMRClient');
if (!Platform.isTesting) {
const HMRClient = require('../Utilities/HMRClient');

if (console._isPolyfilled) {
// We assume full control over the console and send JavaScript logs to Metro.
[
'trace',
'info',
'warn',
'error',
'log',
'group',
'groupCollapsed',
'groupEnd',
'debug',
].forEach(level => {
const originalFunction = console[level];
console[level] = function(...args) {
HMRClient.log(level, args);
originalFunction.apply(console, args);
};
});
} else {
// We assume the environment has a real rich console (like Chrome), and don't hijack it to log to Metro.
// It's likely the developer is using rich console to debug anyway, and hijacking it would
// lose the filenames in console.log calls: https://github.com/facebook/react-native/issues/26788.
HMRClient.log('log', [
`JavaScript logs will appear in your ${
isLikelyARealBrowser ? 'browser' : 'environment'
} console`,
]);
}
if (console._isPolyfilled) {
// We assume full control over the console and send JavaScript logs to Metro.
[
'trace',
'info',
'warn',
'error',
'log',
'group',
'groupCollapsed',
'groupEnd',
'debug',
].forEach(level => {
const originalFunction = console[level];
console[level] = function(...args) {
HMRClient.log(level, args);
originalFunction.apply(console, args);
};
});
} else {
// We assume the environment has a real rich console (like Chrome), and don't hijack it to log to Metro.
// It's likely the developer is using rich console to debug anyway, and hijacking it would
// lose the filenames in console.log calls: https://github.com/facebook/react-native/issues/26788.
HMRClient.log('log', [
`JavaScript logs will appear in your ${
isLikelyARealBrowser ? 'browser' : 'environment'
} console`,
]);
}

require('./setUpReactRefresh');
}

require('./setUpReactRefresh');
}

0 comments on commit c7d28bc

Please sign in to comment.