-
Notifications
You must be signed in to change notification settings - Fork 46k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Removing -leave classes in CSSTransitionGroup doesn't work well with alternative batching strategies #2292
Comments
For my use case, I solved it by only removing In the callback instead of these // We differ from original implementation in that we don't want -leave classes
// to be removed here if element is to be removed from DOM anyway, as this
// causes flicker with alternative batching strategies.
// Instead, we only remove `enter` classes in the end callback.
// We will remove `leave` classes only if we're about to `enter` again (see below).
if (animationType === 'enter') {
CSSCore.removeClass(node, className);
CSSCore.removeClass(node, activeClassName);
} Right before // Remove `leave` class if we're about to `enter` again.
// (See rationale above.)
if (animationType === 'enter') {
CSSCore.removeClass(node, this.props.name + '-leave');
CSSCore.removeClass(node, this.props.name + '-leave-active');
} I'm actually using (I hope there's a less hackish solution though!) |
I'm having enough trouble convincing myself that your fix is correct that I don't think I want to take this. If we ever support rAF batching in core, perhaps we will want a fix for this. I'm curious though – what problems does rAF batching solve for you? Does React.addons.batchedUpdates fix the same problems? |
Can you elaborate a bit so I could learn? My line of thought was that there is no real reason to remove I'm using rAF batching for a few very tight spots in my app where I need to update opacity as user scrolls, and it lags terribly without rAF batching. I used to have complicated userland code for rAF but with rAF batching I was able to just use |
The idea sounds good but the code is still tricky, especially for the re-entry case. That makes sense. Have you looked at all at throttling the scroll events instead? That's the typical way to deal with this. You could do something like this if you still want to do it on rAF boundaries:
Basically, rAF batching introduces complexity and makes things harder to reason about (like necessitating your fix here) so we've so far tried to avoid using it. |
I see. Perhaps you're right. When I first wrote that code I wasn't trustring myself to use rAF properly but I think I have a better idea of how to use it now, so I might as well do that (and throttle scrolling). Thanks! |
No problem. Let me know how it goes! |
Hi,
This is probably by design but I wanted to make sure.
I had a problem with using
CSSTransitionGroup
together with RAF batching strategy. I'm aware that RAF batching is not officially supported but it works very well for me and solves quite a few problems in my app so I don't want to give it up.The problem is following:
CSSTransitionGroup
removes-leave
and-leave-active
classes just before callingfinishCallback()
. Is it really necessary to do so?With batching strategy other than default, this may (and does with RAF) result in
-leave
and-leave-active
classes being removed a tick before element is removed from the DOM. Thus the element flickers.If I move these calls behind a condition, transition group behaves just fine:
Am I missing something?
Edit: Indeed, I am missing the situation where I fire another
enter
beforeleave
completes—probably in this case myif
won't work. But still I wish there was a way around this.The text was updated successfully, but these errors were encountered: