diff --git a/packages/react-dom/src/client/ReactDOMLegacy.js b/packages/react-dom/src/client/ReactDOMLegacy.js index af0e35e128bd4..78a8a4ebd767b 100644 --- a/packages/react-dom/src/client/ReactDOMLegacy.js +++ b/packages/react-dom/src/client/ReactDOMLegacy.js @@ -238,10 +238,22 @@ function legacyRenderSubtreeIntoContainer( return getPublicRootInstance(root); } +let didWarnAboutFindDOMNode = false; + export function findDOMNode( componentOrElement: Element | ?React$Component, ): null | Element | Text { if (__DEV__) { + if (!didWarnAboutFindDOMNode) { + didWarnAboutFindDOMNode = true; + console.error( + 'findDOMNode is deprecated and will be removed in the next major ' + + 'release. Instead, add a ref directly to the element you want ' + + 'to reference. Learn more about using refs safely here: ' + + 'https://reactjs.org/link/strict-mode-find-node', + ); + } + const owner = (ReactCurrentOwner.current: any); if (owner !== null && owner.stateNode !== null) { const warnedAboutRefsInRender = owner.stateNode._warnedAboutRefsInRender; diff --git a/scripts/jest/shouldIgnoreConsoleError.js b/scripts/jest/shouldIgnoreConsoleError.js index cbe2cfb6180b6..72c5eba2f9a0c 100644 --- a/scripts/jest/shouldIgnoreConsoleError.js +++ b/scripts/jest/shouldIgnoreConsoleError.js @@ -31,7 +31,8 @@ module.exports = function shouldIgnoreConsoleError(format, args) { 'uses the legacy childContextTypes API which is no longer supported and will be removed' ) !== -1 || format.indexOf('ReactDOMTestUtils is deprecated') !== -1 || - format.indexOf('`ReactDOMTestUtils.act` is deprecated') !== -1 + format.indexOf('`ReactDOMTestUtils.act` is deprecated') !== -1 || + format.indexOf('findDOMNode is deprecated and will be removed') !== -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