The library for web and native user interfaces.
Fix typechecks for isRenderedByReact()
CommitSyncScript committed
Jun 10, 2013 at 16:16 UTC
1be6c592a64ac8c996763b875a80b17c0193b309
3 files changed
+15
-3
src/core/ReactInstanceHandles.js
+6
-2
@@ -154,11 +154,15 @@ var ReactInstanceHandles = {
154
/**
155
* True if the supplied `node` is rendered by React.
156
*
157
- * @param {DOMEventTarget} node DOM Element to check.
157
+ * @param {*} node DOM Element to check.
158
* @return {boolean} True if the DOM Element appears to be rendered by React.
159
- * @private
159
+ * @internal
160
*/
161
isRenderedByReact: function(node) {
162
+ if (node.nodeType !== 1) {
163
+ // Not a DOMElement, therefore not a React component
164
+ return false;
165
+ }
166
var id = getDOMNodeID(node);
167
return id ? id.charAt(0) === SEPARATOR : false;
168
},
src/core/ReactMount.js
+1
-1
@@ -32,7 +32,7 @@ var containersByReactRootID = {};
32
33
/**
34
* @param {DOMElement} container DOM element that may contain a React component
35
- * @return {?DOMElement} DOM element that may have the reactRoot ID, or null.
35
+ * @return {?*} DOM element that may have the reactRoot ID, or null.
36
*/
37
function getReactRootElementInContainer(container) {
38
return container.firstChild;
src/core/__tests__/ReactInstanceHandles-test.js
+8
@@ -312,3 +312,11 @@ describe('ReactInstanceHandles.getReactRootIDFromNodeID', function() {
312
expect(actual).toEqual(expected);
313
});
314
});
315
+
316
+describe('ReactInstanceHandles.isRenderedByReact', function() {
317
+ it('should not crash on text nodes', function() {
318
+ expect(function() {
319
+ ReactInstanceHandles.isRenderedByReact(document.createTextNode('yolo'))
320
+ }).not.toThrow();
321
+ });
322
+});