mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Check that container is a valid DOM element
This commit is contained in:
@@ -511,6 +511,10 @@ var ReactComponent = {
|
||||
container,
|
||||
transaction,
|
||||
shouldReuseMarkup) {
|
||||
invariant(
|
||||
container && container.nodeType === 1,
|
||||
'mountComponentIntoNode(...): Target container is not a DOM element.'
|
||||
);
|
||||
var renderStart = Date.now();
|
||||
var markup = this.mountComponent(rootID, transaction);
|
||||
ReactMount.totalInstantiationTime += (Date.now() - renderStart);
|
||||
|
||||
@@ -35,7 +35,7 @@ var containersByReactRootID = {};
|
||||
* @return {?*} DOM element that may have the reactRoot ID, or null.
|
||||
*/
|
||||
function getReactRootElementInContainer(container) {
|
||||
return container.firstChild;
|
||||
return container && container.firstChild;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,6 +31,24 @@ describe('ReactComponent', function() {
|
||||
reactComponentExpect = require('reactComponentExpect');
|
||||
});
|
||||
|
||||
it('should throw on invalid render targets', function() {
|
||||
var container = document.createElement('div');
|
||||
// jQuery objects are basically arrays; people often pass them in by mistake
|
||||
expect(function() {
|
||||
React.renderComponent(<div></div>, [container]);
|
||||
}).toThrow(
|
||||
'Invariant Violation: mountComponentIntoNode(...): Target container is ' +
|
||||
'not a DOM element.'
|
||||
);
|
||||
|
||||
expect(function() {
|
||||
React.renderComponent(<div></div>, null);
|
||||
}).toThrow(
|
||||
'Invariant Violation: mountComponentIntoNode(...): Target container is ' +
|
||||
'not a DOM element.'
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw when supplying a ref outside of render method', function() {
|
||||
var instance = <div ref="badDiv" />;
|
||||
expect(function() {
|
||||
|
||||
Reference in New Issue
Block a user