admin: stop the models page jumping to the bottom on refresh

Clicking Load/Unload (or any refreshLocal) re-ran loadCachedModels, which
blanked the HF/GGUF lists to "Loading…" every time. That collapsed the page
height and threw the viewport to the end, so a whisper-server unload looked
like it "did nothing and scrolled to the bottom" even though it worked.

Now the "Loading…" placeholder only shows on the first (empty) load; on a
refresh the existing rows stay in place and the scroll position is captured
and restored around the re-render.
Co-Authored-By: 's avatarClaude Opus 4.8 <noreply@anthropic.com>
parent b717f1dc
......@@ -2346,7 +2346,12 @@ async function loadCachedModels(){
_localModels = [];
const hfEl = document.getElementById('hf-models-list');
const ggufEl = document.getElementById('gguf-models-list');
hfEl.innerHTML = ggufEl.innerHTML = '<span class="muted small">Loading…</span>';
// Preserve scroll position across the refresh. Only blank the lists on the
// first (empty) load — on a refresh (e.g. after load/unload) keep the existing
// rows in place so the page doesn't collapse and jump the viewport to the end.
const _scrollY = window.scrollY;
const _firstLoad = !hfEl.dataset.loaded;
if(_firstLoad) hfEl.innerHTML = ggufEl.innerHTML = '<span class="muted small">Loading…</span>';
try{
const r = await fetch(ROOT_PATH + '/admin/api/cached-models');
if(!r.ok) throw new Error((await r.json()).detail||r.statusText);
......@@ -2504,8 +2509,11 @@ async function loadCachedModels(){
if(wsHtml) ggufEl.insertAdjacentHTML('afterend', wsHtml);
resetWhisperServerBuilderDefaults();
applyLocalFilter();
hfEl.dataset.loaded = '1';
// Restore the pre-refresh scroll position (the lists were rebuilt in place).
if(!_firstLoad) window.scrollTo(0, _scrollY);
}catch(e){
hfEl.innerHTML = ggufEl.innerHTML = `<span class="muted small">Error: ${esc(e.message)}</span>`;
if(_firstLoad) hfEl.innerHTML = ggufEl.innerHTML = `<span class="muted small">Error: ${esc(e.message)}</span>`;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment