Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(desktop): keep a page's saved view while its tab moves to another page (#10288)

rawlence32809da96e7b
diff --git a/apps/desktop/src/renderer/src/platform/issue-view-tabs.test.tsx b/apps/desktop/src/renderer/src/platform/issue-view-tabs.test.tsx
index a67a4bbc3d..f08c88a15c 100644
--- a/apps/desktop/src/renderer/src/platform/issue-view-tabs.test.tsx
+++ b/apps/desktop/src/renderer/src/platform/issue-view-tabs.test.tsx
@@ -127,4 +127,44 @@ describe("desktop issue views per tab", () => {
expect(activeUrl()).toBe("/acme/issues");
expect(shown()).toBe("none");
});
+
+ it("leaves the outgoing page's view alone while the tab moves to another page", () => {
+ // The tab's URL changes before the router swaps pages, so My issues is
+ // still mounted when the URL already names the Issues page's view.
+ useTabStore.getState().navigateActiveSession("/acme/my-issues?view=m");
+ render(
+ <DesktopNavigationProvider>
+ <IssueViewUrlSync scope={{ scope_type: "my" }}>
+ <span />
+ </IssueViewUrlSync>
+ </DesktopNavigationProvider>,
+ );
+ expect(useActiveIssueViewStore.getState().active["ws-1:my"]).toBe("m");
+
+ act(() => useTabStore.getState().navigateActiveSession("/acme/issues?view=w"));
+
+ expect(useActiveIssueViewStore.getState().active["ws-1:my"]).toBe("m");
+ expect(activeUrl()).toBe("/acme/issues?view=w");
+ });
+
+ it("adopts the next project's view once the reused page renders that project", () => {
+ const sync = (id: string) => (
+ <DesktopNavigationProvider>
+ <IssueViewUrlSync scope={{ scope_type: "project", scope_id: id }}>
+ <span />
+ </IssueViewUrlSync>
+ </DesktopNavigationProvider>
+ );
+ const active = () => useActiveIssueViewStore.getState().active;
+ useTabStore.getState().navigateActiveSession("/acme/projects/p1?view=a");
+ const { rerender } = render(sync("p1"));
+
+ act(() => useTabStore.getState().navigateActiveSession("/acme/projects/p2?view=b"));
+ expect(active()["ws-1:project:p1"]).toBe("a");
+
+ rerender(sync("p2"));
+ expect(active()["ws-1:project:p1"]).toBe("a");
+ expect(active()["ws-1:project:p2"]).toBe("b");
+ expect(activeUrl()).toBe("/acme/projects/p2?view=b");
+ });
});
diff --git a/apps/desktop/src/renderer/src/platform/issue-view-tabs.tsx b/apps/desktop/src/renderer/src/platform/issue-view-tabs.tsx
index 09187613b6..839cd883bb 100644
--- a/apps/desktop/src/renderer/src/platform/issue-view-tabs.tsx
+++ b/apps/desktop/src/renderer/src/platform/issue-view-tabs.tsx
@@ -55,19 +55,27 @@ export function IssueViewUrlSync({ scope, children }: { scope: IssueViewScope; c
const activeViewId = useActiveIssueViewStore((s) => s.active[containerKey] ?? null);
const setActive = useActiveIssueViewStore((s) => s.setActive);
const seenUrlView = useRef<string | null | undefined>(undefined);
+ // The page this sync belongs to. The tab's URL moves to the next page a few
+ // frames before the router swaps this one out (see rendered-route-store);
+ // in that gap `?view=` names the next page's view, which this page must
+ // neither adopt nor write over.
+ const page = useRef<{ containerKey: string; pathname: string } | null>(null);
// Until the URL is adopted the store can still hold another surface's view;
// rendering against it would mount (and fetch) that view first.
const [adopting, setAdopting] = useState(() => urlView !== null && urlView !== activeViewId);
useLayoutEffect(() => {
+ if (page.current?.containerKey !== containerKey) page.current = { containerKey, pathname: navigation.pathname };
+ if (navigation.pathname !== page.current.pathname) return;
const mounting = seenUrlView.current === undefined;
if (urlView === seenUrlView.current) return;
seenUrlView.current = urlView;
if (!mounting || urlView) setActive(containerKey, urlView);
setAdopting(false);
- }, [containerKey, urlView, setActive]);
+ }, [containerKey, urlView, navigation.pathname, setActive]);
useEffect(() => {
+ if (navigation.pathname !== page.current?.pathname) return;
const current = useActiveIssueViewStore.getState().active[containerKey] ?? null;
if (current === seenUrlView.current) return;
const params = new URLSearchParams(navigation.searchParams);