bigskysoftware / htmx-extensions

164 stars 50 forks source link

Do not emit htmx events when preloading requests #91

Open meln1k opened 2 months ago

meln1k commented 2 months ago

As discussed on #90, here is a change to make prefetch hx-get request side-effect free.

netlify[bot] commented 2 months ago

Deploy Preview for htmx-extensions canceled.

Name Link
Latest commit 87758436460f28c14976da8983f195abf1ad2b17
Latest deploy log https://app.netlify.com/sites/htmx-extensions/deploys/66ec6ce4bcb1d100088ffe76
Telroshan commented 2 months ago

Hey, could you remove the formatting changes to make the overall diff more readable and easier to review? Thanks!

meln1k commented 2 months ago

@Telroshan done!

marisst commented 1 week ago

I have fixed this issue in https://github.com/bigskysoftware/htmx-extensions/pull/106, since I was receiving two comments about it there. I have used @meln1k solution as a foundation and implemented @Telroshan idea to reuse the xhr generated by htmx.ajax() and null the HTMX callbacks. Additionally, I am triggering the process in what I believe is a more rigid way to avoid bugs. Instead of attaching prefetchEventHandler to all preloaded node in the loading function, I make the extension listen to all htmx:beforeRequest events and check for those which include "HX-Preload": "true" header. I hope you like it!