Skip to content

Commit 59c4102

Browse files
committed
Avoid silencing transition when this.state.nextChild exists
1 parent b277790 commit 59c4102

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/ReactCSSTransitionReplace.jsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ export default class ReactCSSTransitionReplace extends React.Component {
101101
const nextChild = nextProps.children ? React.Children.only(nextProps.children) : false
102102
const currentChild = this.state.currentChild
103103

104-
if (currentChild && nextChild && nextChild.key === currentChild.key) {
104+
// Avoid silencing the transition when this.state.nextChild exists because it means that there’s
105+
// already a transition ongoing that has to be replaced.
106+
if (currentChild && nextChild && nextChild.key === currentChild.key && !this.state.nextChild) {
105107
// Nothing changed, but we are re-rendering so update the currentChild.
106108
return this.setState({
107109
currentChild: nextChild,
@@ -117,9 +119,10 @@ export default class ReactCSSTransitionReplace extends React.Component {
117119

118120
const {state } = this
119121

120-
// When transitionLeave is set to false, it might happen that current component is not yet
121-
// rendered when a new component reaches this part of the code. At this point we want to
122-
// use the height and width of the latest rendered elment.
122+
// When transitionLeave is set to false, refs.curr does not exist when refs.next is being
123+
// transitioned into existence. When another child is set for this component at the point
124+
// where only refs.next exists, we want to use the width/height of refs.next instead of
125+
// refs.curr.
123126
const ref = this.refs.curr || this.refs.next
124127

125128
// Set the next child to start the transition, and set the current height.

0 commit comments

Comments
 (0)