Skip to content

Commit

Permalink
Add consoleManagedByDevToolsDuringStrictMode feature flag in React Re…
Browse files Browse the repository at this point in the history
…conciler (#22196)
  • Loading branch information
lunaruan authored Sep 1, 2021
1 parent 9fc04ea commit fc40f02
Show file tree
Hide file tree
Showing 13 changed files with 418 additions and 172 deletions.
29 changes: 21 additions & 8 deletions packages/react-reconciler/src/ReactFiberReconciler.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ import {
import getComponentNameFromFiber from 'react-reconciler/src/getComponentNameFromFiber';
import invariant from 'shared/invariant';
import isArray from 'shared/isArray';
import {enableSchedulingProfiler} from 'shared/ReactFeatureFlags';
import {
enableSchedulingProfiler,
consoleManagedByDevToolsDuringStrictMode,
} from 'shared/ReactFeatureFlags';
import ReactSharedInternals from 'shared/ReactSharedInternals';
import {getPublicInstance} from './ReactFiberHostConfig';
import {
Expand Down Expand Up @@ -107,6 +110,7 @@ export {

import * as Scheduler from './Scheduler';
import {setSuppressWarning} from 'shared/consoleWithStackDev';
import {disableLogs, reenableLogs} from 'shared/ConsolePatchingDev';

type OpaqueRoot = FiberRoot;

Expand Down Expand Up @@ -717,14 +721,23 @@ export function getIsStrictModeForDevtools() {
}

export function setIsStrictModeForDevtools(newIsStrictMode: boolean) {
// We're in a test because Scheduler.unstable_yieldValue only exists
// in SchedulerMock. To reduce the noise in strict mode tests,
// suppress warnings and disable scheduler yielding during the double render
if (typeof Scheduler.unstable_yieldValue === 'function') {
Scheduler.unstable_setDisableYieldValue(newIsStrictMode);
setSuppressWarning(newIsStrictMode);
}
isStrictMode = newIsStrictMode;

if (consoleManagedByDevToolsDuringStrictMode) {
// We're in a test because Scheduler.unstable_yieldValue only exists
// in SchedulerMock. To reduce the noise in strict mode tests,
// suppress warnings and disable scheduler yielding during the double render
if (typeof Scheduler.unstable_yieldValue === 'function') {
Scheduler.unstable_setDisableYieldValue(newIsStrictMode);
setSuppressWarning(newIsStrictMode);
}
} else {
if (newIsStrictMode) {
disableLogs();
} else {
reenableLogs();
}
}
}

export function injectIntoDevTools(devToolsConfig: DevToolsConfig): boolean {
Expand Down
29 changes: 21 additions & 8 deletions packages/react-reconciler/src/ReactFiberReconciler.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ import {
import getComponentNameFromFiber from 'react-reconciler/src/getComponentNameFromFiber';
import invariant from 'shared/invariant';
import isArray from 'shared/isArray';
import {enableSchedulingProfiler} from 'shared/ReactFeatureFlags';
import {
enableSchedulingProfiler,
consoleManagedByDevToolsDuringStrictMode,
} from 'shared/ReactFeatureFlags';
import ReactSharedInternals from 'shared/ReactSharedInternals';
import {getPublicInstance} from './ReactFiberHostConfig';
import {
Expand Down Expand Up @@ -107,6 +110,7 @@ export {

import * as Scheduler from './Scheduler';
import {setSuppressWarning} from 'shared/consoleWithStackDev';
import {disableLogs, reenableLogs} from 'shared/ConsolePatchingDev';

type OpaqueRoot = FiberRoot;

Expand Down Expand Up @@ -717,14 +721,23 @@ export function getIsStrictModeForDevtools() {
}

export function setIsStrictModeForDevtools(newIsStrictMode: boolean) {
// We're in a test because Scheduler.unstable_yieldValue only exists
// in SchedulerMock. To reduce the noise in strict mode tests,
// suppress warnings and disable scheduler yielding during the double render
if (typeof Scheduler.unstable_yieldValue === 'function') {
Scheduler.unstable_setDisableYieldValue(newIsStrictMode);
setSuppressWarning(newIsStrictMode);
}
isStrictMode = newIsStrictMode;

if (consoleManagedByDevToolsDuringStrictMode) {
// We're in a test because Scheduler.unstable_yieldValue only exists
// in SchedulerMock. To reduce the noise in strict mode tests,
// suppress warnings and disable scheduler yielding during the double render
if (typeof Scheduler.unstable_yieldValue === 'function') {
Scheduler.unstable_setDisableYieldValue(newIsStrictMode);
setSuppressWarning(newIsStrictMode);
}
} else {
if (newIsStrictMode) {
disableLogs();
} else {
reenableLogs();
}
}
}

export function injectIntoDevTools(devToolsConfig: DevToolsConfig): boolean {
Expand Down
Loading

0 comments on commit fc40f02

Please sign in to comment.