Skip to content

Commit

Permalink
Add deprecation warning for findDOMNode
Browse files Browse the repository at this point in the history
This is removed in version 19. We already warned inside of Strict Mode
but this adds the warning everywhere.
  • Loading branch information
acdlite committed Apr 25, 2024
1 parent d4ea75d commit c3b2839
Show file tree
Hide file tree
Showing 2 changed files with 14 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 @@ -238,10 +238,22 @@ function legacyRenderSubtreeIntoContainer(
return getPublicRootInstance(root);
}

let didWarnAboutFindDOMNode = false;

export function findDOMNode(
componentOrElement: Element | ?React$Component<any, any>,
): 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;
Expand Down
3 changes: 2 additions & 1 deletion scripts/jest/shouldIgnoreConsoleError.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c3b2839

Please sign in to comment.