Skip to content

Commit 725c054

Browse files
authored
Refactor findHostInstance and findNodeHandle (#12575)
* Move findNodeHandle into the renderers and use instantiation This is just like ReactDOM does it. This also lets us get rid of injection for findNodeHandle. Instead I move NativeMethodsMixin and ReactNativeComponent to use instantiation. * Refactor findHostInstance The reconciler shouldn't expose the Fiber data structure. We should pass the component instance to the reconciler, since the reconciler is the thing that is supposed to be instancemap aware. * Fix devtools injection
1 parent b99d0b1 commit 725c054

File tree

10 files changed

+446
-484
lines changed

10 files changed

+446
-484
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ describe('findDOMNode', () => {
6565
it('findDOMNode should reject random objects', () => {
6666
expect(function() {
6767
ReactDOM.findDOMNode({foo: 'bar'});
68-
}).toThrowError(
69-
'Element appears to be neither ReactComponent nor DOMNode. Keys: foo',
70-
);
68+
}).toThrowError('Argument appears to not be a ReactComponent. Keys: foo');
7169
});
7270

7371
it('findDOMNode should reject unmounted objects with render func', () => {

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,20 +1147,7 @@ const ReactDOM: Object = {
11471147
return (componentOrElement: any);
11481148
}
11491149

1150-
const inst = ReactInstanceMap.get(componentOrElement);
1151-
if (inst) {
1152-
return DOMRenderer.findHostInstance(inst);
1153-
}
1154-
1155-
if (typeof componentOrElement.render === 'function') {
1156-
invariant(false, 'Unable to find node on an unmounted component.');
1157-
} else {
1158-
invariant(
1159-
false,
1160-
'Element appears to be neither ReactComponent nor DOMNode. Keys: %s',
1161-
Object.keys(componentOrElement),
1162-
);
1163-
}
1150+
return DOMRenderer.findHostInstance(componentOrElement);
11641151
},
11651152

11661153
hydrate(element: React$Node, container: DOMContainer, callback: ?Function) {

0 commit comments

Comments
 (0)