js: When page load fails during install, show it to user

- Currently when HTMX tries to fetch a page and fails, it silently fails and
does not perform any further operations. So, the installation page is stuck.
This is also leading to functional test case failures.

- Handle errors in page response and errors while making requests and reload the
entire page. This will result in browser showing appropriate error page. User
will understand that the operation has failed.

- Also add HTMX event listeners on the body as shown in HTMX documentation.

Tests:

- Press install. After installation process has started, stop Apache web server.
Without the patch, HTMX fails silently and the installation progress is shown
indefinitely.

- With the patch applied, the connection error page is properly shown.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2026-02-23 22:12:45 -08:00 committed by James Valleroy
parent 68ccb46ecf
commit 5e112bd8bf
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -292,13 +292,28 @@ document.addEventListener('click', function (event) {
* element is not found in the response. However, in htmx:afterSwap event we can
* see that the target has no children and choose to refresh the whole page.
*/
document.addEventListener('htmx:afterSwap', function (event) {
document.body.addEventListener('htmx:afterSwap', function (event) {
const target = event.detail.target;
if (target && target.children.length === 0) {
window.location.reload();
}
});
/*
* If an error occurs during a HTMX request, then reload the page. It won't be a
* silent failure for the user and will imitate the behavior that was present
* before HTMX was introduced. For functional tests, this means that a clear
* browser is shown. Tests can decide to reload the page until the error is
* resolved.
*/
document.body.addEventListener('htmx:responseError', function (event) {
window.location.reload();
});
document.body.addEventListener("htmx:sendError", function(event) {
window.location.reload();
});
/*
* Decrement notification counter badge when a notification is dismissed via
* HTMX.