diff --git a/CHANGELOG.md b/CHANGELOG.md index a6b59e0..8d25264 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,14 @@ APIs change between minors without a deprecation period. ## Unreleased +### Fixed + +- The cluster and node pages swapped their live part every few seconds, + forms and all, so filling one in raced the clock: what was typed, an + open choice and the focus were lost. The refresh now waits while a field + in it has the focus or a form in it has been typed into and not sent; + the mirror page's reload during a download waits the same way. + ## v0.14.5 — 2026-10-14 Picture and 3D models that add themselves where a card fits them, with a diff --git a/internal/web/admin_mirror_test.go b/internal/web/admin_mirror_test.go index a91242d..df57683 100644 --- a/internal/web/admin_mirror_test.go +++ b/internal/web/admin_mirror_test.go @@ -239,14 +239,14 @@ func TestThePageReloadsOnlyWhileSomethingIsDownloading(t *testing.T) { // A reload while nothing is happening would take with it whatever the // operator was typing into the fetch form. - if strings.Contains(idle, "http-equiv=\"refresh\"") { + if strings.Contains(idle, "name=\"llmgw-refresh\"") { t.Error("an idle page should not reload itself") } busy := mirrorGet(t, mirrorPage(t, &fakeMirror{models: []mirror.Status{ {Model: "m", Version: "v", File: "f", State: mirror.Fetching}, }}, true), "/admin/mirror").Body.String() - if !strings.Contains(busy, "http-equiv=\"refresh\"") { + if !strings.Contains(busy, "name=\"llmgw-refresh\"") { t.Error("a page with a download running should follow it") } } @@ -680,7 +680,7 @@ func TestEachTabDoesOnlyItsOwnWork(t *testing.T) { if strings.Contains(held, `name="source" required`) || strings.Contains(held, "Search Hugging Face") { t.Error("other tabs' forms are on the list") } - if !strings.Contains(held, `http-equiv="refresh"`) { + if !strings.Contains(held, `name="llmgw-refresh"`) { t.Error("the list stopped following a download") } @@ -688,7 +688,7 @@ func TestEachTabDoesOnlyItsOwnWork(t *testing.T) { if reg.explored != 1 || !strings.Contains(explore, "Search Hugging Face") { t.Error("the explorer tab did not explore") } - if strings.Contains(explore, `id="held"`) || strings.Contains(explore, `http-equiv="refresh"`) { + if strings.Contains(explore, `id="held"`) || strings.Contains(explore, `name="llmgw-refresh"`) { t.Error("the explorer shows the list, or reloads away a search") } // A link from before there were tabs still lands on the explorer. diff --git a/internal/web/mirror_detail_test.go b/internal/web/mirror_detail_test.go index 0d6eee8..196da04 100644 --- a/internal/web/mirror_detail_test.go +++ b/internal/web/mirror_detail_test.go @@ -92,7 +92,7 @@ func TestAHeldModelOpensToWhereItRunsAndHowMuchRoomIsLeft(t *testing.T) { if strings.Contains(body, "secret-engine-key") { t.Error("the engine's key reached the page") } - if strings.Contains(body, `http-equiv="refresh"`) { + if strings.Contains(body, `name="llmgw-refresh"`) { t.Error("a page with an open form reloads under the operator") } } diff --git a/internal/web/static/pages.js b/internal/web/static/pages.js index 3035c7d..ee812c4 100644 --- a/internal/web/static/pages.js +++ b/internal/web/static/pages.js @@ -18,11 +18,50 @@ var msg = e.target.getAttribute && e.target.getAttribute('data-confirm'); if (msg && !window.confirm(msg)) { e.preventDefault(); } }); + // A form being filled in is not refreshed away. The live parts of the + // cluster and node pages are swapped whole every few seconds, and a form + // inside one lost what was typed into it, its open choice, its focus: + // filling one in raced the clock. While a field in the refreshing part + // has the focus, or a form in it has been typed into and not sent, it + // waits; sending the form, or leaving the page, ends that. + var edited = []; + document.addEventListener('input', function (e) { + var f = e.target.form || (e.target.closest && e.target.closest('form')); + if (f && edited.indexOf(f) < 0) { edited.push(f); } + }); + document.addEventListener('submit', function (e) { + if (!e.defaultPrevented) { edited = []; } + }); + function busy(root) { + var a = document.activeElement; + if (a && a !== document.body && root.contains(a) && + a.matches('input, select, textarea, [contenteditable]')) { + return true; + } + for (var i = 0; i < edited.length; i++) { + if (root.contains(edited[i]) && document.contains(edited[i])) { return true; } + } + return false; + } // htmx's trigger filters are evaluated JavaScript; this is the same - // "only while visible" without them. + // "only while visible" without them, and "not while being filled in". document.addEventListener('htmx:beforeRequest', function (e) { - if (document.visibilityState !== 'visible' && e.detail.elt.hasAttribute('data-visible-only')) { + var elt = e.detail.elt; + if (elt.hasAttribute('data-visible-only') && + (document.visibilityState !== 'visible' || busy(elt))) { e.preventDefault(); } }); + // A page that reloads itself () + // does it on the same terms, rather than by http-equiv, which nothing + // can hold off. + var r = document.querySelector('meta[name="llmgw-refresh"]'); + var every = r ? parseInt(r.getAttribute('content'), 10) : 0; + if (every > 0) { + setInterval(function () { + if (document.visibilityState === 'visible' && !busy(document.body)) { + window.location.reload(); + } + }, every * 1000); + } })(); diff --git a/internal/web/templates/admin_mirror.html b/internal/web/templates/admin_mirror.html index 32bcefd..5e750ad 100644 --- a/internal/web/templates/admin_mirror.html +++ b/internal/web/templates/admin_mirror.html @@ -1,9 +1,9 @@ {{define "admin_mirror"}} -{{/* Only while something is downloading. A reload at any other time would - take with it whatever the operator was typing into the form below. */}} -{{if .RefreshSec}}{{end}} +{{/* Only while something is downloading, and not while a form is being + filled in: pages.js holds the reload off then. */}} +{{if .RefreshSec}}{{end}} {{t "mirror.title"}} · llmgw