mirror of
https://github.com/facebook/react.git
synced 2026-02-26 02:44:59 +00:00
Basically make `console.error` and `console.warn` behave like normal - when a component stack isn't appended. I need this because I need to be able to print rich logs with the component stack option and to be able to disable instrumentation completely in `console.createTask` environments that don't need it. Currently we can't print logs with richer objects because they're toString:ed first. In practice, pretty much all arguments we log are already toString:ed so it's not necessary anyway. Some might be like a number. So it would only be a problem if some environment can't handle proper consoles but then it's up to that environment to toString it before logging. The `Warning: ` prefix is historic and is both noisy and confusing. It's mostly unnecessary since the UI surrounding `console.error` and `console.warn` tend to have visual treatment around it anyway. However, it's actively misleading when `console.error` gets prefixed with a Warning that we consider an error level. There's an argument to be made that some of our `console.error` don't make the bar for an error but then the argument is to downgrade each of those to `console.warn` - not to brand all our actual error logging with `Warning: `. Apparently something needs to change in React Native before landing this because it depends on the prefix somehow which probably doesn't make sense already.
51 lines
1.7 KiB
JavaScript
51 lines
1.7 KiB
JavaScript
'use strict';
|
|
|
|
module.exports = function shouldIgnoreConsoleError(format, args) {
|
|
if (__DEV__) {
|
|
if (typeof format === 'string') {
|
|
if (
|
|
args[0] != null &&
|
|
((typeof args[0] === 'object' &&
|
|
typeof args[0].message === 'string' &&
|
|
// This specific log has the same signature as error logging.
|
|
// The trick is to get rid of this whole file.
|
|
!format.includes('Failed to serialize an action') &&
|
|
typeof args[0].stack === 'string') ||
|
|
(typeof args[0] === 'string' &&
|
|
args[0].indexOf('An error occurred in ') === 0))
|
|
) {
|
|
// This looks like an error with addendum from ReactFiberErrorLogger.
|
|
// They are noisy too so we'll try to ignore them.
|
|
return true;
|
|
}
|
|
if (
|
|
format.indexOf('ReactDOM.render was removed in React 19') !== -1 ||
|
|
format.indexOf('ReactDOM.hydrate was removed in React 19') !== -1 ||
|
|
format.indexOf(
|
|
'ReactDOM.render has not been supported since React 18',
|
|
) !== -1 ||
|
|
format.indexOf(
|
|
'ReactDOM.hydrate has not been supported since React 18',
|
|
) !== -1 ||
|
|
format.indexOf('react-test-renderer is deprecated.') !== -1
|
|
) {
|
|
// We haven't finished migrating our tests to use createRoot.
|
|
return true;
|
|
}
|
|
}
|
|
} else {
|
|
if (
|
|
format != null &&
|
|
typeof format.message === 'string' &&
|
|
typeof format.stack === 'string' &&
|
|
args.length === 0
|
|
) {
|
|
// In production, ReactFiberErrorLogger logs error objects directly.
|
|
// They are noisy too so we'll try to ignore them.
|
|
return true;
|
|
}
|
|
}
|
|
// Looks legit
|
|
return false;
|
|
};
|