Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(desktop): prevent tab close router sync loop (#2393)
Qiang Zhang6a48022123c3
diff --git a/apps/desktop/src/renderer/src/stores/tab-store.test.ts b/apps/desktop/src/renderer/src/stores/tab-store.test.tsindex 8e5ed7d6f6..dbae30977e 100644--- a/apps/desktop/src/renderer/src/stores/tab-store.test.ts+++ b/apps/desktop/src/renderer/src/stores/tab-store.test.ts@@ -180,6 +180,61 @@ describe("useTabStore actions", () => {expect(s.byWorkspace.acme.tabs[0].id).not.toBe(onlyTabId); // fresh tab});+ it("defers disposing the closed tab router until after the store update", () => {+ vi.useFakeTimers();+ try {+ const store = useTabStore.getState();+ store.switchWorkspace("acme");+ const closedTabId = store.addTab("/acme/settings", "Settings", "Settings");+ const closingTab = useTabStore+ .getState()+ .byWorkspace.acme.tabs.find((t) => t.id === closedTabId);+ const dispose = vi.mocked(closingTab!.router.dispose);++ store.closeTab(closedTabId);++ expect(dispose).not.toHaveBeenCalled();+ expect(+ useTabStore.getState().byWorkspace.acme.tabs.some((t) => t.id === closedTabId),+ ).toBe(false);++ vi.runAllTimers();++ expect(dispose).toHaveBeenCalledOnce();+ } finally {+ vi.useRealTimers();+ }+ });++ it("ignores router-sync updates from a tab after it has been closed", () => {+ const store = useTabStore.getState();+ store.switchWorkspace("acme");+ const closedTabId = store.addTab("/acme/settings", "Settings", "Settings");++ store.closeTab(closedTabId);+ const before = useTabStore.getState().byWorkspace.acme;++ store.updateTab(closedTabId, { path: "/acme/runtimes", icon: "Monitor" });+ store.updateTabHistory(closedTabId, 1, 2);++ expect(useTabStore.getState().byWorkspace.acme).toBe(before);+ expect(+ useTabStore.getState().byWorkspace.acme.tabs.some((t) => t.id === closedTabId),+ ).toBe(false);+ });++ it("does not replace the tab group for no-op router-sync updates", () => {+ const store = useTabStore.getState();+ store.switchWorkspace("acme");+ const tab = useTabStore.getState().byWorkspace.acme.tabs[0];+ const before = useTabStore.getState().byWorkspace.acme;++ store.updateTab(tab.id, { path: tab.path, icon: tab.icon, title: tab.title });+ store.updateTabHistory(tab.id, tab.historyIndex, tab.historyLength);++ expect(useTabStore.getState().byWorkspace.acme).toBe(before);+ });+it("validateWorkspaceSlugs drops groups for slugs not in the valid set and repoints active", () => {const store = useTabStore.getState();store.switchWorkspace("acme");diff --git a/apps/desktop/src/renderer/src/stores/tab-store.ts b/apps/desktop/src/renderer/src/stores/tab-store.tsindex 6ca66893d8..78a1bb5c27 100644--- a/apps/desktop/src/renderer/src/stores/tab-store.ts+++ b/apps/desktop/src/renderer/src/stores/tab-store.ts@@ -350,7 +350,10 @@ export const useTabStore = create<TabStore>()(const { slug, group, index } = hit;const closing = group.tabs[index];- closing.router.dispose();+ const disposeClosingRouter = () => {+ // Let React unmount the tab's RouterProvider before disposing it.+ window.setTimeout(() => closing.router.dispose(), 0);+ };if (group.tabs.length === 1) {// Last tab in this workspace — reseed a default so the workspace@@ -363,6 +366,7 @@ export const useTabStore = create<TabStore>()([slug]: { tabs: [fresh], activeTabId: fresh.id },},});+ disposeClosingRouter();return;}@@ -378,6 +382,7 @@ export const useTabStore = create<TabStore>()([slug]: { tabs: nextTabs, activeTabId: nextActiveTabId },},});+ disposeClosingRouter();},setActiveTab(tabId) {@@ -402,6 +407,13 @@ export const useTabStore = create<TabStore>()(const { slug, group, index } = hit;const current = group.tabs[index];const next: Tab = { ...current, ...patch };+ if (+ next.path === current.path &&+ next.title === current.title &&+ next.icon === current.icon+ ) {+ return;+ }const nextTabs = [...group.tabs];nextTabs[index] = next;set({@@ -418,6 +430,12 @@ export const useTabStore = create<TabStore>()(if (!hit) return;const { slug, group, index } = hit;const current = group.tabs[index];+ if (+ current.historyIndex === historyIndex &&+ current.historyLength === historyLength+ ) {+ return;+ }const next: Tab = { ...current, historyIndex, historyLength };const nextTabs = [...group.tabs];nextTabs[index] = next;