25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(plugins): invalidate workbench html cache on plugin set changes
Abeautifulsnow0b3d82fed50c
diff --git a/apps/desktop/src/lib/plugins/pluginUiHtmlCache.spec.ts b/apps/desktop/src/lib/plugins/pluginUiHtmlCache.spec.tsindex 0f5cf26b66..c52d10ddab 100644--- a/apps/desktop/src/lib/plugins/pluginUiHtmlCache.spec.ts+++ b/apps/desktop/src/lib/plugins/pluginUiHtmlCache.spec.ts@@ -11,6 +11,7 @@ vi.mock("@/lib/backend/api", () => ({readPluginUiAsset: mocks.readPluginUiAsset,}));+import { COMPONENT_PLUGINS_UPDATED_EVENT } from "@/lib/updates/componentUpdateEvents";import { clearPluginUiHtmlCache, getCachedPluginUiHtml, getOrLoadPluginUiHtml, setCachedPluginUiHtml } from "./pluginUiHtmlCache";function uiEntryPayload(html: string): { dataBase64: string } {@@ -51,6 +52,36 @@ describe("pluginUiHtmlCache", () => {expect(getCachedPluginUiHtml("[email protected]")).toBeUndefined();});+ it("invalidates on dbx:plugins-changed so a same-version reinstall re-reads the build", async () => {+ setCachedPluginUiHtml("[email protected]", { html: "stale", entryDirectory: "" });+ window.dispatchEvent(new CustomEvent("dbx:plugins-changed"));+ expect(getCachedPluginUiHtml("[email protected]")).toBeUndefined();+ // The next workbench boot pays a fresh bridge read instead of serving stale bytes.+ mocks.readPluginUiEntry.mockResolvedValueOnce(uiEntryPayload("<html>fresh</html>"));+ await expect(getOrLoadPluginUiHtml("[email protected]", "io.dbx.ssh")).resolves.toEqual({ html: "<html>fresh</html>", entryDirectory: "" });+ });++ it("invalidates on the component plugins updated event", () => {+ setCachedPluginUiHtml("[email protected]", { html: "stale", entryDirectory: "" });+ window.dispatchEvent(new Event(COMPONENT_PLUGINS_UPDATED_EVENT));+ expect(getCachedPluginUiHtml("[email protected]")).toBeUndefined();+ });++ it("does not repopulate the cache when an invalidated load completes", async () => {+ let resolveStale!: (value: { dataBase64: string }) => void;+ mocks.readPluginUiEntry.mockReturnValueOnce(new Promise((resolve) => (resolveStale = resolve)));+ const staleLoad = getOrLoadPluginUiHtml("[email protected]", "io.dbx.ssh");++ window.dispatchEvent(new Event("dbx:plugins-changed"));+ mocks.readPluginUiEntry.mockResolvedValueOnce(uiEntryPayload("<html>fresh</html>"));+ const freshLoad = getOrLoadPluginUiHtml("[email protected]", "io.dbx.ssh");+ resolveStale(uiEntryPayload("<html>stale</html>"));++ await expect(staleLoad).resolves.toEqual({ html: "<html>stale</html>", entryDirectory: "" });+ await expect(freshLoad).resolves.toEqual({ html: "<html>fresh</html>", entryDirectory: "" });+ expect(getCachedPluginUiHtml("[email protected]")).toEqual({ html: "<html>fresh</html>", entryDirectory: "" });+ });+it("getOrLoad resolves from the cache without touching the bridge", async () => {setCachedPluginUiHtml("[email protected]", { html: "cached", entryDirectory: "" });await expect(getOrLoadPluginUiHtml("[email protected]", "io.dbx.ssh")).resolves.toEqual({ html: "cached", entryDirectory: "" });diff --git a/apps/desktop/src/lib/plugins/pluginUiHtmlCache.ts b/apps/desktop/src/lib/plugins/pluginUiHtmlCache.tsindex 9f26612d33..a94cdbbc6d 100644--- a/apps/desktop/src/lib/plugins/pluginUiHtmlCache.ts+++ b/apps/desktop/src/lib/plugins/pluginUiHtmlCache.ts@@ -4,6 +4,7 @@// is shared by every PluginWorkbenchHost instance, so only the first boot of a// plugin version pays the read/decode/inline pipeline.import * as api from "@/lib/backend/api";+import { COMPONENT_PLUGINS_UPDATED_EVENT } from "@/lib/updates/componentUpdateEvents";export interface PluginUiHtml {html: string;@@ -17,6 +18,7 @@ export interface PluginUiHtml {const cache = new Map<string, PluginUiHtml>();const LIMIT = 4;+let cacheGeneration = 0;export function getCachedPluginUiHtml(key: string): PluginUiHtml | undefined {const hit = cache.get(key);@@ -36,6 +38,7 @@ export function setCachedPluginUiHtml(key: string, value: PluginUiHtml): void {/** Test and plugin-uninstall escape hatch. */export function clearPluginUiHtmlCache(): void {+ cacheGeneration++;cache.clear();inFlight.clear();}@@ -125,15 +128,30 @@ export function getOrLoadPluginUiHtml(key: string, pluginId: string): Promise<Plif (hit) return Promise.resolve(hit);let load = inFlight.get(key);if (!load) {+ const generation = cacheGeneration;load = loadPluginUiHtml(pluginId).then((value) => {- setCachedPluginUiHtml(key, value);+ // A plugin change may arrive while its old UI document is still being+ // read. Do not let that pre-invalidation request repopulate the cache.+ if (cacheGeneration === generation) setCachedPluginUiHtml(key, value);return value;}).finally(() => {- inFlight.delete(key);+ // A post-invalidation load may already own this key.+ if (cacheGeneration === generation) inFlight.delete(key);});inFlight.set(key, load);}return load;}++// The plugin set can change from entry points other than the plugin center (the update center+// dispatches COMPONENT_PLUGINS_UPDATED_EVENT from App.vue while the center is closed; batch+// uninstall dispatches only dbx:plugins-changed), and a same-version reinstall reuses the+// id:version key. Invalidate on both events here, at the cache owner — the same contract the+// icon resolver follows — so workbench tabs opened after an install/update/uninstall read the+// new ui build instead of the stale inlined bytes.+if (typeof window !== "undefined") {+ window.addEventListener(COMPONENT_PLUGINS_UPDATED_EVENT, clearPluginUiHtmlCache);+ window.addEventListener("dbx:plugins-changed", clearPluginUiHtmlCache);+}