Replies: 3 comments
-
Probably not what you want since the doc marks it already as the default behaviour, but hx-sync allows you to configure how requests triggered while another one was already in flight, should behave.
If the 2 requests you're describing are happening from the same element AND within a short period of time (i.e. the second one happens before the first one got the response from the server), then hx-sync should match your needs |
Beta Was this translation helpful? Give feedback.
-
I've tried hx-sync but it didn't do anything. The architecture changed a bit in the meantime, but let me show you the logic maybe it helps:
On page load -> dropdown 1 and 2 get loaded in -> after settle trigger retrieve_data (this is where duplicate event happens with the exact same request details). Just to note, that I simplified the above html, in practice we have up to 7 dropdowns that work similarly in the filters div. In the past we used on change trigger retrieve data on the filters dropdown, but it was creating different problem with the request to retrieve data being sent before the dom had actually settled. How would could hx-sync be implemented in this scenario? |
Beta Was this translation helpful? Give feedback.
-
Thank for the sample code! Put it on a JSFiddle to see what's going on, and could indeed observe the duplicate request. Indeed, I tried hx-sync there and it doesn't work, because it seems the second request happens after the first one has already ended. A workaround you could do, is to add a
Check out this JSFiddle, where I've only modified the hx-trigger to You'd have to play with the timing value to match your real setup, I found out 500ms is not enough on the JSFiddle so I put in a whole second in there |
Beta Was this translation helpful? Give feedback.
-
Hi,
Due to the design of our front end architecture/events handling, we are in a position where sometimes duplicate itentical HTMX requests happen consequently. This is fixed with some custom js code that tracks each request being sent and specifically finalRequestPath, not allowing consecutive duplicate events. However, I was wondering if there is a more clever HTMX way to fix this problem?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions