Version 2.0.7.
Steps
- The web page has a
title tag in head block.
- Perform an htmx swap where the response contains the
title tag inside a div block (instead of being one of the "top" tags in the response).
Expected
The tab title is updated.
Actual
The tab title is not updated.
Why is this needed?
Because in my current code the response is constructed by calling several functions and it's most convenient and logical to set the title in one of them. Simplified pseudocode:
function handle-response (request)
data = prepare-data (request
return page(<div class="container">... (helper data)...</div>)
function helper (data)
title = f(data)
return fragment(...<title>title</title> ...)
This doesn't demonstrate well why the title calculation has to be in helper, but let's not dive much into this. I think htmx could simply search for title in the whole response.
Notes
The window title is updated if the original page has no title in head. But this could be the built-in browser "autofixing" behavior and is unrelated to htmx code. E.g. the next html file will have title Foo in Firefox:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<title>Foo</title>
</body>
</html>
Workaround
My current workaround is to use OOB swapping, i.e. replacing all title tags (including in head) with <title hx-swap-oob="true" id="document-title">...</title>
Version 2.0.7.
Steps
titletag inheadblock.titletag inside adivblock (instead of being one of the "top" tags in the response).Expected
The tab title is updated.
Actual
The tab title is not updated.
Why is this needed?
Because in my current code the response is constructed by calling several functions and it's most convenient and logical to set the title in one of them. Simplified pseudocode:
This doesn't demonstrate well why the title calculation has to be in
helper, but let's not dive much into this. I think htmx could simply search fortitlein the whole response.Notes
The window title is updated if the original page has no
titleinhead. But this could be the built-in browser "autofixing" behavior and is unrelated to htmx code. E.g. the next html file will have titleFooin Firefox:Workaround
My current workaround is to use OOB swapping, i.e. replacing all
titletags (including inhead) with<title hx-swap-oob="true" id="document-title">...</title>