htmx
htmx copied to clipboard
`htmx:afterSettle` is no longer called when returning `<title>` element within the response (2.0.0-beta1)
Expected behavior: (works in 2.0.0-alpha2)
Register 'afterSettle' event listener:
document.addEventListener('htmx:afterSettle', function(event) {
console.log("after settle called")
});
A server returns HTML fragment:
<title>New page title</title>
<div>
<h2>Latest posts</h2>
<div>...</div>
</div>
- content is swapped
- the title is updated
- the event is called - the message is logged into the console.
Current behavior: (2.0.0-beta1)
- content is swapped
- the title is updated
- the event is NOT called - the message is NOT logged into the console.
If the <title> is not present in a response:
<div>
<h2>Latest posts</h2>
<div>...</div>
</div>
the event is called as expected.
UPDATE:
This happens when hx-swap is set to 'outerHTML' (https://github.com/bigskysoftware/htmx/blob/htmx-2.0/src/htmx.js#L940). This filtering causes the settleInfo.elts to be empty.
Also noticed a regression with afterSettle and afterSwap events, which are not firing on 2.0.0 (it works straight away on 1.9.12 if I revert to it.) However, for me it is not related with having a
Hello, I experienced the same like adicco that afterSettle and afterSwap are not fired after update to 2.0.0 and it was fixed by going back to 1.9.12. In my application the error happens regardless of what is swapped and not only for a particular swap.
Was this breaking change intentional? If not, is there a roadmap for fixing the behavior?
Was this breaking change intentional?
Likely not @silentbugs , I haven't had the occasion to look into this yet, but bugfix PRs are always welcome if you (or anyone interested) would like to give it a shot!
This seems to be fixed in version 2.0.2 (released in August). I can only reproduce this by doing all of the following:
- Set
hx-swap="outerHTML" - Include a title in the response
- Use version 2.0.0 or 2.0.1