Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(projects): refresh progress by label when labels change (#11473)
pseudoyu10bc04473b0c
diff --git a/packages/core/issues/ws-updaters.test.ts b/packages/core/issues/ws-updaters.test.tsindex 1aff05847d..776784537f 100644--- a/packages/core/issues/ws-updaters.test.ts+++ b/packages/core/issues/ws-updaters.test.ts@@ -170,6 +170,18 @@ describe("onIssueLabelsChanged", () => {qc = new QueryClient();});+ it.each([undefined, 2])("refreshes project progress, which counts issues by label (revision %s)", (revision) => {+ const progressKey = projectKeys.progress(WS_ID, PROJECT_ID);+ const membersKey = projectKeys.members(WS_ID, PROJECT_ID);+ qc.setQueryData(progressKey, { by_label: [] });+ qc.setQueryData(membersKey, []);++ onIssueLabelsChanged(qc, WS_ID, ISSUE_ID, [labelB], revision);++ expect(qc.getQueryState(progressKey)?.isInvalidated).toBe(true);+ expect(qc.getQueryState(membersKey)?.isInvalidated).toBe(false);+ });+it("patches the per-issue label cache when present (LabelPicker source)", () => {qc.setQueryData<IssueLabelsResponse>(labelKeys.byIssue(WS_ID, ISSUE_ID), {labels: [labelA],diff --git a/packages/core/issues/ws-updaters.ts b/packages/core/issues/ws-updaters.tsindex d077a510e0..48ea33c787 100644--- a/packages/core/issues/ws-updaters.ts+++ b/packages/core/issues/ws-updaters.ts@@ -556,6 +556,14 @@ export function onIssueUpdated(* remounts — `staleTime: Infinity` + `refetchOnWindowFocus: false` (see* `query-client.ts`) means focus changes won't recover it.*/+/** Progress counts issues by label, and a label event doesn't name the project. */+export function invalidateProjectProgress(qc: QueryClient, wsId: string) {+ qc.invalidateQueries({+ queryKey: projectKeys.all(wsId),+ predicate: ({ queryKey }) => queryKey[2] === "detail" && queryKey[4] === "progress",+ });+}+export function onIssueLabelsChanged(qc: QueryClient,wsId: string,@@ -566,6 +574,7 @@ export function onIssueLabelsChanged(// Runs after the change is committed (event or mutation success), so the// archive can be asked again; the optimistic patch below cannot.void refreshArchivedInboxMatches(qc, wsId);+ invalidateProjectProgress(qc, wsId);if (refetchForUnversionedIssueEvent(qc, wsId, issueId, revision)) {qc.invalidateQueries({ queryKey: labelKeys.byIssue(wsId, issueId) });return;diff --git a/packages/core/realtime/use-realtime-sync-project-activity.test.tsx b/packages/core/realtime/use-realtime-sync-project-activity.test.tsxindex 411eaaf446..d9df3cff0d 100644--- a/packages/core/realtime/use-realtime-sync-project-activity.test.tsx+++ b/packages/core/realtime/use-realtime-sync-project-activity.test.tsx@@ -8,7 +8,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";import { setApiInstance } from "../api";import type { ApiClient } from "../api/client";import type { WSClient } from "../api/ws-client";-import { projectListOptions } from "../projects/queries";+import { projectKeys, projectListOptions } from "../projects/queries";import type { Project } from "../types";import { useRealtimeSync, type RealtimeSyncStores } from "./use-realtime-sync";@@ -26,15 +26,19 @@ vi.mock("../paths", () => ({function createRecordingWs() {const handlers: Record<string, (p: unknown) => void> = {};+ const anyHandlers: ((msg: { type: string; payload: unknown }) => void)[] = [];const ws = {on: vi.fn((event: string, handler: (p: unknown) => void) => {handlers[event] = handler;return () => {};}),- onAny: vi.fn(() => () => {}),+ onAny: vi.fn((handler: (msg: { type: string; payload: unknown }) => void) => {+ anyHandlers.push(handler);+ return () => {};+ }),onReconnect: vi.fn(() => () => {}),} as unknown as WSClient;- return { ws, handlers };+ return { ws, handlers, anyHandlers };}const stores = {@@ -63,7 +67,7 @@ describe("useRealtimeSync — project recent activity", () => {let listProjects: ReturnType<typeof vi.fn>;function mount() {- const { ws, handlers } = createRecordingWs();+ const { ws, handlers, anyHandlers } = createRecordingWs();const view = renderHook(() => {useRealtimeSync(ws, stores);@@ -75,7 +79,7 @@ describe("useRealtimeSync — project recent activity", () => {),},);- return { ...view, handlers };+ return { ...view, handlers, anyHandlers };}beforeEach(() => {@@ -120,4 +124,16 @@ describe("useRealtimeSync — project recent activity", () => {});await waitFor(() => expect(listProjects).toHaveBeenCalledTimes(2), { timeout: 3000 });});++ it("refreshes project progress when a label is deleted", async () => {+ const { anyHandlers } = mount();+ const progressKey = projectKeys.progress("ws-1", "project-1");+ qc.setQueryData(progressKey, { by_label: [] });++ act(() => {+ for (const handler of anyHandlers) handler({ type: "label:deleted", payload: { label_id: "label-1" } });+ });++ await waitFor(() => expect(qc.getQueryState(progressKey)?.isInvalidated).toBe(true));+ });});diff --git a/packages/core/realtime/use-realtime-sync.ts b/packages/core/realtime/use-realtime-sync.tsindex 1103beef75..d2b5309bf0 100644--- a/packages/core/realtime/use-realtime-sync.ts+++ b/packages/core/realtime/use-realtime-sync.ts@@ -62,6 +62,7 @@ import {onIssueReactionAdded,onIssueReactionRemoved,invalidateIssueOwnerProjections,+ invalidateProjectProgress,} from "../issues/ws-updaters";import {invalidateLastActivitySortedIssueLists,@@ -989,6 +990,7 @@ export function useRealtimeSync(if (wsId) {qc.invalidateQueries({ queryKey: ["labels", wsId] });qc.invalidateQueries({ queryKey: issueKeys.all(wsId) });+ invalidateProjectProgress(qc, wsId);qc.invalidateQueries({ queryKey: workspaceKeys.agents(wsId) });qc.invalidateQueries({ queryKey: workspaceKeys.skills(wsId) });}