mirror of
https://github.com/facebook/react.git
synced 2026-02-21 19:31:52 +00:00
The forking for `shared/ReactFeatureFlags` doesn't work in the console patches. Since they're already forked, we can import the internal ReactFeatureFlags files directly. Would have caught this in testing a PR sync, but the PR syncs are broken right now.
69 lines
1.7 KiB
JavaScript
69 lines
1.7 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
const {enableRemoveConsolePatches} = require('ReactFeatureFlags');
|
|
|
|
// This refers to a WWW module.
|
|
const warningWWW = require('warning');
|
|
|
|
let suppressWarning = false;
|
|
export function setSuppressWarning(newSuppressWarning) {
|
|
if (enableRemoveConsolePatches) {
|
|
return;
|
|
}
|
|
if (__DEV__) {
|
|
suppressWarning = newSuppressWarning;
|
|
}
|
|
}
|
|
|
|
export function warn(format, ...args) {
|
|
if (enableRemoveConsolePatches) {
|
|
if (__DEV__) {
|
|
console['warn'](format, ...args);
|
|
}
|
|
} else if (__DEV__) {
|
|
if (!suppressWarning) {
|
|
printWarning('warn', format, args);
|
|
}
|
|
}
|
|
}
|
|
|
|
export function error(format, ...args) {
|
|
if (enableRemoveConsolePatches) {
|
|
if (__DEV__) {
|
|
console['error'](format, ...args);
|
|
}
|
|
} else if (__DEV__) {
|
|
if (!suppressWarning) {
|
|
printWarning('error', format, args);
|
|
}
|
|
}
|
|
}
|
|
|
|
function printWarning(level, format, args) {
|
|
if (enableRemoveConsolePatches) {
|
|
return;
|
|
}
|
|
if (__DEV__) {
|
|
const React = require('react');
|
|
const ReactSharedInternals =
|
|
React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
|
|
// Defensive in case this is fired before React is initialized.
|
|
if (ReactSharedInternals != null && ReactSharedInternals.getCurrentStack) {
|
|
const stack = ReactSharedInternals.getCurrentStack();
|
|
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);
|
|
}
|
|
}
|