Skip to content

Commit cd81c4a

Browse files
committed
Expose findDOMNode on internals
Exposes `findDOMNode` on internals and updates tests to read from internals
1 parent a1ace9d commit cd81c4a

27 files changed

+135
-79
lines changed

packages/react-dom/index.experimental.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export {
1212
createPortal,
1313
createRoot,
1414
hydrateRoot,
15-
findDOMNode,
1615
flushSync,
1716
hydrate,
1817
render,

packages/react-dom/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export {
1414
createPortal,
1515
createRoot,
1616
hydrateRoot,
17-
findDOMNode,
1817
flushSync,
1918
hydrate,
2019
render,

packages/react-dom/index.stable.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export {
1212
createPortal,
1313
createRoot,
1414
hydrateRoot,
15-
findDOMNode,
1615
flushSync,
1716
hydrate,
1817
render,

packages/react-dom/src/ReactDOMSharedInternals.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* @flow
88
*/
99

10+
import type {FindDOMNodeType} from './client/ReactDOMLegacy.js';
1011
import type {HostDispatcher} from './shared/ReactDOMTypes';
1112

1213
type InternalsType = {
@@ -15,6 +16,7 @@ type InternalsType = {
1516
Dispatcher: {
1617
current: null | HostDispatcher,
1718
},
19+
findDOMNode: null | FindDOMNodeType,
1820
};
1921

2022
const Internals: InternalsType = ({
@@ -23,6 +25,7 @@ const Internals: InternalsType = ({
2325
Dispatcher: {
2426
current: null,
2527
},
28+
findDOMNode: null,
2629
}: any);
2730

2831
export default Internals;

packages/react-dom/src/__tests__/ReactComponentLifeCycle-test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ let ReactDOM;
1616
let ReactDOMClient;
1717
let ReactTestUtils;
1818
let PropTypes;
19+
let findDOMNode;
1920

2021
const clone = function (o) {
2122
return JSON.parse(JSON.stringify(o));
@@ -94,6 +95,8 @@ describe('ReactComponentLifeCycle', () => {
9495

9596
React = require('react');
9697
ReactDOM = require('react-dom');
98+
findDOMNode =
99+
ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.findDOMNode;
97100
ReactDOMClient = require('react-dom/client');
98101
ReactTestUtils = require('react-dom/test-utils');
99102
PropTypes = require('prop-types');
@@ -376,7 +379,7 @@ describe('ReactComponentLifeCycle', () => {
376379
}
377380
render() {
378381
if (this.state.isMounted) {
379-
expect(ReactDOM.findDOMNode(this).tagName).toBe('DIV');
382+
expect(findDOMNode(this).tagName).toBe('DIV');
380383
}
381384
return <div />;
382385
}

packages/react-dom/src/__tests__/ReactDOM-test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
let React;
1313
let ReactDOM;
14+
let findDOMNode;
1415
let ReactDOMClient;
1516
let ReactDOMServer;
1617
let ReactTestUtils;
@@ -21,6 +22,8 @@ describe('ReactDOM', () => {
2122
beforeEach(() => {
2223
React = require('react');
2324
ReactDOM = require('react-dom');
25+
findDOMNode =
26+
ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.findDOMNode;
2427
ReactDOMClient = require('react-dom/client');
2528
ReactDOMServer = require('react-dom/server');
2629
ReactTestUtils = require('react-dom/test-utils');
@@ -420,7 +423,7 @@ describe('ReactDOM', () => {
420423

421424
const instance = ReactTestUtils.renderIntoDocument(<Component />);
422425
const App = () => {
423-
ReactDOM.findDOMNode(instance);
426+
findDOMNode(instance);
424427
return <div />;
425428
};
426429

packages/react-dom/src/__tests__/ReactDOMComponent-test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2035,7 +2035,11 @@ describe('ReactDOMComponent', () => {
20352035

20362036
componentWillUnmount() {
20372037
// Should not throw
2038-
expect(ReactDOM.findDOMNode(this).nodeName).toBe('SPAN');
2038+
expect(
2039+
ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.findDOMNode(
2040+
this,
2041+
).nodeName,
2042+
).toBe('SPAN');
20392043
}
20402044
}
20412045

packages/react-dom/src/__tests__/ReactDOMEventListener-test.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,18 @@ describe('ReactDOMEventListener', () => {
110110
this.setState({clicked: true});
111111
};
112112
componentDidMount() {
113-
expect(ReactDOM.findDOMNode(this)).toBe(container.firstChild);
113+
expect(
114+
ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.findDOMNode(
115+
this,
116+
),
117+
).toBe(container.firstChild);
114118
}
115119
componentDidUpdate() {
116-
expect(ReactDOM.findDOMNode(this)).toBe(container.firstChild);
120+
expect(
121+
ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.findDOMNode(
122+
this,
123+
),
124+
).toBe(container.firstChild);
117125
}
118126
render() {
119127
if (this.state.clicked) {

packages/react-dom/src/__tests__/ReactDOMLegacyFiber-test.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ describe('ReactDOMLegacyFiber', () => {
103103
container,
104104
);
105105

106-
const textNode = ReactDOM.findDOMNode(instance);
106+
const textNode =
107+
ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.findDOMNode(
108+
instance,
109+
);
107110
expect(textNode).toBe(container.firstChild);
108111
expect(textNode.nodeType).toBe(3);
109112
expect(textNode.nodeValue).toBe('foo');
@@ -121,7 +124,10 @@ describe('ReactDOMLegacyFiber', () => {
121124

122125
expect(container.childNodes.length).toBe(2);
123126

124-
const firstNode = ReactDOM.findDOMNode(instance);
127+
const firstNode =
128+
ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.findDOMNode(
129+
instance,
130+
);
125131
expect(firstNode).toBe(container.firstChild);
126132
expect(firstNode.tagName).toBe('DIV');
127133
});
@@ -149,7 +155,10 @@ describe('ReactDOMLegacyFiber', () => {
149155

150156
expect(container.childNodes.length).toBe(2);
151157

152-
const firstNode = ReactDOM.findDOMNode(instance);
158+
const firstNode =
159+
ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.findDOMNode(
160+
instance,
161+
);
153162
expect(firstNode).toBe(container.firstChild);
154163
expect(firstNode.tagName).toBe('DIV');
155164
});
@@ -172,7 +181,10 @@ describe('ReactDOMLegacyFiber', () => {
172181

173182
expect(container.childNodes.length).toBe(2);
174183

175-
const firstNode = ReactDOM.findDOMNode(instance);
184+
const firstNode =
185+
ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.findDOMNode(
186+
instance,
187+
);
176188
expect(firstNode).toBe(container.firstChild);
177189
expect(firstNode.tagName).toBe('DIV');
178190
});
@@ -849,13 +861,19 @@ describe('ReactDOMLegacyFiber', () => {
849861
}
850862

851863
const myNodeA = ReactDOM.render(<MyNode />, container);
852-
const a = ReactDOM.findDOMNode(myNodeA);
864+
const a =
865+
ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.findDOMNode(
866+
myNodeA,
867+
);
853868
expect(a.tagName).toBe('DIV');
854869

855870
const myNodeB = ReactDOM.render(<MyNode flag={true} />, container);
856871
expect(myNodeA === myNodeB).toBe(true);
857872

858-
const b = ReactDOM.findDOMNode(myNodeB);
873+
const b =
874+
ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.findDOMNode(
875+
myNodeB,
876+
);
859877
expect(b.tagName).toBe('SPAN');
860878
});
861879

packages/react-dom/src/__tests__/ReactDOMSuspensePlaceholder-test.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
let React;
1313
let ReactDOM;
14+
let findDOMNode;
1415
let ReactDOMClient;
1516
let Suspense;
1617
let Scheduler;
@@ -23,6 +24,8 @@ describe('ReactDOMSuspensePlaceholder', () => {
2324
beforeEach(() => {
2425
React = require('react');
2526
ReactDOM = require('react-dom');
27+
findDOMNode =
28+
ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.findDOMNode;
2629
ReactDOMClient = require('react-dom/client');
2730
Scheduler = require('scheduler');
2831
act = require('internal-test-utils').act;
@@ -228,11 +231,11 @@ describe('ReactDOMSuspensePlaceholder', () => {
228231
class Child extends React.Component {
229232
componentDidMount() {
230233
log.push('cDM ' + this.props.id);
231-
ReactDOM.findDOMNode(this);
234+
findDOMNode(this);
232235
}
233236
componentDidUpdate() {
234237
log.push('cDU ' + this.props.id);
235-
ReactDOM.findDOMNode(this);
238+
findDOMNode(this);
236239
}
237240
render() {
238241
return 'child';
@@ -287,12 +290,12 @@ describe('ReactDOMSuspensePlaceholder', () => {
287290
class Child extends React.Component {
288291
componentDidMount() {
289292
log.push('cDM');
290-
ReactDOM.findDOMNode(this);
293+
findDOMNode(this);
291294
}
292295

293296
componentDidUpdate() {
294297
log.push('cDU');
295-
ReactDOM.findDOMNode(this);
298+
findDOMNode(this);
296299
}
297300

298301
render() {

0 commit comments

Comments
 (0)