Skip to content

Commit 01fdf1f

Browse files
committed
Add toggle to unpatch global console
1 parent 818c480 commit 01fdf1f

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

packages/react-devtools-shared/src/devtools/views/Settings/DebuggingSettings.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default function DebuggingSettings(_: {||}) {
4646
setEnableDoubleLogging(currentTarget.checked)
4747
}
4848
/>{' '}
49-
Enable double logging
49+
Suppress console during development-only second render pass
5050
</label>
5151
</div>
5252
<div className={styles.Setting}>

packages/react-devtools-shared/src/devtools/views/Settings/SettingsContext.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ function SettingsContextController({
8989
setEnableDoubleLogging,
9090
] = useLocalStorage<boolean>(
9191
LOCAL_STORAGE_SHOULD_ENABLE_DOUBLE_LOGGING,
92-
false,
92+
true,
9393
);
9494

9595
const [

packages/shared/ConsolePatchingDev.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// replaying on render function. This currently only patches the object
1212
// lazily which won't cover if the log function was extracted eagerly.
1313
// We could also eagerly patch the method.
14+
import {canUseDOM} from './ExecutionEnvironment';
1415

1516
let disabledDepth = 0;
1617
let prevLog;
@@ -20,13 +21,16 @@ let prevError;
2021
let prevGroup;
2122
let prevGroupCollapsed;
2223
let prevGroupEnd;
24+
const {
25+
__REACT_DEVTOOLS_ENABLE_DOUBLE_LOGGING__: enableDoubleLogging,
26+
} = canUseDOM ? window : global;
2327

2428
function disabledLog() {}
2529
disabledLog.__reactDisabledLog = true;
2630

2731
export function disableLogs(): void {
2832
if (__DEV__) {
29-
if (disabledDepth === 0) {
33+
if (disabledDepth === 0 && !enableDoubleLogging) {
3034
/* eslint-disable react-internal/no-production-logging */
3135
prevLog = console.log;
3236
prevInfo = console.info;
@@ -61,7 +65,7 @@ export function disableLogs(): void {
6165
export function reenableLogs(): void {
6266
if (__DEV__) {
6367
disabledDepth--;
64-
if (disabledDepth === 0) {
68+
if (disabledDepth === 0 && !enableDoubleLogging) {
6569
/* eslint-disable react-internal/no-production-logging */
6670
const props = {
6771
configurable: true,

0 commit comments

Comments
 (0)