htmx icon indicating copy to clipboard operation
htmx copied to clipboard

tx-trigger="every 1ms"

Open benji-york opened this issue 1 year ago • 5 comments

If I create a range slider like so

<input
  type="range"
  name="value"
  hx-target="#range-value"
  hx-post="/range"
  hx-trigger="every 10ms"
>

I will see a POST every time the slider is moved (rate limited to 10ms), but not once every 10ms.

Also, I will also see a POST every second, even when the range value is not changing.

Is this expected behavior? What am I missing?

Many thanks—and HTMX rocks!

benji-york avatar May 27 '23 19:05 benji-york

I think you are also looking for delay.

https://htmx.org/attributes/hx-trigger/

delay: - a delay will occur before an event triggers a request. If the event is seen again it will reset the delay.

cemrehancavdar avatar May 27 '23 20:05 cemrehancavdar

Thank you @cemrehancavdar for the fast response!

I think you are also looking for delay.

Yes, in a real-world situation, that would be helpful—in this particular case, I am looking for clarification on the noted behavior.

More specifically, I expect 100 requests per second to the endpoint mentioned in hx-post, but instead I see requests at approximately that rate only while the value is changing (when I did not specify changed in hx-trigger).

Oddly, I also see one request every second, when the range control is not changing (with or without changed).

I see clarification as to whether my understanding is incomplete and/or the behavior is unintended.

benji-york avatar May 27 '23 20:05 benji-york

i wonder if the requests are "piling up" because htmx will, by default, only issue one request at a time and will keep one request queued. So the response time also figures in just how quickly the requests will be reissued.

1cg avatar Jun 15 '23 17:06 1cg

sorry, accidentally closed

1cg avatar Jun 15 '23 17:06 1cg

1cg wrote:

i wonder if the requests are "piling up" because htmx will, by default, only issue one request at a time and will keep one request queued. So the response time also figures in just how quickly the requests will be reissued.

Thanks for looking at this!

I don't think the above hypothesis is it, since

I see requests at approximately [the expected] rate [...] while the value is changing

In other words, the request rate is possible, but I don't understand the behavior (and think it's likely a bug).

benji-york avatar Jun 15 '23 18:06 benji-york