Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/addons/transitions/ReactCSSTransitionGroupChild.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ var ReactCSSTransitionGroupChild = React.createClass({
if (userSpecifiedDelay) {
// Clean-up the animation after the specified delay
timeout = setTimeout(endListener, userSpecifiedDelay);
this.transitionTimeouts.push(timeout);
} else {
// DEPRECATED: this listener will be removed in a future version of react
ReactTransitionEvents.addEndEventListener(node, endListener);
Expand All @@ -126,12 +127,16 @@ var ReactCSSTransitionGroupChild = React.createClass({

componentWillMount: function() {
this.classNameQueue = [];
this.transitionTimeouts = [];
},

componentWillUnmount: function() {
if (this.timeout) {
clearTimeout(this.timeout);
}
this.transitionTimeouts.forEach(function(timeout) {
clearTimeout(timeout);
});
},

componentWillAppear: function(done) {
Expand Down
22 changes: 22 additions & 0 deletions src/addons/transitions/__tests__/ReactCSSTransitionGroup-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,26 @@ describe('ReactCSSTransitionGroup', function() {
var leavingNode = ReactDOM.findDOMNode(a).childNodes[0];
expect(CSSCore.hasClass(leavingNode, 'custom-leaving')).toBe(true);
});

it('should clear transition timeouts when unmounted', function() {
var Component = React.createClass({
render: function() {
return (
<ReactCSSTransitionGroup
transitionName="yolo"
transitionEnterTimeout={500}>
{this.props.children}
</ReactCSSTransitionGroup>
);
},
});

ReactDOM.render(<Component/>, container);
ReactDOM.render(<Component><span key="yolo" id="yolo"/></Component>, container);

ReactDOM.unmountComponentAtNode(container);

// Testing that no exception is thrown here, as the timeout has been cleared.
jest.runAllTimers();
});
});