Skip to content

Commit

Permalink
Refactor findHostInstance and findNodeHandle (#12575)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
sebmarkbage committed Apr 10, 2018
1 parent b99d0b1 commit 725c054
Show file tree
Hide file tree
Showing 10 changed files with 446 additions and 484 deletions.
4 changes: 1 addition & 3 deletions packages/react-dom/src/__tests__/findDOMNode-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ describe('findDOMNode', () => {
it('findDOMNode should reject random objects', () => {
expect(function() {
ReactDOM.findDOMNode({foo: 'bar'});
}).toThrowError(
'Element appears to be neither ReactComponent nor DOMNode. Keys: foo',
);
}).toThrowError('Argument appears to not be a ReactComponent. Keys: foo');
});

it('findDOMNode should reject unmounted objects with render func', () => {
Expand Down
15 changes: 1 addition & 14 deletions packages/react-dom/src/client/ReactDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -1147,20 +1147,7 @@ const ReactDOM: Object = {
return (componentOrElement: any);
}

const inst = ReactInstanceMap.get(componentOrElement);
if (inst) {
return DOMRenderer.findHostInstance(inst);
}

if (typeof componentOrElement.render === 'function') {
invariant(false, 'Unable to find node on an unmounted component.');
} else {
invariant(
false,
'Element appears to be neither ReactComponent nor DOMNode. Keys: %s',
Object.keys(componentOrElement),
);
}
return DOMRenderer.findHostInstance(componentOrElement);
},

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

0 comments on commit 725c054

Please sign in to comment.