Skip to content

Commit c3b2839

Browse files
committed
Add deprecation warning for findDOMNode
This is removed in version 19. We already warned inside of Strict Mode but this adds the warning everywhere.
1 parent d4ea75d commit c3b2839

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

packages/react-dom/src/client/ReactDOMLegacy.js

+12
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,22 @@ function legacyRenderSubtreeIntoContainer(
238238
return getPublicRootInstance(root);
239239
}
240240

241+
let didWarnAboutFindDOMNode = false;
242+
241243
export function findDOMNode(
242244
componentOrElement: Element | ?React$Component<any, any>,
243245
): null | Element | Text {
244246
if (__DEV__) {
247+
if (!didWarnAboutFindDOMNode) {
248+
didWarnAboutFindDOMNode = true;
249+
console.error(
250+
'findDOMNode is deprecated and will be removed in the next major ' +
251+
'release. Instead, add a ref directly to the element you want ' +
252+
'to reference. Learn more about using refs safely here: ' +
253+
'https://reactjs.org/link/strict-mode-find-node',
254+
);
255+
}
256+
245257
const owner = (ReactCurrentOwner.current: any);
246258
if (owner !== null && owner.stateNode !== null) {
247259
const warnedAboutRefsInRender = owner.stateNode._warnedAboutRefsInRender;

scripts/jest/shouldIgnoreConsoleError.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ module.exports = function shouldIgnoreConsoleError(format, args) {
3131
'uses the legacy childContextTypes API which is no longer supported and will be removed'
3232
) !== -1 ||
3333
format.indexOf('ReactDOMTestUtils is deprecated') !== -1 ||
34-
format.indexOf('`ReactDOMTestUtils.act` is deprecated') !== -1
34+
format.indexOf('`ReactDOMTestUtils.act` is deprecated') !== -1 ||
35+
format.indexOf('findDOMNode is deprecated and will be removed') !== -1
3536
) {
3637
// This is a backported warning. In `main`, there's a different warning
3738
// (and it's fully tested). Not going to bother upgrading all the tests

0 commit comments

Comments
 (0)