[fix] prevent findNodeHandle throwing on unmounted components

Fix #1097
This commit is contained in:
Nicolas Gallagher
2018-09-09 11:11:18 -07:00
parent f062eded40
commit b56a737d62
2 changed files with 20 additions and 7 deletions
@@ -8,4 +8,15 @@
*/ */
import { findDOMNode } from 'react-dom'; import { findDOMNode } from 'react-dom';
export default findDOMNode;
const findNodeHandle = component => {
let node;
try {
node = findDOMNode(component);
} catch (e) {}
return node;
};
export default findNodeHandle;
@@ -100,6 +100,7 @@ const NativeMethodsMixin = {
return; return;
} }
const node = findNodeHandle(this); const node = findNodeHandle(this);
if (node) {
// Next state is determined by comparison to existing state (in the DOM). // Next state is determined by comparison to existing state (in the DOM).
// Existing state has already gone through i18n transform // Existing state has already gone through i18n transform
const domProps = createDOMProps(null, nativeProps, style => const domProps = createDOMProps(null, nativeProps, style =>
@@ -107,6 +108,7 @@ const NativeMethodsMixin = {
); );
UIManager.updateView(node, domProps, this); UIManager.updateView(node, domProps, this);
} }
}
}; };
export default NativeMethodsMixin; export default NativeMethodsMixin;