Skip to content

Commit fc40f02

Browse files
authored
Add consoleManagedByDevToolsDuringStrictMode feature flag in React Reconciler (#22196)
1 parent 9fc04ea commit fc40f02

13 files changed

+418
-172
lines changed

packages/react-reconciler/src/ReactFiberReconciler.new.js

+21-8
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ import {
3535
import getComponentNameFromFiber from 'react-reconciler/src/getComponentNameFromFiber';
3636
import invariant from 'shared/invariant';
3737
import isArray from 'shared/isArray';
38-
import {enableSchedulingProfiler} from 'shared/ReactFeatureFlags';
38+
import {
39+
enableSchedulingProfiler,
40+
consoleManagedByDevToolsDuringStrictMode,
41+
} from 'shared/ReactFeatureFlags';
3942
import ReactSharedInternals from 'shared/ReactSharedInternals';
4043
import {getPublicInstance} from './ReactFiberHostConfig';
4144
import {
@@ -107,6 +110,7 @@ export {
107110

108111
import * as Scheduler from './Scheduler';
109112
import {setSuppressWarning} from 'shared/consoleWithStackDev';
113+
import {disableLogs, reenableLogs} from 'shared/ConsolePatchingDev';
110114

111115
type OpaqueRoot = FiberRoot;
112116

@@ -717,14 +721,23 @@ export function getIsStrictModeForDevtools() {
717721
}
718722

719723
export function setIsStrictModeForDevtools(newIsStrictMode: boolean) {
720-
// We're in a test because Scheduler.unstable_yieldValue only exists
721-
// in SchedulerMock. To reduce the noise in strict mode tests,
722-
// suppress warnings and disable scheduler yielding during the double render
723-
if (typeof Scheduler.unstable_yieldValue === 'function') {
724-
Scheduler.unstable_setDisableYieldValue(newIsStrictMode);
725-
setSuppressWarning(newIsStrictMode);
726-
}
727724
isStrictMode = newIsStrictMode;
725+
726+
if (consoleManagedByDevToolsDuringStrictMode) {
727+
// We're in a test because Scheduler.unstable_yieldValue only exists
728+
// in SchedulerMock. To reduce the noise in strict mode tests,
729+
// suppress warnings and disable scheduler yielding during the double render
730+
if (typeof Scheduler.unstable_yieldValue === 'function') {
731+
Scheduler.unstable_setDisableYieldValue(newIsStrictMode);
732+
setSuppressWarning(newIsStrictMode);
733+
}
734+
} else {
735+
if (newIsStrictMode) {
736+
disableLogs();
737+
} else {
738+
reenableLogs();
739+
}
740+
}
728741
}
729742

730743
export function injectIntoDevTools(devToolsConfig: DevToolsConfig): boolean {

packages/react-reconciler/src/ReactFiberReconciler.old.js

+21-8
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ import {
3535
import getComponentNameFromFiber from 'react-reconciler/src/getComponentNameFromFiber';
3636
import invariant from 'shared/invariant';
3737
import isArray from 'shared/isArray';
38-
import {enableSchedulingProfiler} from 'shared/ReactFeatureFlags';
38+
import {
39+
enableSchedulingProfiler,
40+
consoleManagedByDevToolsDuringStrictMode,
41+
} from 'shared/ReactFeatureFlags';
3942
import ReactSharedInternals from 'shared/ReactSharedInternals';
4043
import {getPublicInstance} from './ReactFiberHostConfig';
4144
import {
@@ -107,6 +110,7 @@ export {
107110

108111
import * as Scheduler from './Scheduler';
109112
import {setSuppressWarning} from 'shared/consoleWithStackDev';
113+
import {disableLogs, reenableLogs} from 'shared/ConsolePatchingDev';
110114

111115
type OpaqueRoot = FiberRoot;
112116

@@ -717,14 +721,23 @@ export function getIsStrictModeForDevtools() {
717721
}
718722

719723
export function setIsStrictModeForDevtools(newIsStrictMode: boolean) {
720-
// We're in a test because Scheduler.unstable_yieldValue only exists
721-
// in SchedulerMock. To reduce the noise in strict mode tests,
722-
// suppress warnings and disable scheduler yielding during the double render
723-
if (typeof Scheduler.unstable_yieldValue === 'function') {
724-
Scheduler.unstable_setDisableYieldValue(newIsStrictMode);
725-
setSuppressWarning(newIsStrictMode);
726-
}
727724
isStrictMode = newIsStrictMode;
725+
726+
if (consoleManagedByDevToolsDuringStrictMode) {
727+
// We're in a test because Scheduler.unstable_yieldValue only exists
728+
// in SchedulerMock. To reduce the noise in strict mode tests,
729+
// suppress warnings and disable scheduler yielding during the double render
730+
if (typeof Scheduler.unstable_yieldValue === 'function') {
731+
Scheduler.unstable_setDisableYieldValue(newIsStrictMode);
732+
setSuppressWarning(newIsStrictMode);
733+
}
734+
} else {
735+
if (newIsStrictMode) {
736+
disableLogs();
737+
} else {
738+
reenableLogs();
739+
}
740+
}
728741
}
729742

730743
export function injectIntoDevTools(devToolsConfig: DevToolsConfig): boolean {

0 commit comments

Comments
 (0)