Skip to content
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

useTransition: out of sync when used multiple times quickly #204

Open
pySilver opened this issue May 11, 2022 · 4 comments
Open

useTransition: out of sync when used multiple times quickly #204

pySilver opened this issue May 11, 2022 · 4 comments

Comments

@pySilver
Copy link

What would be the proper way to handle the situation when leave/enter is called multiple times in a short time window that causes element being out of state? Element is hidden instead of being shown.

Is there a lock or promise cancellation method so I can be sure that final state of an element is correct?

@marcoroth marcoroth changed the title useTransition out of sync when used multiple times quickly useTransition: out of sync when used multiple times quickly Aug 6, 2022
@hms
Copy link

hms commented Sep 12, 2022

I just bumped into this too.

It looks like some transition classes are being left on the target rather than being removed if one cycles the transition too fast. Once that happens, there is no way to recover other than refreshing the page (i.e., follow on requests to transition don't clear the lingering classes from the previous cycle)

@pySilver while ugly, ugly, ugly, I added a cleanup() as the first step in any functions that trigger a transition. The cleanup() basically does a target.classList.remove(...AllOfTheTransitionClasses) which seems to solve for now.

@pySilver
Copy link
Author

@hms I've switched to el-transition which has promise support and had no issues since then.

@marcoroth
Copy link
Member

Is there any chance we can improve this in Stimulus Use as well, so that all people can benefit from it?

@hms
Copy link

hms commented Sep 12, 2022

@marcoroth I hate like hell asking for even more of your help given how much you contribute here and elsewhere, but the JS involved is a little over my head.

I've tried adding useThrottle to my code that triggers a transition with no luck. My cleanup() hack seems to work no matter how hard I push state changes. Part of the problem, at least in my code, is I'm also using useHotKeys -- so I have lots of places in my Stimulus controller where a state change could be asked for -- and it doesn't look like throttling is a solution.

If I can find some time, I can try with el-transition to see if their promise based solution is all we need. If that works, it would suggest a direction for useTransition -- and possibly a bunch of other use* functions.

If I can help, I'm willing to try -- but I'll need you to point me in the right directions given I'll be learning as I go.

Hal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants