From b4e6b7bcdcd61e9c557120f7c5e54ac0b8d525a4 Mon Sep 17 00:00:00 2001 From: Brendan Date: Thu, 3 Dec 2026 09:58:31 +0000 Subject: [PATCH] fix(details): keep list rows on show while a refresh loads --- plugins/details/init.js | 2 ++ plugins/details/lists.js | 19 +++++++++++-------- plugins/details/mcp.js | 6 +++--- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/plugins/details/init.js b/plugins/details/init.js index 962419db3..858674076 100644 --- a/plugins/details/init.js +++ b/plugins/details/init.js @@ -68,6 +68,8 @@ module.exports = plugin.defineWindow((ctx) => { signIn: { current: null }, location: (directory) => lists.location(env, directory), servers: (json) => lists.servers(json), + // Every location's `/api/mcp`, keeping what the lists show until it reads again. + invalidate: () => lists.invalidate(env, "mcp", null), redraw, }; env = { diff --git a/plugins/details/lists.js b/plugins/details/lists.js index 1254aee62..5005a0bc7 100644 --- a/plugins/details/lists.js +++ b/plugins/details/lists.js @@ -127,6 +127,7 @@ function synced(env, directory, items) { // Drops cached reads for `service` at `directory` (or every directory when `directory` is null/empty) // so open popovers, drawers, and dialogs refresh on live SSE updates // (`packages/gui-plugins/src/details/server-panel.tsx:787-795`, `packages/client/src/solid/data.ts:1539, 1602-1606`). +// Their parsed items stay on show, marked refreshing, until the new answer lands. lists.invalidate = function (env, service, directory) { const prefix = PATHS[service]; if (prefix == null) { @@ -134,14 +135,10 @@ lists.invalidate = function (env, service, directory) { } const target = directory != null && directory !== "" ? prefix + lists.location(env, directory) : prefix; env.Server.Invalidate(target); - if (target === prefix) { - for (const key of Object.keys(env.state.parsed)) { - if (key.startsWith(prefix)) { - delete env.state.parsed[key]; - } + for (const [key, cached] of Object.entries(env.state.parsed)) { + if (target === prefix ? key.startsWith(prefix) : key === target) { + cached.refreshing = true; } - } else { - delete env.state.parsed[target]; } }; @@ -154,13 +151,19 @@ lists.read = function (env, service, directory) { paths[directory] = path; } const res = env.Server.Resource(path, env.state.opens); + const cached = env.state.parsed[path]; if (res.status === "error") { + delete env.state.parsed[path]; return [{ kind: "failed" }, res.generation]; } if (res.status === "loading" && res.generation === 0) { + // `Server.Invalidate` dropped the read, so it loads again from nothing: the rows it showed + // stay until the new answer lands rather than blinking to "Loading". + if (cached && cached.refreshing) { + return [{ kind: "ready", items: cached.items }, cached.generation]; + } return [{ kind: "loading" }, 0]; } - const cached = env.state.parsed[path]; if (cached && cached.generation === res.generation) { return [{ kind: "ready", items: cached.items }, res.generation]; } diff --git a/plugins/details/mcp.js b/plugins/details/mcp.js index c1cb0492d..a945c0416 100644 --- a/plugins/details/mcp.js +++ b/plugins/details/mcp.js @@ -99,7 +99,7 @@ function runToggle(env, directory, effect) { return failed(done.error); } } - env.Server.Invalidate("/api/mcp"); + env.invalidate(); const listed = await env.Server.RequestAsync("GET", "/api/mcp" + loc); if (!listed.ok) { return failed(listed.error); @@ -275,7 +275,7 @@ function runSignIn(env, s, effects) { mcp.signInStep(env, { type: "sync.timed-out", syncAttempt }); }); task.spawn(async () => { - env.Server.Invalidate("/api/mcp"); + env.invalidate(); const res = await env.Server.RequestAsync("GET", "/api/mcp" + env.location(s.directory)); if (res.ok) { mcp.signInStep(env, { type: "sync.succeeded", syncAttempt }); @@ -291,7 +291,7 @@ function runSignIn(env, s, effects) { cancelHandle(s.sync); s.sync = null; } else if (effect.type === "refresh") { - env.Server.Invalidate("/api/mcp"); + env.invalidate(); } else if (effect.type === "open-external") { env.System.OpenExternal(effect.url); } else if (effect.type === "cancel") {