Skip to content

Enter transition breaks when CSSTransition has mountOnEnter and child triggers reflow on componentDidMount #382

@JohnAlbin

Description

@JohnAlbin

Do you want to request a feature or report a bug?

CSSTransition bug using react-transition-group 2.4.0.

What is the current behavior?

The enter transition fails to run, if:

  • using mountOnEnter, and
  • the child of CSSTransition calls a DOM method on componentDidMount() that triggers a reflow of the page (see note below).

Here's the smallest demo of the bug I could manage: https://jsfiddle.net/JohnAlbin/fq8oa109/68/

The demo includes 3 examples.

  1. The first example uses the same CSSTransition properties, HTML structure and CSS as the second example. It shows what the transition is supposed to look like.
  2. The second example is the same as example # 1 but the child element has a componentDidMount(). The transition does not work on enter. (It does work on exit, though.)
  3. The third example is the same as example # 2, but includes the "-enter" class on the child directly instead of having CSSTransition apply it. The transition is now fixed.

You need to press the big "Toggle Transition" button to make all three examples transition at the same time.

Regarding the DOM methods that break the enter transition: Not all DOM methods break it. For example, document.querySelector('body') and document.hasFocus() won't break the transition, but getClientRects() and focus() on DOM elements did break the transition. ¯\_(ツ)_/¯ Not sure why that is. [edit: It's this list of DOM methods that force a reflow that breaks the transition: https://gist.github.com/paulirish/5d52fb081b3570c81e3a ]

What is the expected behavior?

The CSSTransition’s enter transition should work no matter the contents of the element that is being animated.

As shown in the first example of the demo above, the transition should have enter transition that has:

  • a background color that changes from white to purple
  • a position that moves from the left (offscreen) to the right (onscreen)

Which versions, and which browser / OS are affected by this issue?

Breaks in Chrome, Safari, and Firefox on Mac. Probably the same on Windows and Linux.

Did this work in previous versions?

Dunno. This is my first time using react-transition-group on a complex child. You could fork my demo and try old 2.x versions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions