symfony / ux

Symfony UX initiative: a JavaScript ecosystem for Symfony
https://ux.symfony.com/
MIT License
851 stars 313 forks source link

[LiveComponent] Debounce / Throttle #1248

Closed smnandre closed 6 months ago

smnandre commented 1 year ago

While playing with the LiveComponent for an upcoming demo, I encountered something I could not resolve. There is a "debounce" modifier, but no throttle.

However, if debounce is the "better option" for something like an autocomplete (the more input, the better the choices suggested to the user), for a button, a throttle would be more suitable in my opinion.

Handling "double click submits" in backend code is something that could be tricky.

Is this something we could easily add/implement, or did I misread the documentation? 🙊"

smnandre commented 1 year ago

And i discoverd this page explaining the difference between throttle & debounce with some sweet interactive demo.... really nice ! 🥇

Capture d’écran 2023-11-04 à 22 56 12
weaverryan commented 1 year ago

It should be reasonable to add if we want it. If the main use-case is avoiding double-submits, another option might be to disable a button that is connected to a LiveAction until the request finishes. Turbo, iirc, does that.

smnandre commented 1 year ago

The main problem with that is ... some users may double click slower than the request is handled.

Some users with trackpads may "double click" with up to 500ms... and a great server could answer in 50ms :/

I tried the addAttribute(disabled) but it did not work.

Following your idea, maybe instead of throttle something like "locked" or "frozen" (meaning no other event would be listen/triggerd for a time).. That could be a good generic way to handle this specific use case ?

carsonbot commented 6 months ago

Thank you for this issue. There has not been a lot of activity here for a while. Has this been resolved?