Skip to content

Commit e2942f2

Browse files
committed
fixed mobxjs#216: findDOMNode might fail with react-test-renderer
1 parent 8310cd1 commit e2942f2

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# MobX-React Changelog
22

3+
### 4.1.3
4+
5+
* Fixed `ReactDOM.findDOMNode` exception when using react-test-runner, #216
6+
37
### 4.1.2
48

59
* Exceptions caught during render are now rethrown with proper stack, fixes #206

src/observer.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,16 @@ export const componentByNodeRegistery = typeof WeakMap !== "undefined" ? new Wea
1818
export const renderReporter = new EventEmitter();
1919

2020
function findDOMNode(component) {
21-
if (ReactDOM)
22-
return ReactDOM.findDOMNode(component);
21+
if (ReactDOM) {
22+
try {
23+
return ReactDOM.findDOMNode(component);
24+
} catch (e) {
25+
// findDOMNode will throw in react-test-renderer, see:
26+
// See https://github.com/mobxjs/mobx-react/issues/216
27+
// Is there a better heuristic?
28+
return null;
29+
}
30+
}
2331
return null;
2432
}
2533

0 commit comments

Comments
 (0)