Temporarily fix EmptyComponents

This a workaround for the problem described in #2770. It should be
temporary because this is really just working around the real problem.
This commit is contained in:
Paul O’Shannessy
2014-12-23 15:33:53 -08:00
parent 3fec78638d
commit b2bf83ec85
2 changed files with 45 additions and 0 deletions
+11
View File
@@ -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() {
@@ -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 <div>hello world</div>;
}
});
var Parent = React.createClass({
update() {
this.forceUpdate();
},
render() {
return (
<div>
<Child key="1" visible={false} />
<Child key="0" visible={true} onMount={this.update} />
<Child key="2" visible={false} />
</div>
);
}
});
expect(function() {
ReactTestUtils.renderIntoDocument(<Parent/>)
}).not.toThrow();
});
});