mirror of
https://github.com/facebook/react.git
synced 2026-02-24 12:43:00 +00:00
React currently suppress console logs in StrictMode during double rendering. However, this causes a lot of confusion. This PR moves the console suppression logic from React into React Devtools. Now by default, we no longer suppress console logs. Instead, we gray out the logs in console during double render. We also add a setting in React Devtools to allow developers to hide console logs during double render if they choose.
55 lines
1.4 KiB
JavaScript
55 lines
1.4 KiB
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
// This refers to a WWW module.
|
|
const warningWWW = require('warning');
|
|
|
|
let suppressWarning = false;
|
|
export function setSuppressWarning(newSuppressWarning) {
|
|
if (__DEV__) {
|
|
suppressWarning = newSuppressWarning;
|
|
}
|
|
}
|
|
|
|
export function warn(format, ...args) {
|
|
if (__DEV__) {
|
|
if (!suppressWarning) {
|
|
printWarning('warn', format, args);
|
|
}
|
|
}
|
|
}
|
|
|
|
export function error(format, ...args) {
|
|
if (__DEV__) {
|
|
if (!suppressWarning) {
|
|
printWarning('error', format, args);
|
|
}
|
|
}
|
|
}
|
|
|
|
function printWarning(level, format, args) {
|
|
if (__DEV__) {
|
|
const React = require('react');
|
|
const ReactSharedInternals =
|
|
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
// Defensive in case this is fired before React is initialized.
|
|
if (ReactSharedInternals != null) {
|
|
const ReactDebugCurrentFrame =
|
|
ReactSharedInternals.ReactDebugCurrentFrame;
|
|
const stack = ReactDebugCurrentFrame.getStackAddendum();
|
|
if (stack !== '') {
|
|
format += '%s';
|
|
args.push(stack);
|
|
}
|
|
}
|
|
// TODO: don't ignore level and pass it down somewhere too.
|
|
args.unshift(format);
|
|
args.unshift(false);
|
|
warningWWW.apply(null, args);
|
|
}
|
|
}
|