Skip to content

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

Go

fix(layout): drop a stale inbox selection from the rail's Inbox link (#10103)

Jean Woodc559a613343c
diff --git a/packages/views/layout/app-rail.test.tsx b/packages/views/layout/app-rail.test.tsx
index 7ef5442d7a..3e55e5d0c7 100644
--- a/packages/views/layout/app-rail.test.tsx
+++ b/packages/views/layout/app-rail.test.tsx
@@ -1,5 +1,5 @@
import type { ReactNode } from "react";
-import { act, fireEvent, screen, within } from "@testing-library/react";
+import { act, fireEvent, screen, waitFor, within } from "@testing-library/react";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { useRailOrderStore } from "@multica/core/navigation";
@@ -7,9 +7,12 @@ import { SidebarProvider, useSidebar } from "@multica/ui/components/ui/sidebar";
import { renderWithI18n } from "../test/i18n";
import { AppRail } from "./app-rail";
import { AppShellProvider, useAppShell } from "./app-shell-context";
+import type { InboxItem } from "@multica/core/types";
const state = vi.hoisted(() => ({
pathname: "/acme/issues",
+ search: "",
+ inboxItems: undefined as InboxItem[] | undefined,
appForeground: true,
inboxUnread: 0,
chatSessions: [] as { id: string; unread_count?: number }[],
@@ -28,7 +31,11 @@ vi.mock("../navigation", () => ({
{children}
</a>
),
- useNavigation: () => ({ pathname: state.pathname, push: vi.fn() }),
+ useNavigation: () => ({
+ pathname: state.pathname,
+ searchParams: new URLSearchParams(state.search),
+ push: vi.fn(),
+ }),
}));
vi.mock("@multica/core/paths", async (importOriginal) => {
const actual = await importOriginal<typeof import("@multica/core/paths")>();
@@ -38,9 +45,14 @@ vi.mock("@multica/core/paths", async (importOriginal) => {
useWorkspacePaths: () => actual.paths.workspace("acme"),
};
});
-vi.mock("@multica/core/inbox/queries", () => ({
- useInboxUnreadCount: () => state.inboxUnread,
-}));
+vi.mock("@multica/core/inbox/queries", async (importOriginal) => {
+ const actual = await importOriginal<typeof import("@multica/core/inbox/queries")>();
+ return {
+ deduplicateInboxItems: actual.deduplicateInboxItems,
+ inboxListOptions: actual.inboxListOptions,
+ useInboxUnreadCount: () => state.inboxUnread,
+ };
+});
vi.mock("@multica/core/chat/queries", () => ({
chatSessionsOptions: (wsId: string) => ({
queryKey: ["chat", wsId, "sessions"],
@@ -82,7 +94,8 @@ function renderRail(children?: ReactNode, rail: ReactNode = <AppRail />) {
defaultOptions: { queries: { retry: false, staleTime: Infinity } },
});
client.setQueryData(["chat", "ws-1", "sessions"], state.chatSessions);
- return renderWithI18n(
+ if (state.inboxItems) client.setQueryData(["inbox", "ws-1", "list"], state.inboxItems);
+ const tree = () => (
<QueryClientProvider client={client}>
<SidebarProvider>
<AppShellProvider>
@@ -91,8 +104,15 @@ function renderRail(children?: ReactNode, rail: ReactNode = <AppRail />) {
{children}
</AppShellProvider>
</SidebarProvider>
- </QueryClientProvider>,
+ </QueryClientProvider>
);
+ const result = renderWithI18n(tree());
+ const visit = (pathname: string, search = "") => {
+ state.pathname = pathname;
+ state.search = search;
+ result.rerender(tree());
+ };
+ return { ...result, client, visit };
}
const link = (href: string) => document.querySelector<HTMLAnchorElement>(`a[href="${href}"]`);
@@ -100,6 +120,8 @@ const countBadge = (href: string) => link(href)?.querySelector("number-flow-reac
beforeEach(() => {
state.pathname = "/acme/issues";
+ state.search = "";
+ state.inboxItems = undefined;
state.appForeground = true;
state.inboxUnread = 0;
state.chatSessions = [];
@@ -208,6 +230,58 @@ describe("AppRail label disclosure", () => {
});
});
+function inboxItem(issueId: string, archived = false): InboxItem {
+ return {
+ id: `inbox-${issueId}`, workspace_id: "ws-1", recipient_type: "member",
+ recipient_id: "member-1", actor_type: "agent", actor_id: "agent-1",
+ type: "new_comment", severity: "info", issue_id: issueId,
+ title: "Issue title", body: null, issue_status: "done", issue_priority: "none",
+ read: true, archived, created_at: "2026-11-01T08:00:00Z", details: null,
+ };
+}
+
+// Read by space: an href query string trips the attribute-selector lookup.
+const inboxHref = () => document.querySelector('a[data-space="inbox"]')?.getAttribute("href");
+
+describe("AppRail inbox return", () => {
+ it("returns to the notification last opened while it is still in the inbox", () => {
+ state.inboxItems = [inboxItem("issue-x")];
+ const { visit } = renderRail();
+ visit("/acme/inbox", "issue=issue-x");
+ visit("/acme/issues/issue-x");
+ expect(inboxHref()).toBe("/acme/inbox?issue=issue-x");
+ });
+
+ // Regression: the inbox page replaces an unknown ?issue= with the issue
+ // itself, so a remembered selection that was archived since turned the
+ // Inbox item into a flash back to the issue on every click.
+ it("drops a remembered notification that has left the inbox", async () => {
+ state.inboxItems = [inboxItem("issue-x")];
+ const { client, visit } = renderRail();
+ visit("/acme/inbox", "issue=issue-x");
+ visit("/acme/issues/issue-x");
+ act(() => {
+ client.setQueryData(["inbox", "ws-1", "list"], [inboxItem("issue-x", true), inboxItem("issue-y")]);
+ });
+ await waitFor(() => expect(inboxHref()).toBe("/acme/inbox"));
+ });
+
+ it("leaves the selection to the inbox page when its list is not cached", () => {
+ const { visit } = renderRail();
+ visit("/acme/inbox", "issue=issue-x");
+ visit("/acme/issues/issue-x");
+ expect(inboxHref()).toBe("/acme/inbox?issue=issue-x");
+ });
+
+ it("keeps an archived-view selection, which resolves against its own list", () => {
+ state.inboxItems = [];
+ const { visit } = renderRail();
+ visit("/acme/inbox", "view=archived&issue=issue-x");
+ visit("/acme/issues/issue-x");
+ expect(inboxHref()).toBe("/acme/inbox?view=archived&issue=issue-x");
+ });
+});
+
describe("AppRail badges", () => {
it("counts inbox unread with a static counter", () => {
state.inboxUnread = 4;
diff --git a/packages/views/layout/app-rail.tsx b/packages/views/layout/app-rail.tsx
index 440a3d8923..90d5b1c7fa 100644
--- a/packages/views/layout/app-rail.tsx
+++ b/packages/views/layout/app-rail.tsx
@@ -18,7 +18,11 @@ import { toast } from "sonner";
import { useChatStore } from "@multica/core/chat";
import { chatSessionsOptions } from "@multica/core/chat/queries";
import { countUnreadChatMessages } from "@multica/core/chat/unread";
-import { useInboxUnreadCount } from "@multica/core/inbox/queries";
+import {
+ deduplicateInboxItems,
+ inboxListOptions,
+ useInboxUnreadCount,
+} from "@multica/core/inbox/queries";
import { useMarkAllInboxRead } from "@multica/core/inbox/mutations";
import { resolveRailOrder, useRailOrderStore } from "@multica/core/navigation";
import {
@@ -127,6 +131,30 @@ function RailBadgeMark({ badge }: { badge: RailBadge }) {
);
}
+/**
+ * The Inbox item returns to the last notification opened there. Once that
+ * notification has left the active list (archived here, on another device, or
+ * by the server), the Inbox page treats `?issue=` as a shared link and
+ * replaces itself with the issue, so the click looks like it did nothing.
+ * Drop a selection the cached list no longer holds; with no cached list the
+ * page still decides.
+ */
+function useInboxReturnHref(href: string, wsId: string | undefined): string {
+ const { data: items } = useQuery({ ...inboxListOptions(wsId ?? ""), enabled: false });
+ return useMemo(() => {
+ const queryAt = href.indexOf("?");
+ if (!items || queryAt < 0) return href;
+ const params = new URLSearchParams(href.slice(queryAt + 1));
+ const key = params.get("issue");
+ if (!key || params.has("view")) return href;
+ if (deduplicateInboxItems(items).some((item) => (item.issue_id ?? item.id) === key)) return href;
+ params.delete("issue");
+ const query = params.toString();
+ const path = href.slice(0, queryAt);
+ return query ? `${path}?${query}` : path;
+ }, [href, items]);
+}
+
/** Hover previews of a collapsed nav. Mouse only: a touch tap navigates. */
function usePeekHandlers(space: AppSpaceId, peekable: boolean) {
const shell = useAppShell();
@@ -306,6 +334,8 @@ export function AppRail({
const shell = useAppShell();
const badges = useRailBadges();
const space = shell?.space ?? null;
+ const wsId = useCurrentWorkspace()?.id;
+ const inboxHref = useInboxReturnHref(shell?.spaceHref("inbox", p.inbox()) ?? p.inbox(), wsId);
const settingsPeek = usePeekHandlers("settings", space === "settings");
const savedOrder = useRailOrderStore((s) => s.order);
const setOrder = useRailOrderStore((s) => s.setOrder);
@@ -397,7 +427,7 @@ export function AppRail({
<RailSpaceLink
space={id}
{...items[id]}
- href={shell?.spaceHref(id, items[id].href) ?? items[id].href}
+ href={id === "inbox" ? inboxHref : (shell?.spaceHref(id, items[id].href) ?? items[id].href)}
active={space === id}
badge={badges[id]}
/>