Skip to content

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

Go

fix(issues): close the blocker picker without waiting for a workspace-wide refetch (MUL-10169) (#11534)

Bohan Jiang4b6f50de6138
diff --git a/packages/core/issues/blockers.test.tsx b/packages/core/issues/blockers.test.tsx
new file mode 100644
index 0000000000..b4f6cdba15
--- /dev/null
+++ b/packages/core/issues/blockers.test.tsx
@@ -0,0 +1,69 @@
+/**
+ * @vitest-environment jsdom
+ */
+import { describe, expect, it, vi } from "vitest";
+import { act, renderHook } from "@testing-library/react";
+import { QueryClient, QueryClientProvider, useQuery } from "@tanstack/react-query";
+import type { ReactNode } from "react";
+
+import { setApiInstance } from "../api";
+import type { ApiClient } from "../api/client";
+import { useUpdateIssueBlockers, useUpdateIssueBlocking } from "./blockers";
+import { issueKeys } from "./queries";
+
+const WS_ID = "ws-1";
+
+// A blocker write must settle once the open issue's detail is fresh, without
+// waiting for every other issue query in the workspace (MUL-10169).
+function setup() {
+ const updateIssue = vi.fn(async () => ({ id: "issue-1" }));
+ setApiInstance({ updateIssue } as unknown as ApiClient);
+ const qc = new QueryClient({ defaultOptions: { queries: { retry: false, staleTime: Infinity } } });
+ const wrapper = ({ children }: { children: ReactNode }) => (
+ <QueryClientProvider client={qc}>{children}</QueryClientProvider>
+ );
+
+ const detailFetch = vi.fn(async () => ({ id: "issue-1" }));
+ let releaseList: () => void = () => {};
+ const listFetch = vi.fn(
+ () => new Promise<string[]>((resolve) => { releaseList = () => resolve([]); }),
+ );
+ // Mounted observers, so invalidation refetches both queries.
+ renderHook(() => {
+ useQuery({ queryKey: issueKeys.detail(WS_ID, "issue-1"), queryFn: detailFetch });
+ useQuery({ queryKey: issueKeys.list(WS_ID), queryFn: listFetch });
+ }, { wrapper });
+
+ return { qc, wrapper, updateIssue, detailFetch, listFetch, releaseList: () => releaseList() };
+}
+
+describe("blocker write hooks", () => {
+ it("adding a blocker settles after the detail refetch, not the workspace-wide one", async () => {
+ const { wrapper, updateIssue, detailFetch, listFetch, releaseList } = setup();
+ await vi.waitFor(() => expect(listFetch).toHaveBeenCalledTimes(1));
+ releaseList();
+ await vi.waitFor(() => expect(detailFetch).toHaveBeenCalledTimes(1));
+
+ const { result } = renderHook(() => useUpdateIssueBlockers(WS_ID, "issue-1"), { wrapper });
+ await act(() => result.current.mutateAsync({ blocked_by: ["blocker-1"] }));
+
+ expect(updateIssue).toHaveBeenCalledWith("issue-1", { blocked_by: ["blocker-1"] });
+ expect(detailFetch).toHaveBeenCalledTimes(2);
+ // The list refetch started but is still out: the write did not wait for it.
+ expect(listFetch).toHaveBeenCalledTimes(2);
+ });
+
+ it("blocking another issue writes on that issue and refreshes this one's detail", async () => {
+ const { wrapper, updateIssue, detailFetch, listFetch, releaseList } = setup();
+ await vi.waitFor(() => expect(listFetch).toHaveBeenCalledTimes(1));
+ releaseList();
+ await vi.waitFor(() => expect(detailFetch).toHaveBeenCalledTimes(1));
+
+ const { result } = renderHook(() => useUpdateIssueBlocking(WS_ID, "issue-1"), { wrapper });
+ await act(() => result.current.mutateAsync({ dependentId: "dependent-1" }));
+
+ expect(updateIssue).toHaveBeenCalledWith("dependent-1", { blocked_by: ["issue-1"] });
+ expect(detailFetch).toHaveBeenCalledTimes(2);
+ expect(listFetch).toHaveBeenCalledTimes(2);
+ });
+});
diff --git a/packages/core/issues/blockers.ts b/packages/core/issues/blockers.ts
index c8d7575962..c4287e0197 100644
--- a/packages/core/issues/blockers.ts
+++ b/packages/core/issues/blockers.ts
@@ -1,14 +1,33 @@
-import { useMutation, useQueryClient } from "@tanstack/react-query";
+import { useMutation, useQueryClient, type QueryClient } from "@tanstack/react-query";
import { api } from "../api";
import { issueKeys } from "./queries";
+/**
+ * Settles a blocker write. Only the open issue's detail, where the Relations
+ * section reads the edge, is awaited, so the picker closes showing the saved
+ * edge. Every other issue query (lists, board, table, the other end of the
+ * edge) refetches in the background: awaiting them held the picker open for
+ * seconds on a busy workspace (MUL-10169).
+ */
+function refreshAfterBlockerWrite(qc: QueryClient, wsId: string, issueId: string): Promise<void> {
+ const detailKey = issueKeys.detail(wsId, issueId);
+ const detail = qc.invalidateQueries({ queryKey: detailKey, exact: true });
+ void qc.invalidateQueries({
+ queryKey: issueKeys.all(wsId),
+ predicate: (query) => !isSameKey(query.queryKey, detailKey),
+ });
+ return detail;
+}
+
+function isSameKey(a: readonly unknown[], b: readonly unknown[]): boolean {
+ return a.length === b.length && a.every((part, i) => part === b[i]);
+}
+
export function useUpdateIssueBlockers(wsId: string, issueId: string) {
const qc = useQueryClient();
return useMutation({
mutationFn: (change: { blocked_by?: string[]; remove_blocked_by?: string[] }) => api.updateIssue(issueId, change),
- onSuccess: async () => {
- await qc.invalidateQueries({ queryKey: issueKeys.all(wsId) });
- },
+ onSuccess: () => refreshAfterBlockerWrite(qc, wsId, issueId),
});
}
@@ -21,8 +40,6 @@ export function useUpdateIssueBlocking(wsId: string, issueId: string) {
return useMutation({
mutationFn: ({ dependentId, remove = false }: { dependentId: string; remove?: boolean }) =>
api.updateIssue(dependentId, remove ? { remove_blocked_by: [issueId] } : { blocked_by: [issueId] }),
- onSuccess: async () => {
- await qc.invalidateQueries({ queryKey: issueKeys.all(wsId) });
- },
+ onSuccess: () => refreshAfterBlockerWrite(qc, wsId, issueId),
});
}
diff --git a/packages/views/modals/issue-picker-modal.test.tsx b/packages/views/modals/issue-picker-modal.test.tsx
index c4160488c2..06f45279d1 100644
--- a/packages/views/modals/issue-picker-modal.test.tsx
+++ b/packages/views/modals/issue-picker-modal.test.tsx
@@ -80,3 +80,32 @@ describe("IssuePickerModal isSelectable", () => {
expect(screen.queryByText("Tap targets too small on iPhone")).toBeNull();
});
});
+
+// A picker that stays open on select (adding a blocker) must show the click
+// landed while the write is out, instead of looking frozen (MUL-10169).
+describe("IssuePickerModal pending select", () => {
+ it("marks the clicked row busy while the caller's write is in flight", () => {
+ const onSelect = vi.fn();
+ const props = {
+ open: true,
+ onOpenChange: () => {},
+ title: "Wait for another task",
+ description: "Pick a blocker",
+ excludeIds: [],
+ closeOnSelect: false,
+ suggestions: [{ key: "recent", heading: "Recently viewed", issues: [ORIGINAL] }],
+ onSelect,
+ };
+ const { rerender } = renderWithI18n(<IssuePickerModal {...props} />);
+ expect(screen.queryByRole("status")).toBeNull();
+
+ fireEvent.click(screen.getByText("Tap targets too small"));
+ expect(onSelect).toHaveBeenCalledWith(ORIGINAL);
+ rerender(<IssuePickerModal {...props} pending />);
+ expect(screen.getByRole("status")).toBeTruthy();
+
+ // A second click while pending is ignored.
+ fireEvent.click(screen.getByText("Tap targets too small"));
+ expect(onSelect).toHaveBeenCalledTimes(1);
+ });
+});
diff --git a/packages/views/modals/issue-picker-modal.tsx b/packages/views/modals/issue-picker-modal.tsx
index 227168c45d..c65592e9d8 100644
--- a/packages/views/modals/issue-picker-modal.tsx
+++ b/packages/views/modals/issue-picker-modal.tsx
@@ -15,6 +15,7 @@ import {
CommandGroup,
CommandItem,
} from "@multica/ui/components/ui/command";
+import { Spinner } from "@multica/ui/components/ui/spinner";
import { StatusIcon } from "../issues/components/status-icon";
import { useT } from "../i18n";
@@ -61,6 +62,9 @@ export function IssuePickerModal({
const [query, setQuery] = useState("");
const [results, setResults] = useState<Issue[]>([]);
const [isLoading, setIsLoading] = useState(false);
+ // The row whose write is in flight, so a picker that stays open on select
+ // shows where the click landed until the caller closes it.
+ const [selectedId, setSelectedId] = useState<string | null>(null);
const debounceRef = useRef<ReturnType<typeof setTimeout>>(undefined);
const abortRef = useRef<AbortController>(undefined);
const selectable = useCallback(
@@ -120,6 +124,7 @@ export function IssuePickerModal({
value={issue.id}
onSelect={() => {
if (pending) return;
+ setSelectedId(issue.id);
onSelect(issue);
if (closeOnSelect) onOpenChange(false);
}}
@@ -133,6 +138,7 @@ export function IssuePickerModal({
/>
<span className="text-muted-foreground shrink-0">{issue.identifier}</span>
<span className="truncate">{issue.title}</span>
+ {pending && selectedId === issue.id && <Spinner className="ml-auto size-3.5 shrink-0 text-muted-foreground" />}
</CommandItem>
);
@@ -145,6 +151,7 @@ export function IssuePickerModal({
setQuery("");
setResults([]);
setIsLoading(false);
+ setSelectedId(null);
}
onOpenChangeComplete?.(nextOpen);
}}
@@ -161,7 +168,7 @@ export function IssuePickerModal({
}}
/>
{error && <p role="alert" className="px-3 py-2 text-caption text-destructive">{error}</p>}
- <CommandList>
+ <CommandList aria-busy={pending || undefined}>
{isLoading && (
<div className="py-6 text-center text-body text-muted-foreground">
{t(($) => $.issue_picker.searching)}