diff --git a/packages/react-dom/src/client/ReactDOMLegacy.js b/packages/react-dom/src/client/ReactDOMLegacy.js index 78a8a4ebd767b..21878d4cb7f55 100644 --- a/packages/react-dom/src/client/ReactDOMLegacy.js +++ b/packages/react-dom/src/client/ReactDOMLegacy.js @@ -393,7 +393,19 @@ export function unstable_renderSubtreeIntoContainer( ); } +let didWarnAboutUnmountComponentAtNode = false; export function unmountComponentAtNode(container: Container) { + if (__DEV__) { + if (!didWarnAboutUnmountComponentAtNode) { + didWarnAboutUnmountComponentAtNode = true; + console.error( + 'unmountComponentAtNode is deprecated and will be removed in the ' + + 'next major release. Switch to the createRoot API. Learn ' + + 'more: https://reactjs.org/link/switch-to-createroot', + ); + } + } + if (!isValidContainerLegacy(container)) { throw new Error( 'unmountComponentAtNode(...): Target container is not a DOM element.', diff --git a/scripts/jest/shouldIgnoreConsoleError.js b/scripts/jest/shouldIgnoreConsoleError.js index 72c5eba2f9a0c..aad2e35258aba 100644 --- a/scripts/jest/shouldIgnoreConsoleError.js +++ b/scripts/jest/shouldIgnoreConsoleError.js @@ -32,7 +32,9 @@ module.exports = function shouldIgnoreConsoleError(format, args) { ) !== -1 || format.indexOf('ReactDOMTestUtils is deprecated') !== -1 || format.indexOf('`ReactDOMTestUtils.act` is deprecated') !== -1 || - format.indexOf('findDOMNode is deprecated and will be removed') !== -1 + format.indexOf('findDOMNode is deprecated and will be removed') !== + -1 || + format.indexOf('unmountComponentAtNode is deprecated') !== -1 ) { // This is a backported warning. In `main`, there's a different warning // (and it's fully tested). Not going to bother upgrading all the tests