Allow changing transitionLeave from false to true

Fixes #724.
This commit is contained in:
Ben Alpert
2013-12-27 10:21:12 -07:00
parent f877c6224f
commit 5e6e332d67
2 changed files with 44 additions and 0 deletions
@@ -79,6 +79,15 @@ var ReactTransitionGroup = React.createClass({
enter: this.props.transitionEnter,
onDoneLeaving: this._handleDoneLeaving.bind(this, key)
}, childMapping[key]);
} else {
// If there's no leave transition and the child has been removed from
// the source children list, we want to remove it immediately from the
// _transitionGroupCurrentKeys cache because _handleDoneLeaving won't
// be called. In normal cases, this prevents a small memory leak; in
// the case of switching transitionLeave from false to true, it
// prevents a confusing bug where ReactTransitionableChild.render()
// returns nothing, throwing an error.
delete currentKeys[key];
}
}
@@ -83,6 +83,41 @@ describe('ReactTransitionGroup', function() {
expect(a.getDOMNode().childNodes[1].id).toBe('one');
});
it('should switch transitionLeave from false to true', function() {
var a = React.renderComponent(
<ReactTransitionGroup
transitionName="yolo"
transitionEnter={false}
transitionLeave={false}>
<span key="one" id="one" />
</ReactTransitionGroup>,
container
);
expect(a.getDOMNode().childNodes.length).toBe(1);
React.renderComponent(
<ReactTransitionGroup
transitionName="yolo"
transitionEnter={false}
transitionLeave={false}>
<span key="two" id="two" />
</ReactTransitionGroup>,
container
);
expect(a.getDOMNode().childNodes.length).toBe(1);
React.renderComponent(
<ReactTransitionGroup
transitionName="yolo"
transitionEnter={false}
transitionLeave={true}>
<span key="three" id="three" />
</ReactTransitionGroup>,
container
);
expect(a.getDOMNode().childNodes.length).toBe(2);
expect(a.getDOMNode().childNodes[0].id).toBe('three');
expect(a.getDOMNode().childNodes[1].id).toBe('two');
});
describe('with an undefined child', function () {
it('should fail silently', function () {
React.renderComponent(