From 8a015b68cc060079878e426610e64e86fb328f8d Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Tue, 23 Apr 2024 16:28:14 -0400 Subject: [PATCH] Add deprecation warning for unmountComponentAtNode This should have been deprecated in 18.0 alongside the other legacy DOM APIs like render(). --- packages/react-dom/src/client/ReactDOMLegacy.js | 12 ++++++++++++ scripts/jest/shouldIgnoreConsoleError.js | 4 +++- 2 files changed, 15 insertions(+), 1 deletion(-) 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