From 5e112bd8bf30eca2b71509735656b4f5cfb7cdb7 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Mon, 23 Feb 2026 22:12:45 -0800 Subject: [PATCH] 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 Reviewed-by: James Valleroy --- static/themes/default/js/main.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/static/themes/default/js/main.js b/static/themes/default/js/main.js index c56a9a3a7..31d4bd1c9 100644 --- a/static/themes/default/js/main.js +++ b/static/themes/default/js/main.js @@ -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.