Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions plugins/details/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
19 changes: 11 additions & 8 deletions plugins/details/lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,18 @@ 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) {
return;
}
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];
}
};

Expand All @@ -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];
}
Expand Down
6 changes: 3 additions & 3 deletions plugins/details/mcp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 });
Expand All @@ -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") {
Expand Down
Loading