freezing-waitress-26396
10/11/2022, 1:23 PMboundless-vase-80440
10/11/2022, 1:54 PMminiature-lizard-24702
10/11/2022, 2:31 PMgorgeous-airport-54386
10/11/2022, 2:32 PMminiature-lizard-24702
10/11/2022, 2:32 PMminiature-lizard-24702
10/11/2022, 2:32 PMminiature-lizard-24702
10/11/2022, 2:32 PMgorgeous-airport-54386
10/11/2022, 2:33 PMmysterious-toddler-20573
10/11/2022, 4:48 PMlate-king-98305
10/11/2022, 6:10 PMGiraffe.ViewEngine.Htmx
release... 🤔miniature-lizard-24702
10/11/2022, 8:40 PMmysterious-toddler-20573
10/11/2022, 8:40 PMminiature-lizard-24702
10/11/2022, 8:41 PMmysterious-toddler-20573
10/11/2022, 8:41 PMminiature-lizard-24702
10/11/2022, 8:41 PMminiature-lizard-24702
10/11/2022, 8:42 PMminiature-lizard-24702
10/11/2022, 8:42 PMminiature-lizard-24702
10/11/2022, 8:42 PMmelodic-france-58143
10/11/2022, 9:00 PMgreen-ram-18435
10/11/2022, 9:38 PMmelodic-father-55349
10/12/2022, 9:03 AMmelodic-father-55349
10/12/2022, 9:03 AMpolite-oil-80202
10/12/2022, 11:05 AMjavascript
htmx.on('notify', function(e) {
console.log(e.detail);
console.log(e);
htmx.ajax('POST', '/flashmessage', {target:'#notification', swap:'innerHTML', values: e.detail})
})
Do you have any idea why is this happening or where should I start looking, this is driving me crazy.late-king-98305
10/12/2022, 12:41 PMlate-king-98305
10/12/2022, 12:43 PMbody
of your returned payload, it'll be run each time the response is entered. You may also be able to work around that by putting the call in an external file, then referencing that file in the head
instead; it isn't re-executed when htmx gets a response.polite-oil-80202
10/12/2022, 1:49 PM<a>
link ? It's like there is an instance that is persistent across all navigation...polite-oil-80202
10/12/2022, 2:35 PMhtmx.on
adds an eventlistener on document.body
and this events get stacked when clicking on links, the only way to start fresh is to reload the page.polite-oil-80202
10/12/2022, 2:47 PMhx-boost="true"
polite-oil-80202
10/12/2022, 3:03 PM<body hx-boost="true">
and I navigate I can observe this :
first.png
is the first time i access the page
second.png
is the same page after navigating to another page and navigating back to the first page
you can see htmx:load
has 3 events, but also click
has 36 events instead of 12...
Is this a bug, is this expected and I am misusing hx-boost
?late-king-98305
10/12/2022, 3:25 PMhx-boost="true"
speed things up so much is that it doesn't reload the head
(it will pull out the title
and replace that). All the scripts and styles remain, so you're really just swapping out the body. (There was a whole discussion about this in this channel over the past weekend, but it was really in-the-weeds.)
That's why I recommended moving the script out to an external file, and referencing that in the head
. It'll initialize the first time, but it won't reinitialize every time. There are a few other ways, but if you're looking for the most straightforward, that would be it.
Think about it like this; the typical HTTP request/response transaction is stateless. However, to avoid swapping out the entire page, htmx introduces state in the current browser session. Because of this, you will want to put its initialization, or your custom initialization, outside the part of the page that's being replaced. `script`s in the replaced content will be loaded and executed, which is what you're seeing here. (There are use cases where this behavior is desired.) I hope that makes sense.