Skip to content

Commit

Permalink
Merge pull request facebook#5391 from zjjw/transition_timeouts
Browse files Browse the repository at this point in the history
Clear transition timeouts when component unmounts. Fixes facebook#4876
  • Loading branch information
jimfb committed Nov 5, 2015
2 parents 22b8952 + 73b496d commit 59dd7b3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
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();
});
});

0 comments on commit 59dd7b3

Please sign in to comment.