Skip to content

Commit 1043549

Browse files
authored
fix: apply entering animation synchronously when unmountOnExit or mountOnEnter is enabled (#847)
* fix: apply entering animation synchronously when unmountOnExit or mountOnEnter is enabled * chore: run prettier * chore: remove unused nextTick
1 parent 35fa332 commit 1043549

File tree

4 files changed

+12
-21
lines changed

4 files changed

+12
-21
lines changed

src/CSSTransition.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import React from 'react';
66

77
import Transition from './Transition';
88
import { classNamesShape } from './utils/PropTypes';
9+
import { forceReflow } from './utils/reflow';
910

1011
const addClass = (node, classes) =>
1112
node && classes && classes.split(' ').forEach((c) => addOneClass(node, c));
@@ -194,8 +195,7 @@ class CSSTransition extends React.Component {
194195
// This is to force a repaint,
195196
// which is necessary in order to transition styles when adding a class name.
196197
if (phase === 'active') {
197-
/* eslint-disable no-unused-expressions */
198-
node && node.scrollTop;
198+
if (node) forceReflow(node);
199199
}
200200

201201
if (className) {

src/Transition.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import ReactDOM from 'react-dom';
55
import config from './config';
66
import { timeoutsShape } from './utils/PropTypes';
77
import TransitionGroupContext from './TransitionGroupContext';
8-
import { nextTick } from './utils/nextTick';
8+
import { forceReflow } from './utils/reflow';
99

1010
export const UNMOUNTED = 'unmounted';
1111
export const EXITED = 'exited';
@@ -213,15 +213,16 @@ class Transition extends React.Component {
213213
this.cancelNextCallback();
214214

215215
if (nextStatus === ENTERING) {
216-
// https://github.com/reactjs/react-transition-group/pull/749
217-
// With unmountOnExit or mountOnEnter, the enter animation should happen at the transition between `exited` and `entering`.
218-
// To make the animation happen, we have to separate each rendering and avoid being processed as batched.
219216
if (this.props.unmountOnExit || this.props.mountOnEnter) {
220-
// `exited` -> `entering`
221-
nextTick(() => this.performEnter(mounting));
222-
} else {
223-
this.performEnter(mounting);
217+
const node = this.props.nodeRef
218+
? this.props.nodeRef.current
219+
: ReactDOM.findDOMNode(this);
220+
// https://github.com/reactjs/react-transition-group/pull/749
221+
// With unmountOnExit or mountOnEnter, the enter animation should happen at the transition between `exited` and `entering`.
222+
// To make the animation happen, we have to separate each rendering and avoid being processed as batched.
223+
if (node) forceReflow(node);
224224
}
225+
this.performEnter(mounting);
225226
} else {
226227
this.performExit();
227228
}

src/utils/nextTick.js

-11
This file was deleted.

src/utils/reflow.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const forceReflow = (node) => node.scrollTop;

0 commit comments

Comments
 (0)