Skip to content

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

Go

fix(desktop): restore background issue tabs after restart (MUL-8679) (#10037)

Bohan Jiang12ce618c4130
diff --git a/apps/desktop/src/renderer/src/components/tab-bar.test.tsx b/apps/desktop/src/renderer/src/components/tab-bar.test.tsx
index 34d9ad7701..003a46e26d 100644
--- a/apps/desktop/src/renderer/src/components/tab-bar.test.tsx
+++ b/apps/desktop/src/renderer/src/components/tab-bar.test.tsx
@@ -84,19 +84,21 @@ vi.mock("@multica/core/paths", async (importOriginal) => ({
// (overflow, pin, close, context menu) don't need the whole query stack. By
// default `title` mirrors the persisted tab title (matching the real hook's
// fallback); a test can set `pres.title` to simulate a resolved title that
-// differs, to exercise the active-tab persist effect.
-const pres = vi.hoisted(() => ({ title: null as string | null }));
+// differs, to exercise resolved-title persistence.
+const pres = vi.hoisted(() => ({ title: null as string | null, titleResolved: true }));
vi.mock("@multica/views/layout", () => ({
- useTabPresentation: (_url: string, fallbackTitle?: string) => ({
+ useTabPresentation: vi.fn((_url: string, fallbackTitle?: string) => ({
visual: { kind: "icon", icon: "ListTodo" },
title: pres.title ?? fallbackTitle ?? "",
- }),
+ titleResolved: pres.titleResolved,
+ })),
ResourceLeadingVisual: ({ visual }: { visual: { kind: string; icon?: string } }) => (
<span data-testid="tab-leading" data-visual-kind={visual.kind} data-icon={visual.icon} />
),
}));
import { TabBar } from "./tab-bar";
+import { useTabPresentation } from "@multica/views/layout";
function render(
ui: ReactElement,
@@ -137,6 +139,8 @@ function reset() {
state.updateTab.mockReset();
state.openIssueWindow.mockReset();
pres.title = null;
+ pres.titleResolved = true;
+ vi.mocked(useTabPresentation).mockClear();
}
beforeEach(() => {
@@ -247,8 +251,8 @@ describe("TabBar hover action buttons", () => {
});
});
-describe("TabBar active-tab title persistence", () => {
- it("persists the resolved title only for the active tab", () => {
+describe("TabBar title persistence", () => {
+ it("loads tab identities and persists resolved titles for background tabs too", () => {
pres.title = "MUL-1: Fixed";
state.byWorkspace.acme.tabs = [
{ id: "tA", url: "/acme/issues/i1", title: "Issues", pinned: false },
@@ -257,14 +261,23 @@ describe("TabBar active-tab title persistence", () => {
state.byWorkspace.acme.activeTabId = "tA";
render(<TabBar />);
expect(state.updateTab).toHaveBeenCalledWith("tA", { title: "MUL-1: Fixed" });
- expect(state.updateTab).not.toHaveBeenCalledWith("tB", expect.anything());
- expect(state.updateTab).toHaveBeenCalledTimes(1);
+ expect(state.updateTab).toHaveBeenCalledWith("tB", { title: "MUL-1: Fixed" });
+ expect(state.updateTab).toHaveBeenCalledTimes(2);
+ expect(useTabPresentation).toHaveBeenCalledWith("/acme/issues/i1", "Issues", { fetch: true });
+ });
+
+ it("does not persist loading placeholders for active or background tabs", () => {
+ pres.title = "Issue";
+ pres.titleResolved = false;
+ state.byWorkspace.acme.tabs = [
+ { id: "tA", url: "/acme/issues/i1", title: "Saved", pinned: false },
+ { id: "tB", url: "/acme/issues/i2", title: "", pinned: false },
+ ];
+ render(<TabBar />);
+ expect(state.updateTab).not.toHaveBeenCalled();
});
it("does not re-persist when the resolved title already matches (no loop)", () => {
- // Active tab's persisted title equals the resolved title.
- pres.title = "Issues";
- state.byWorkspace.acme.activeTabId = "tA"; // tA.title === "Issues"
render(<TabBar />);
expect(state.updateTab).not.toHaveBeenCalled();
});
diff --git a/apps/desktop/src/renderer/src/components/tab-bar.tsx b/apps/desktop/src/renderer/src/components/tab-bar.tsx
index 6ea6ce721a..bb52599abb 100644
--- a/apps/desktop/src/renderer/src/components/tab-bar.tsx
+++ b/apps/desktop/src/renderer/src/components/tab-bar.tsx
@@ -161,7 +161,7 @@ function SortableTabItem({
// query cache — a resource's own icon/status/avatar and its real title,
// updated as the cache updates. `tab.title` is only a persisted first-frame
// fallback. See @multica/views useTabPresentation.
- const { visual, title } = useTabPresentation(tab.url, tab.title);
+ const { visual, title, titleResolved } = useTabPresentation(tab.url, tab.title, { fetch: true });
const pinLabel = tab.pinned
? t(($) => $.desktop.tab_bar.unpin)
: t(($) => $.desktop.tab_bar.pin);
@@ -172,15 +172,15 @@ function SortableTabItem({
? t(($) => $.desktop.tab_bar.pinned_name, { title })
: title;
- // Persist the active tab's resolved title so it survives as the next
+ // Persist each tab's resolved title so it survives as the next
// session's first-frame fallback. The tab strip itself always renders the
// live resolved `title`; `tab.title` is just the persisted seed. This
// replaces the old document.title → MutationObserver → tab.title path (the OS
// window title stays page-driven via useDocumentTitle).
useEffect(() => {
- if (!isActive) return;
+ if (!titleResolved) return;
if (tab.title !== title) updateTab(tab.id, { title });
- }, [isActive, title, tab.id, tab.title, updateTab]);
+ }, [titleResolved, title, tab.id, tab.title, updateTab]);
const {
attributes,
diff --git a/packages/core/issues/canonical-id.ts b/packages/core/issues/canonical-id.ts
index 33c51d5f25..d4eddcf404 100644
--- a/packages/core/issues/canonical-id.ts
+++ b/packages/core/issues/canonical-id.ts
@@ -50,11 +50,17 @@ export interface CanonicalIssue {
* canonical query never observes an empty cache and never fires a fetch of its
* own. Seeding the cache from an effect instead would run after that decision
* and leave the single-request property resting on hook ordering.
+ *
+ * `enabled: false` keeps the cache subscriptions without starting requests.
*/
-export function useCanonicalIssue(wsId: string, routeId: string): CanonicalIssue {
+export function useCanonicalIssue(
+ wsId: string,
+ routeId: string,
+ { enabled = true }: { enabled?: boolean } = {},
+): CanonicalIssue {
const qc = useQueryClient();
const isUuid = isIssueUuid(routeId);
- const resolveEnabled = !isUuid && !!wsId && !!routeId;
+ const resolveEnabled = enabled && !isUuid && !!wsId && !!routeId;
const resolve = useQuery({
...issueDetailOptions(wsId, routeId),
@@ -65,7 +71,7 @@ export function useCanonicalIssue(wsId: string, routeId: string): CanonicalIssue
const detail = useQuery({
...issueDetailOptions(wsId, canonicalId ?? ""),
- enabled: !!canonicalId && !!wsId,
+ enabled: enabled && !!canonicalId && !!wsId,
// Ignored once the entry holds data, so a row already patched by a realtime
// event is never overwritten by this older resolution response.
initialData: isUuid ? undefined : resolve.data,
diff --git a/packages/core/paths/tab-presentation.ts b/packages/core/paths/tab-presentation.ts
index 8e7f8ab7c7..fc1aab3f47 100644
--- a/packages/core/paths/tab-presentation.ts
+++ b/packages/core/paths/tab-presentation.ts
@@ -16,7 +16,7 @@
* loaded yet renders a stable type icon and a type label, never a wrong or
* empty identity, and never borrows the Issues icon.
*/
-import type { IssueStatus, IssueStatusCategory } from "../types";
+import type { Issue, IssueStatus, IssueStatusCategory } from "../types";
import { issueStatusCategory } from "../issues/status-category";
import {
WORKSPACE_PAGES,
@@ -79,7 +79,7 @@ export type InboxSelectionData =
* pending (type-label + type-icon) presentation.
*/
export interface TabEntityData {
- issue?: { identifier: string; title: string; status: IssueStatus };
+ issue?: Pick<Issue, "identifier" | "title" | "status" | "status_category">;
project?: { icon: string | null; title: string };
autopilot?: { title: string };
/** Resolved display name for an actor subject. */
diff --git a/packages/views/layout/tab-presentation.test.tsx b/packages/views/layout/tab-presentation.test.tsx
index 867d156220..0b805041cf 100644
--- a/packages/views/layout/tab-presentation.test.tsx
+++ b/packages/views/layout/tab-presentation.test.tsx
@@ -1,7 +1,11 @@
-import { describe, it, expect, vi, beforeEach } from "vitest";
+import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import type { ReactNode } from "react";
-import { render, renderHook } from "@testing-library/react";
+import { act, render, renderHook, waitFor } from "@testing-library/react";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
+import { ApiError, setApiInstance, type ApiClient } from "@multica/core/api";
+import { createQueryClient } from "@multica/core/query-client";
+import type { Issue, ListIssueStatusesResponse } from "@multica/core/types";
+import { onIssueUpdated } from "@multica/core/issues";
import { issueDetailOptions } from "@multica/core/issues/queries";
import { issueStatusListOptions } from "@multica/core/issue-statuses/queries";
import { projectDetailOptions } from "@multica/core/projects/queries";
@@ -105,8 +109,8 @@ function presentationOf(url: string, fallback?: string) {
const wrapper = ({ children }: { children: ReactNode }) => (
<QueryClientProvider client={qc}>{children}</QueryClientProvider>
);
- return renderHook(() => useTabPresentation(url, fallback), { wrapper }).result
- .current;
+ const { visual, title } = renderHook(() => useTabPresentation(url, fallback), { wrapper }).result.current;
+ return { visual, title };
}
beforeEach(() => {
@@ -296,6 +300,24 @@ describe("useTabPresentation — live from cache", () => {
});
describe("useTabPresentation — pending / fallback", () => {
+ it.each([undefined, "Saved session"])("keeps an unresolved chat selection pending with fallback %s", async (fallback) => {
+ const qc = makeClient();
+ const wrapper = ({ children }: { children: ReactNode }) => (
+ <QueryClientProvider client={qc}>{children}</QueryClientProvider>
+ );
+ const { result } = renderHook(
+ () => useTabPresentation("/acme/chat?session=s7", fallback), { wrapper },
+ );
+
+ expect(result.current).toMatchObject({ title: fallback ?? "Chat", titleResolved: false });
+ act(() => qc.setQueryData(chatSessionsOptions("ws1").queryKey, [
+ { id: "s7", title: "Loaded session" },
+ ] as never));
+ await waitFor(() => expect(result.current).toMatchObject({
+ title: "Loaded session", titleResolved: true,
+ }));
+ });
+
it("pending issue keeps the issue-status slot and uses the persisted fallback", () => {
expect(presentationOf("/acme/issues/unloaded", "MUL-7: Prior")).toEqual({
visual: { kind: "issue-status", status: null },
@@ -326,6 +348,17 @@ describe("useTabPresentation — pending / fallback", () => {
});
describe("ResourceLeadingVisual", () => {
+ it("uses a neutral skeleton while the status has not loaded", () => {
+ const { container, rerender } = render(
+ <ResourceLeadingVisual visual={{ kind: "issue-status", status: null }} />,
+ );
+ expect(container.querySelector("svg")).toBeNull();
+ expect(container.querySelector('[data-slot="skeleton"]')).toBeVisible();
+ rerender(<ResourceLeadingVisual visual={{ kind: "issue-status", status: "todo" }} />);
+ expect(container.querySelector('[data-slot="skeleton"]')).toBeNull();
+ expect(container.querySelector("svg")).not.toBeNull();
+ });
+
it("renders a project icon with its emoji", () => {
const { getByText } = render(
<ResourceLeadingVisual visual={{ kind: "project-icon", icon: "🚀" }} />,
@@ -356,3 +389,149 @@ describe("ResourceLeadingVisual", () => {
expect(container.querySelector("svg")).toBeTruthy();
});
});
+
+describe("useTabPresentation — restored issue tabs", () => {
+ const issue: Issue = {
+ id: "cb240efb-154c-42a8-ae92-42b02676feca", workspace_id: "ws1",
+ number: 7, identifier: "MUL-7", title: "Restore tabs", description: null,
+ status: "in_progress", status_category: "started", priority: "medium",
+ assignee_type: null, assignee_id: null, creator_type: "member", creator_id: "u1",
+ parent_issue_id: null, project_id: null, position: 0, stage: null,
+ start_date: null, due_date: null, metadata: {}, properties: {}, labels: [],
+ created_at: "2026-11-06T00:00:00Z", updated_at: "2026-11-06T00:00:00Z",
+ };
+ let qc: QueryClient;
+ let getIssue: ReturnType<typeof vi.fn>;
+ let listIssueStatuses: ReturnType<typeof vi.fn>;
+
+ beforeEach(() => {
+ qc = createQueryClient();
+ qc.setDefaultOptions({ queries: { ...qc.getDefaultOptions().queries, retry: false } });
+ getIssue = vi.fn(async () => issue);
+ listIssueStatuses = vi.fn(async (): Promise<ListIssueStatusesResponse> => ({
+ statuses: [], categories: ["unstarted", "started", "done", "closed"], total: 0,
+ }));
+ setApiInstance({ getIssue, listIssueStatuses } as unknown as ApiClient);
+ });
+
+ afterEach(() => qc.clear());
+
+ function wrapper({ children }: { children: ReactNode }) {
+ return <QueryClientProvider client={qc}>{children}</QueryClientProvider>;
+ }
+
+ it("loads an identifier tab once and follows UUID realtime patches without opening its page", async () => {
+ const { result } = renderHook(
+ () => useTabPresentation("/acme/issues/MUL-7", "Prior title", { fetch: true }),
+ { wrapper },
+ );
+ await waitFor(() => expect(result.current.title).toBe("MUL-7: Restore tabs"));
+ expect(result.current.titleResolved).toBe(true);
+ expect(qc.getQueryData(issueDetailOptions("ws1", issue.id).queryKey)).toEqual(issue);
+ expect(getIssue).toHaveBeenCalledExactlyOnceWith("MUL-7");
+
+ act(() => onIssueUpdated(qc, "ws1", { ...issue, status: "done", status_category: "done", title: "Fixed" }));
+ await waitFor(() => expect(result.current.visual).toMatchObject({ status: "done", category: "done" }));
+ expect(result.current.title).toBe("MUL-7: Fixed");
+ expect(getIssue).toHaveBeenCalledTimes(1);
+ });
+
+ it("shares the detail and catalog requests between tabs for the same issue", async () => {
+ const { result } = renderHook(() => [
+ useTabPresentation(`/acme/issues/${issue.id}`, undefined, { fetch: true }),
+ useTabPresentation(`/acme/issues/${issue.id}`, undefined, { fetch: true }),
+ ], { wrapper });
+ await waitFor(() => expect(result.current.every((tab) => tab.title === "MUL-7: Restore tabs")).toBe(true));
+ expect(getIssue).toHaveBeenCalledExactlyOnceWith(issue.id);
+ expect(listIssueStatuses).toHaveBeenCalledExactlyOnceWith(true);
+ });
+
+ it("preserves server categories and loads custom colors without a custom icon", async () => {
+ getIssue.mockResolvedValue({ ...issue, status: "qa" });
+ listIssueStatuses.mockResolvedValue({
+ statuses: [{ id: "qa", workspace_id: "ws1", key: "qa", name: "QA", description: "",
+ category: "started", color: "#123456", icon: null, is_system: false,
+ position: 0, archived_at: null, created_at: "", updated_at: "" }],
+ categories: ["unstarted", "started", "done", "closed"], total: 1,
+ });
+ const { result } = renderHook(
+ () => useTabPresentation(`/acme/issues/${issue.id}`, undefined, { fetch: true }), { wrapper },
+ );
+ await waitFor(() => expect(result.current.visual).toMatchObject({
+ status: "qa", category: "started", color: "#123456", icon: null,
+ }));
+ });
+
+ it("keeps the server category when the catalog is unavailable", async () => {
+ getIssue.mockResolvedValue({ ...issue, status: "qa" });
+ listIssueStatuses.mockRejectedValue(new Error("offline"));
+ const { result } = renderHook(
+ () => useTabPresentation(`/acme/issues/${issue.id}`, undefined, { fetch: true }), { wrapper },
+ );
+ await waitFor(() => expect(result.current.visual).toMatchObject({ status: "qa", category: "started" }));
+ });
+
+ it("stays cache-only unless fetching is requested", async () => {
+ const { result } = renderHook(() => useTabPresentation(`/acme/issues/${issue.id}`, "Saved"), { wrapper });
+ await act(async () => {});
+ expect(getIssue).not.toHaveBeenCalled();
+ expect(listIssueStatuses).not.toHaveBeenCalled();
+ expect(result.current.title).toBe("Saved");
+ });
+
+ it("waits for the workspace before starting requests", async () => {
+ ws.current = null;
+ const { result, rerender } = renderHook(
+ () => useTabPresentation(`/acme/issues/${issue.id}`, "Saved", { fetch: true }), { wrapper },
+ );
+ await act(async () => {});
+ expect(getIssue).not.toHaveBeenCalled();
+ expect(listIssueStatuses).not.toHaveBeenCalled();
+ ws.current = { id: "ws1", slug: "acme" };
+ rerender();
+ await waitFor(() => expect(result.current.title).toBe("MUL-7: Restore tabs"));
+ expect(getIssue).toHaveBeenCalledTimes(1);
+ });
+
+ it("only fetches inbox selections known to reference an issue", async () => {
+ qc.setQueryData(inboxListOptions("ws1").queryKey, [{
+ id: "n1", workspace_id: "ws1", recipient_type: "member", recipient_id: "u1",
+ actor_type: null, actor_id: null, type: "issue_assigned", severity: "info",
+ issue_id: issue.id, title: "Assigned to you", body: null, issue_status: "in_progress",
+ read: false, archived: false, created_at: issue.created_at, details: null,
+ }]);
+ const { result } = renderHook(
+ () => useTabPresentation(`/acme/inbox?issue=${issue.id}`, "Saved", { fetch: true }), { wrapper },
+ );
+ await waitFor(() => expect(result.current.title).toBe("MUL-7: Restore tabs"));
+ expect(getIssue).toHaveBeenCalledExactlyOnceWith(issue.id);
+ });
+
+ it.each(["n2", "unknown-notification"])("does not query an issue for the notification %s", async (key) => {
+ seed(qc);
+ renderHook(() => useTabPresentation(`/acme/inbox?issue=${key}`, "Saved", { fetch: true }), { wrapper });
+ await act(async () => {});
+ expect(getIssue).not.toHaveBeenCalled();
+ });
+
+ it.each([new Error("offline"), new ApiError("Not found", 404, "Not Found")])("preserves the title and unresolved status when the request fails: %s", async (error) => {
+ getIssue.mockRejectedValue(error);
+ const { result } = renderHook(
+ () => useTabPresentation(`/acme/issues/${issue.id}`, "Saved", { fetch: true }), { wrapper },
+ );
+ await waitFor(() => expect(qc.getQueryState(issueDetailOptions("ws1", issue.id).queryKey)?.status).toBe("error"));
+ expect(result.current).toMatchObject({ title: "Saved", titleResolved: false, visual: { status: null } });
+ expect(getIssue).toHaveBeenCalledTimes(1);
+ });
+
+ it("refreshes a background tab after reconnect invalidation", async () => {
+ const { result } = renderHook(
+ () => useTabPresentation(`/acme/issues/${issue.id}`, undefined, { fetch: true }), { wrapper },
+ );
+ await waitFor(() => expect(result.current.title).toBe("MUL-7: Restore tabs"));
+ getIssue.mockResolvedValue({ ...issue, title: "Changed while offline", status: "done", status_category: "done" });
+ await act(() => qc.invalidateQueries({ queryKey: ["issues", "ws1"] }));
+ await waitFor(() => expect(result.current.title).toBe("MUL-7: Changed while offline"));
+ expect(result.current.visual).toMatchObject({ status: "done", category: "done" });
+ });
+});
diff --git a/packages/views/layout/tab-presentation.tsx b/packages/views/layout/tab-presentation.tsx
index 889824125c..363cc39243 100644
--- a/packages/views/layout/tab-presentation.tsx
+++ b/packages/views/layout/tab-presentation.tsx
@@ -13,7 +13,7 @@ import {
type TabEntityData,
type TabLabelKey,
} from "@multica/core/paths";
-import { issueDetailOptions } from "@multica/core/issues/queries";
+import { useCanonicalIssue } from "@multica/core/issues/canonical-id";
import { projectDetailOptions } from "@multica/core/projects/queries";
import { autopilotDetailOptions } from "@multica/core/autopilots/queries";
import {
@@ -32,6 +32,7 @@ import {
} from "@multica/core/inbox/queries";
import { useInboxFilters } from "@multica/core/inbox/filter-store";
import { cn } from "@multica/ui/lib/utils";
+import { Skeleton } from "@multica/ui/components/ui/skeleton";
import { StatusIcon } from "../issues/components";
import { ProjectIcon } from "../projects/components/project-icon";
import { ActorAvatar } from "../common/actor-avatar";
@@ -44,12 +45,10 @@ import { ROUTE_ICON_COMPONENTS } from "./route-icon-components";
* live from the query cache. This is the view half of the contract whose pure
* core is `@multica/core/paths` (`parseTabSubject` + `resolveTabPresentation`).
*
- * Cache-only reads: every query in `useTabEntityData` is `enabled: false`. It
- * observes whatever the pages/directory already loaded and re-renders when that
- * data changes, so an open tab's icon/title stay in sync (project renamed,
- * issue status changed, chat session retitled) without amplifying requests. A
- * resource that has not loaded yet renders a stable type fallback until its
- * page fills the cache.
+ * Reads are cache-only by default. The desktop tab strip opts into fetching
+ * issue details and the status catalog so restored background tabs resolve
+ * without mounting their pages. Other resources observe the pages' caches and
+ * keep their type fallback until those pages load.
*
* The one exception is an actor tab's avatar: `ResourceLeadingVisual` renders
* `ActorAvatar`, which loads the (workspace-global, sidebar-warmed) member /
@@ -75,8 +74,7 @@ const PENDING_RESOURCE_KEYS: ReadonlySet<TabLabelKey> = new Set<TabLabelKey>([
"runtime",
]);
-/** Gather cached entity data for a subject. All reads are cache-only. */
-function useTabEntityData(subject: TabSubject, wsId: string): TabEntityData {
+function useTabEntityData(subject: TabSubject, wsId: string, fetch: boolean): TabEntityData {
const { t: chatT } = useT("chat");
// Read both inbox lists cache-only; the archived view keeps its own list, so
@@ -117,20 +115,13 @@ function useTabEntityData(subject: TabSubject, wsId: string): TabEntityData {
: subject.kind === "inbox"
? (subject.selectedKey ?? "")
: "";
- // An issue tab's URL segment may be a human-readable identifier (`MUL-123`).
- // The route seeds that entry when it resolves, but only the UUID-keyed entry
- // receives realtime patches — so hop through it, or a tab opened by
- // identifier would freeze on the title and status it had when first opened.
- // Both reads stay cache-only, and a UUID segment resolves to itself.
- const rawIssue = useQuery({
- ...issueDetailOptions(wsId, issueId || NONE),
- enabled: false,
- }).data;
- const issue =
- useQuery({
- ...issueDetailOptions(wsId, rawIssue?.id || NONE),
- enabled: false,
- }).data ?? rawIssue;
+ // An inbox key can name an issue-less notification. Only fetch known
+ // issue-backed rows; unknown selections can still resolve from cache.
+ // The canonical query seeds/subscribes to the UUID entry even when the URL
+ // uses an identifier, so background tabs receive realtime patches too.
+ const { issue } = useCanonicalIssue(wsId, issueId, {
+ enabled: fetch && (subject.kind === "issue" || !!inboxItem?.issue_id),
+ });
const project = useQuery({
...projectDetailOptions(wsId, subject.kind === "project" ? subject.id : NONE),
@@ -162,6 +153,7 @@ function useTabEntityData(subject: TabSubject, wsId: string): TabEntityData {
identifier: issue.identifier,
title: issue.title,
status: issue.status,
+ status_category: issue.status_category,
};
}
break;
@@ -258,6 +250,8 @@ function useTabTitle(
export interface TabPresentationResult {
visual: TabVisual;
title: string;
+ /** False while a resource title is only a type label or persisted fallback. */
+ titleResolved: boolean;
}
/**
@@ -270,19 +264,24 @@ export interface TabPresentationResult {
export function useTabPresentation(
url: string,
fallbackTitle?: string,
+ { fetch = false }: { fetch?: boolean } = {},
): TabPresentationResult {
const subject = useMemo(() => parseTabSubject(url), [url]);
const ws = useCurrentWorkspace();
const wsId = ws?.id ?? "";
- const data = useTabEntityData(subject, wsId);
- const statuses = useQuery({ ...issueStatusListOptions(wsId), enabled: false }).data;
+ const data = useTabEntityData(subject, wsId, fetch);
+ const statuses = useQuery({
+ ...issueStatusListOptions(wsId),
+ enabled: fetch && !!wsId && subject.kind === "issue",
+ }).data;
const catalog = useMemo(() => buildIssueStatusCatalog(statuses), [statuses]);
const { visual, title: titleSpec } = resolveTabPresentation(subject, data);
- // A selected notification whose identity has not resolved from cache yet is
+ // A selected notification or chat session not resolved from cache yet is
// pending in exactly the sense a not-yet-loaded issue is — keep the tab's
// persisted title instead of collapsing it to the bare container label.
const selectionPending =
- subject.kind === "inbox" && !!subject.selectedKey && !data.inboxSelection;
+ (subject.kind === "inbox" && !!subject.selectedKey && !data.inboxSelection) ||
+ (subject.kind === "chat" && !!subject.sessionId && !data.chatSessionTitle);
const title = useTabTitle(titleSpec, fallbackTitle, selectionPending);
// The actor avatar resolves through workspace directory queries and throws
@@ -302,9 +301,16 @@ export function useTabPresentation(
return {
visual: safeVisual.kind === "issue-status" && safeVisual.status && catalog.entryOf(safeVisual.status)?.is_system === false
- ? { ...safeVisual, color: catalog.colorOf(safeVisual.status), icon: catalog.iconOf(safeVisual.status) }
+ ? {
+ ...safeVisual,
+ category: safeVisual.category ?? catalog.categoryOf(safeVisual.status),
+ color: catalog.colorOf(safeVisual.status),
+ icon: catalog.iconOf(safeVisual.status),
+ }
: safeVisual,
title,
+ titleResolved: !selectionPending &&
+ (titleSpec.kind !== "tab" || !PENDING_RESOURCE_KEYS.has(titleSpec.tabKey)),
};
}
@@ -329,10 +335,11 @@ export function ResourceLeadingVisual({
break;
}
case "issue-status":
- // A null status (loading) renders StatusIcon's neutral fallback glyph.
- inner = (
+ inner = visual.status === null ? (
+ <Skeleton aria-hidden className="size-3 rounded-sm" />
+ ) : (
<StatusIcon
- status={visual.status ?? ""}
+ status={visual.status}
category={visual.category}
color={visual.color}
icon={visual.icon}