Properly set title during history cache miss (#1014)

I am running HTMX with hx-boost and the history cache disabled (it's important to not show stale content to my users unless my backend uses cache-control headers to do so, in which case I simply rely on the fetch being cached). However, during 'history cache misses', the page title is not properly set.

This fixes it (mirroring the logic in `handleAjaxResponse`).
This commit is contained in:
Leif Foged 2022-09-30 15:07:56 -05:00 committed by GitHub
parent d94f38d65c
commit 3c6b5996a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1972,6 +1972,15 @@ return (function () {
fragment = fragment.querySelector('[hx-history-elt],[data-hx-history-elt]') || fragment;
var historyElement = getHistoryElement();
var settleInfo = makeSettleInfo(historyElement);
var title = findTitle(this.response);
if (title) {
var titleElt = find("title");
if (titleElt) {
titleElt.innerHTML = title;
} else {
window.document.title = title;
}
}
// @ts-ignore
swapInnerHTML(historyElement, fragment, settleInfo)
settleImmediately(settleInfo.tasks);