Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow changing transitionLeave from false to true #728

Merged
merged 1 commit into from
Dec 27, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/addons/transitions/ReactTransitionGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}

Expand Down
35 changes: 35 additions & 0 deletions src/addons/transitions/__tests__/ReactTransitionGroup-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down