Skip to content

Commit

Permalink
Add deprecation warning for unmountComponentAtNode
Browse files Browse the repository at this point in the history
This should have been deprecated in 18.0 alongside the other legacy
DOM APIs like render().
  • Loading branch information
acdlite committed Apr 25, 2024
1 parent c3b2839 commit 8a015b6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 12 additions & 0 deletions packages/react-dom/src/client/ReactDOMLegacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down
4 changes: 3 additions & 1 deletion scripts/jest/shouldIgnoreConsoleError.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8a015b6

Please sign in to comment.