diff --git a/src/core/ReactEmptyComponent.js b/src/core/ReactEmptyComponent.js index aed8169754..d40c28d79f 100644 --- a/src/core/ReactEmptyComponent.js +++ b/src/core/ReactEmptyComponent.js @@ -30,10 +30,21 @@ var ReactEmptyComponentInjection = { var ReactEmptyComponentType = function() {}; ReactEmptyComponentType.prototype.componentDidMount = function() { var internalInstance = ReactInstanceMap.get(this); + // TODO: Make sure we run these methods in the correct order, we shouldn't + // need this check. We're going to assume if we're here it means we ran + // componentWillUnmount already so there is no internal instance (it gets + // removed as part of the unmounting process). + if (!internalInstance) { + return; + } registerNullComponentID(internalInstance._rootNodeID); }; ReactEmptyComponentType.prototype.componentWillUnmount = function() { var internalInstance = ReactInstanceMap.get(this); + // TODO: Get rid of this check. See TODO in componentDidMount. + if (!internalInstance) { + return; + } deregisterNullComponentID(internalInstance._rootNodeID); }; ReactEmptyComponentType.prototype.render = function() { diff --git a/src/core/__tests__/ReactEmptyComponent-test.js b/src/core/__tests__/ReactEmptyComponent-test.js index 9882de9e60..962cecdbca 100644 --- a/src/core/__tests__/ReactEmptyComponent-test.js +++ b/src/core/__tests__/ReactEmptyComponent-test.js @@ -231,4 +231,38 @@ describe('ReactEmptyComponent', function() { 'Invariant Violation: React.render(): Invalid component element.' ); }); + + it('does not break when updating during mount', function() { + var Child = React.createClass({ + componentDidMount() { + this.props.onMount && this.props.onMount(); + }, + render() { + if (!this.props.visible) { + return null; + } + + return