react icon indicating copy to clipboard operation
react copied to clipboard

ReactCSSTransitionGroup leaves DOM nodes with both `leave` and `enter` classes

Open victor-homyakov opened this issue 12 years ago • 26 comments

After sequence of fast changes (add/delete operations) nodes under ReactCSSTransitionGroup are left stuck with classes example-leave example-enter-active example-leave-active. Further state modifications do not change rendered DOM tree. Console has multiple warnings

transition(): tried to perform an animation without an animationend or transitionend event after timeout (5000ms). You should either disable this transition in JS or add a CSS animation/transition. 

Test page: http://jsbin.com/kasurusa/2

  1. Place cursor in input field
  2. Type l then type Backspace very fast
  3. Repeat step 2 few times

Easily reproduces in IE10, but could be also reproduced in Chrome 35.

victor-homyakov avatar Jun 17 '14 16:06 victor-homyakov

Code in ReactCSSTransitionGroupChild sometimes is executed in wrong sequence.

It assumes that independent asynchronous callbacks flushClassNameQueue and endListener are always executed in proper sequence:

  1. transition('leave')

    1.1 CSSCore.addClass(node, 'example-leave')

  2. flushClassNameQueue

    2.1 CSSCore.addClass(this.getDOMNode(), 'example-leave-active')

  3. endListener

    3.1 CSSCore.removeClass(node, 'example-leave'); CSSCore.removeClass(node, 'example-leave-active');

What sometimes happens:

  1. transition('leave')

    1.1 CSSCore.addClass(node, 'example-leave') - initiates CSS transition

  2. endListener - transition is finished

    2.1 CSSCore.removeClass(node, 'example-leave'); CSSCore.removeClass(node, 'example-leave-active');

  3. flushClassNameQueue - only then setTimeout timer fired

    3.1 CSSCore.addClass(this.getDOMNode(), 'example-leave-active')

victor-homyakov avatar Jun 17 '14 17:06 victor-homyakov

@chenglou any updates on this?

shilpan avatar Sep 09 '14 22:09 shilpan

Encountered the same issue =\ @victor-homyakov You found any workaround?

yurynix avatar Sep 23 '14 13:09 yurynix

Manual patching of those places where the classes are added/removed helped to some extent, but not completely. The algorithm of the addon should be rewritten to avoid using both event observers and timeouts simultaneously, but this requires some amount of time. Taking in account other issues easier was not to use this addon at all.

victor-homyakov avatar Sep 23 '14 13:09 victor-homyakov

I have also encountered this issue with multiple DOM objects (20+) listening after a fast sequence of changes.

felixakiragreen avatar Sep 29 '14 17:09 felixakiragreen

I am seeing a similar issue as well. Sometimes, React does not always eliminate the enter and enter-active classes. In this case, transitioning to a different element will result in the former element remaining in the DOM.

lsvx avatar Nov 04 '14 17:11 lsvx

+1 Just have bumped into the same issue.

koistya avatar Dec 07 '14 21:12 koistya

+1 Any chances that it will be fixed?

vmakhaev avatar Dec 08 '14 09:12 vmakhaev

I was able to solve it by tweaking the order of state variables applied to the component's state. E.g.:

this.setState(updateAB) --> this.setState(updateA); this.setState(updateB);

koistya avatar Dec 08 '14 13:12 koistya

I've been running into this issue too. Usually with enter and enter-active not being removed as @lsvx mentioned.

jmarr avatar Dec 13 '14 01:12 jmarr

I just played around with Khan Academy's TimeoutTransitionGroup. I still see animation glitches occur, but the components do get correctly removed, so at least it prevents my app from getting stuck in a broken state.

jmarr avatar Dec 13 '14 02:12 jmarr

I have a similar issue, it happens when changing the cssClass property of an element during his transition.

guillaume86 avatar Dec 15 '14 15:12 guillaume86

+1 getting rid of a nice animation to fix this bug in our code :-/

mfunkie avatar Dec 19 '14 19:12 mfunkie

I tweaked Khan Academy's TimeoutTransitionGroup to avoid another problem. Maybe it also fixes this problem, so give it a try!

Here's my version:

https://gist.github.com/gaearon/f18a33e3bd58275762f4

gaearon avatar Dec 19 '14 20:12 gaearon

+1 breaks all my things. :/

solussd avatar Dec 24 '14 18:12 solussd

Just saw the same issue. React (with addons) v0.12.2.

I have a form that adds things and a table that should list the last 5 things (with animation). If I add many things quickly it will sometimes list more than 5, with the foo-enter and foo-enter-active classes remaining on the surplus elements.

henrik avatar Dec 27 '14 17:12 henrik

+1 I have this sometimes. (take a look at https://github.com/ccoenraets/pageslider-react it might solve some issues)

bitplanets avatar Jan 14 '15 15:01 bitplanets

Same issue here, it does seem to be related to changing the classes on an item that is transitioning. Simply adding another element within the transitioning item and changing classes on that fixes the issue.

tommoor avatar Feb 07 '15 02:02 tommoor

+1

Efimster avatar Feb 17 '15 07:02 Efimster

+1 causing issues on iOS for me.

andrelevi avatar Feb 17 '15 16:02 andrelevi