Files
react/scripts/jest/shouldIgnoreConsoleError.js
Sebastian Markbåge 4b8dfd6215 Move Hydration Warnings from the DOM Config into the Fiber reconciliation (#28476)
Stacked on #28458.

This doesn't actually really change the messages yet, it's just a
refactor.

Hydration warnings can be presented either as HTML or React JSX format.
If presented as HTML it makes more sense to make that a DOM specific
concept, however, I think it's actually better to present it in terms of
React JSX.

Most of the time the errors aren't going to be something messing with
them at the HTML/HTTP layer. It's because the JS code does something
different. Most of the time you're working in just React. People don't
necessarily even know what the HTML form of it looks like. So this takes
the approach that the warnings are presented in React JSX in their rich
object form.

Therefore, I'm moving the approach to yield diff data to the reconciler
but it's the reconciler that's actually printing all the warnings.
2024-03-26 19:04:18 -04:00

57 lines
1.6 KiB
JavaScript

'use strict';
module.exports = function shouldIgnoreConsoleError(
format,
args,
{TODO_ignoreHydrationErrors} = {TODO_ignoreHydrationErrors: false}
) {
if (__DEV__) {
if (typeof format === 'string') {
if (
args[0] != null &&
typeof args[0].message === 'string' &&
typeof args[0].stack === 'string'
) {
// 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
) {
// We haven't finished migrating our tests to use createRoot.
return true;
}
if (
TODO_ignoreHydrationErrors &&
format.indexOf(
'An error occurred during hydration. The server HTML was replaced with client content'
) !== -1
) {
// This also gets logged by onRecoverableError, so we can ignore it.
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;
};