Skip to content
This repository has been archived by the owner on Dec 31, 2020. It is now read-only.

Commit

Permalink
fixed #216: findDOMNode might fail with react-test-renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
mweststrate committed Mar 10, 2017
1 parent 8310cd1 commit e2942f2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# MobX-React Changelog

### 4.1.3

* Fixed `ReactDOM.findDOMNode` exception when using react-test-runner, #216

### 4.1.2

* Exceptions caught during render are now rethrown with proper stack, fixes #206
Expand Down
12 changes: 10 additions & 2 deletions src/observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,16 @@ export const componentByNodeRegistery = typeof WeakMap !== "undefined" ? new Wea
export const renderReporter = new EventEmitter();

function findDOMNode(component) {
if (ReactDOM)
return ReactDOM.findDOMNode(component);
if (ReactDOM) {
try {
return ReactDOM.findDOMNode(component);
} catch (e) {
// findDOMNode will throw in react-test-renderer, see:
// See https://github.com/mobxjs/mobx-react/issues/216
// Is there a better heuristic?
return null;
}
}
return null;
}

Expand Down

0 comments on commit e2942f2

Please sign in to comment.