⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
fix: address verified delivery and concurrency review findings
Tin8e776680e1ee
diff --cc apps/web/src/components/kanban-board/index.tsxindex 8dbe059cb,6c40a8375..aca9c31b1--- a/apps/web/src/components/kanban-board/index.tsx+++ b/apps/web/src/components/kanban-board/index.tsx@@@ -180,11 -174,13 +180,15 @@@ function KanbanBoard(const moved = moveBoardTask(canonical, activeId, overId, sortedByNumber);if (!moved || !moved.tasks.length) return;+ for (const task of moved.tasks)+ markBoardCacheChanged(queryClient, project.id, task.id);setProject(moved.project);queryClient.setQueryData(["tasks", project.id], moved.project);- reorder({ projectId: project.id, tasks: moved.tasks });+ reorder({+ projectId: project.id,+ tasks: moved.tasks,+ expectedTasks: moved.expectedTasks,+ });};if (!project?.columns) {diff --cc apps/web/src/hooks/use-project-websocket-cache.test.tsxindex 206f7a2c2,000000000..44aa566ebmode 100644,000000..100644--- a/apps/web/src/hooks/use-project-websocket-cache.test.tsx+++ b/apps/web/src/hooks/use-project-websocket-cache.test.tsx@@@ -1,200 -1,0 +1,279 @@@+import { cleanup, renderHook } from "@testing-library/react";+import {+ afterEach,+ beforeEach,+ describe,+ expect,+ it,+ vi,+} from "vite-plus/test";+import { useProjectWebSocket } from "./use-project-websocket";++const mocks = vi.hoisted(() => ({+ board: null as unknown,+ getTask: vi.fn(),+ subscribe: vi.fn(),+ client: {+ getQueryCache: () => ({+ subscribe: (listener: unknown) => {+ mocks.subscribe(listener);+ return () => {};+ },+ }),+ getQueryState: vi.fn(),+ getQueryData: vi.fn(),+ setQueryData: vi.fn(),+ invalidateQueries: vi.fn(),+ cancelQueries: vi.fn().mockResolvedValue(undefined),+ },+}));+vi.mock("@tanstack/react-query", () => ({+ useQueryClient: () => mocks.client,+}));+vi.mock("@kaneo/libs", () => ({ windowId: "test" }));+vi.mock("@/lib/auth-client", () => ({+ authClient: { useSession: () => ({ data: { user: { id: "u" } } }) },+}));+vi.mock("@/fetchers/task/get-task", () => ({ default: mocks.getTask }));+vi.mock("@/fetchers/label/get-labels-by-task", () => ({+ default: () => Promise.resolve([]),+}));+vi.mock("@/fetchers/external-link/get-external-links", () => ({+ default: () => Promise.resolve([]),+}));++class Socket {+ static current: Socket;+ onopen: (() => void) | null = null;+ onclose: (() => void) | null = null;+ onmessage: ((event: { data: string }) => void) | null = null;+ close = vi.fn();+ constructor() {+ Socket.current = this;+ }+ message(type: string, rest: Record<string, unknown>) {+ this.onmessage?.({+ data: JSON.stringify({ type, projectId: "p", ...rest }),+ });+ }+}++beforeEach(() => {+ vi.stubGlobal("WebSocket", Socket);+ mocks.board = {+ id: "p",+ columns: [+ {+ id: "todo",+ slug: "todo",+ tasks: [{ id: "a", projectId: "p", status: "todo", position: 0 }],+ },+ { id: "doing", slug: "doing", tasks: [] },+ ],+ plannedTasks: [],+ archivedTasks: [],+ };+ mocks.client.getQueryData.mockImplementation(() => mocks.board);+ mocks.client.setQueryData.mockImplementation((_key, value) => {+ mocks.board = typeof value === "function" ? value(mocks.board) : value;+ });+ mocks.client.invalidateQueries.mockClear();+ mocks.client.getQueryState.mockReset();+ mocks.subscribe.mockClear();+});+afterEach(() => {+ cleanup();+ vi.unstubAllGlobals();+});++describe("board realtime races", () => {+ it.each(["TASKS_REORDERED", "PROJECT_UPDATED", "TASK_RELATION_UPDATED"])(+ "discards a task refresh started before %s",+ async (type) => {+ let finish!: (value: unknown) => void;+ mocks.getTask.mockImplementationOnce(+ () =>+ new Promise((resolve) => {+ finish = resolve;+ }),+ );+ renderHook(() => useProjectWebSocket("p"));+ Socket.current.message("TASK_UPDATED", { taskId: "a" });+ Socket.current.message(type, {+ tasks: [{ id: "a", position: 2, status: "doing" }],+ });+ const afterEvent = mocks.board;+ finish({ id: "a", projectId: "p", status: "todo", position: 0 });+ await Promise.resolve();+ await Promise.resolve();+ await Promise.resolve();+ expect(mocks.board).toBe(afterEvent);+ if (type === "TASKS_REORDERED")+ expect(+ (mocks.board as { columns: { tasks: { id: string }[] }[] }).columns[1]+ .tasks[0].id,+ ).toBe("a");+ },+ );++ it("coalesces updates while pagination finishes without restarting page one", async () => {+ mocks.client.getQueryState.mockReturnValue({ fetchStatus: "fetching" });+ mocks.getTask.mockReset();+ mocks.getTask.mockResolvedValue({+ id: "a",+ projectId: "p",+ status: "doing",+ position: 2,+ });+ renderHook(() => useProjectWebSocket("p"));+ Socket.current.message("TASK_UPDATED", { taskId: "a" });+ Socket.current.message("TASK_UPDATED", { taskId: "a" });+ expect(mocks.getTask).not.toHaveBeenCalled();+ expect(mocks.client.invalidateQueries).not.toHaveBeenCalled();+ mocks.client.getQueryState.mockReturnValue({ fetchStatus: "idle" });+ mocks.subscribe.mock.calls[0][0]({+ query: { queryKey: ["tasks", "p"], state: { fetchStatus: "idle" } },+ });+ await Promise.resolve();+ await Promise.resolve();+ await Promise.resolve();+ expect(mocks.getTask).toHaveBeenCalledExactlyOnceWith("a", "board");+ expect(mocks.client.invalidateQueries).not.toHaveBeenCalledWith({+ queryKey: ["tasks", "p"],+ });+ });++ it("refreshes a project-wide task update with no task id", () => {+ renderHook(() => useProjectWebSocket("p"));+ Socket.current.message("TASK_UPDATED", { taskId: "" });+ expect(mocks.client.invalidateQueries).toHaveBeenCalledWith({+ queryKey: ["tasks", "p"],+ });+ });+});++it("reconciles the initial handshake after active pagination completes", async () => {+ mocks.client.getQueryState.mockReturnValue({ fetchStatus: "fetching" });+ renderHook(() => useProjectWebSocket("p"));+ Socket.current.onopen?.();+ await Promise.resolve();+ expect(mocks.client.invalidateQueries).not.toHaveBeenCalled();+ mocks.client.getQueryState.mockReturnValue({ fetchStatus: "idle" });+ mocks.subscribe.mock.calls[0][0]({+ query: { queryKey: ["tasks", "p"], state: { fetchStatus: "idle" } },+ });+ await Promise.resolve();+ expect(mocks.client.invalidateQueries).toHaveBeenCalledExactlyOnceWith({+ queryKey: ["tasks", "p"],+ });+});+it("preserves distinct task effects across pagination and a disconnect before replay", async () => {+ vi.useFakeTimers();+ try {+ mocks.client.getQueryState.mockReturnValue({ fetchStatus: "fetching" });+ mocks.getTask.mockResolvedValue({+ id: "a",+ projectId: "p",+ status: "todo",+ });+ renderHook(() => useProjectWebSocket("p"));+ Socket.current.message("COMMENT_UPDATED", { taskId: "a" });+ Socket.current.message("TASK_LABEL_UPDATED", { taskId: "a" });+ mocks.client.getQueryState.mockReturnValue({ fetchStatus: "idle" });+ mocks.subscribe.mock.calls[0][0]({+ query: { queryKey: ["tasks", "p"], state: { fetchStatus: "idle" } },+ });+ Socket.current.onclose?.();+ await Promise.resolve();+ await vi.advanceTimersByTimeAsync(1000);+ Socket.current.onopen?.();+ await vi.advanceTimersByTimeAsync(0);+ expect(mocks.client.invalidateQueries).toHaveBeenCalledWith({+ queryKey: ["comments", "a"],+ });+ expect(mocks.client.invalidateQueries).toHaveBeenCalledWith({+ queryKey: ["labels", "a"],+ });+ } finally {+ vi.useRealTimers();+ }+});++++it("does not overwrite a parent's newer progress with an older child's response", async () => {++ let finish!: (value: unknown) => void;++ mocks.getTask++ .mockImplementationOnce(++ () =>++ new Promise((resolve) => {++ finish = resolve;++ }),++ )++ .mockResolvedValueOnce({++ id: "b",++ projectId: "p",++ status: "todo",++ parentSubtaskCounts: [{ taskId: "a", completed: 2, total: 2 }],++ });++ renderHook(() => useProjectWebSocket("p"));++ Socket.current.message("TASK_UPDATED", { taskId: "old-child" });++ Socket.current.message("TASK_UPDATED", { taskId: "b" });++ await Promise.resolve();++ await Promise.resolve();++ await Promise.resolve();++ finish({++ id: "old-child",++ projectId: "p",++ status: "todo",++ parentSubtaskCounts: [{ taskId: "a", completed: 1, total: 2 }],++ });++ await Promise.resolve();++ await Promise.resolve();++ await Promise.resolve();++ const task = (++ mocks.board as {++ columns: { tasks: { id: string; subtaskCounts?: unknown }[] }[];++ }++ ).columns[0].tasks.find((task) => task.id === "a");++ expect(task?.subtaskCounts).toEqual({ completed: 2, total: 2 });++ expect(mocks.client.invalidateQueries).toHaveBeenCalledWith({++ queryKey: ["tasks", "p"],++ });++});++++it("preserves newer parent progress when an earlier parent refresh finishes last", async () => {++ let finish!: (value: unknown) => void;++ mocks.getTask++ .mockImplementationOnce(++ () =>++ new Promise((resolve) => {++ finish = resolve;++ }),++ )++ .mockResolvedValueOnce({++ id: "b",++ projectId: "p",++ status: "todo",++ parentSubtaskCounts: [{ taskId: "a", completed: 2, total: 2 }],++ });++ renderHook(() => useProjectWebSocket("p"));++ Socket.current.message("TASK_UPDATED", { taskId: "a" });++ Socket.current.message("TASK_UPDATED", { taskId: "b" });++ await Promise.resolve();++ await Promise.resolve();++ await Promise.resolve();++ finish({++ id: "a",++ projectId: "p",++ status: "todo",++ subtaskCounts: { completed: 1, total: 2 },++ });++ await Promise.resolve();++ await Promise.resolve();++ await Promise.resolve();++ const task = (++ mocks.board as {++ columns: { tasks: { id: string; subtaskCounts?: unknown }[] }[];++ }++ ).columns[0].tasks.find((task) => task.id === "a");++ expect(task?.subtaskCounts).toEqual({ completed: 2, total: 2 });++});diff --cc apps/web/src/hooks/use-project-websocket-lifecycle.test.tsxindex 77cb673a8,6acbf54aa..d1e5c2068--- a/apps/web/src/hooks/use-project-websocket-lifecycle.test.tsx+++ b/apps/web/src/hooks/use-project-websocket-lifecycle.test.tsx@@@ -143,6 -162,6 +143,7 @@@ describe("project WebSocket lifecycle"const { unmount } = renderHook(() => useProjectWebSocket("project-a"));for (let retry = 0; retry < 5; retry++) {act(() => {++ TestSocket.instances.at(-1)?.open();TestSocket.instances.at(-1)?.onclose?.();vi.advanceTimersByTime(1000 * 2 ** retry);});diff --cc apps/web/src/hooks/use-project-websocket.tsindex c09aad8fe,f52da8eb3..06b7d1c11--- a/apps/web/src/hooks/use-project-websocket.ts+++ b/apps/web/src/hooks/use-project-websocket.ts@@@ -43,8 -32,7 +43,11 @@@ export function useProjectWebSocket(prolet activeSocket: WebSocket | null = null;let retries = 0;let retryTimeout: ReturnType<typeof setTimeout> | null = null;++ let healthyTimeout: ReturnType<typeof setTimeout> | null = null;++ let requestSequence = 0;++ const parentCountVersions = new Map<string, number>();let pingInterval: ReturnType<typeof setInterval> | null = null;+ let fallbackInterval: ReturnType<typeof setInterval> | null = null;function clearPing() {if (pingInterval !== null) {@@@ -62,13 -50,7 +65,18 @@@ws.onopen = () => {if (disposed || activeSocket !== ws) return;- retries = 0; // Reset retries on successful connection+ needsReconcile = true;+ flushPending();- if (fallbackInterval !== null) {- clearInterval(fallbackInterval);- fallbackInterval = null;- }- retries = 0; // Reset retries on successful connection++ if (healthyTimeout !== null) clearTimeout(healthyTimeout);++ healthyTimeout = setTimeout(() => {++ healthyTimeout = null;++ if (disposed || activeSocket !== ws) return;++ retries = 0;++ if (fallbackInterval !== null) {++ clearInterval(fallbackInterval);++ fallbackInterval = null;++ }++ }, WS_PING_INTERVAL_MS);// Start keepalive pings to prevent Cloudflare idle timeout (100s)clearPing();pingInterval = setInterval(() => {@@@ -165,97 -96,9 +173,117 @@@message.type === "COMMENT_UPDATED" ||message.type === "PROJECT_UPDATED") {- queryClient.invalidateQueries({- queryKey: ["tasks", message.projectId],- });+ if (+ message.type === "PROJECT_UPDATED" ||+ message.type === "TASK_RELATION_UPDATED"+ ) {+ markBoardCacheChanged(queryClient, projectId);+ void queryClient.invalidateQueries({+ queryKey: ["tasks", projectId],+ });+ } else if (!message.taskId && message.type !== "COMMENT_UPDATED") {+ markBoardCacheChanged(queryClient, projectId);+ void queryClient.invalidateQueries({+ queryKey: ["tasks", projectId],+ });+ } else if (message.taskId && message.type !== "COMMENT_UPDATED") {+ const taskId = message.taskId as string;++ const sequence = ++requestSequence;+ const version = (taskVersions.get(taskId) ?? 0) + 1;+ taskVersions.set(taskId, version);+ markBoardCacheChanged(queryClient, projectId, taskId);+ const boardVersion = getBoardCacheVersion(+ queryClient,+ projectId,+ taskId,+ );+ if (message.type === "TASK_DELETED") {+ queryClient.setQueryData<ProjectWithTasks>(+ ["tasks", projectId],+ (board) =>+ board ? (patchBoardTask(board, taskId) ?? board) : board,+ );+ } else {+ void Promise.all([+ getTask(taskId, "board"),+ getLabelsByTask({ taskId }),+ getExternalLinks(taskId),+ ])+ .then(([task, labels, externalLinks]) => {+ if (+ disposed ||+ activeSocket !== ws ||+ taskVersions.get(taskId) !== version ||+ getBoardCacheVersion(queryClient, projectId, taskId) !==+ boardVersion+ )+ return;++ const staleOwnCounts =++ (parentCountVersions.get(taskId) ?? 0) > sequence;++ const { subtaskCounts, ...taskFields } = task;++ if (staleOwnCounts)++ void queryClient.invalidateQueries({++ queryKey: ["tasks", projectId],++ });++ else parentCountVersions.set(taskId, sequence);+ queryClient.setQueryData<ProjectWithTasks>(+ ["tasks", projectId],+ (board) =>+ board+ ? (patchBoardTask(board, taskId, {- ...task,++ ...taskFields,++ ...(!staleOwnCounts ? { subtaskCounts } : {}),+ labels,+ externalLinks: externalLinks.map((link) => ({+ ...link,+ metadata:+ link.metadata &&+ typeof link.metadata === "object" &&+ !Array.isArray(link.metadata)+ ? link.metadata+ : null,+ })),+ }) ?? board)+ : board,+ );+ for (const progress of task.parentSubtaskCounts ?? []) {++ if (++ (parentCountVersions.get(progress.taskId) ?? 0) >++ sequence++ ) {++ void queryClient.invalidateQueries({++ queryKey: ["tasks", projectId],++ });++ continue;++ }++ parentCountVersions.set(progress.taskId, sequence);+ queryClient.setQueryData<ProjectWithTasks>(+ ["tasks", projectId],+ (board) =>+ board+ ? (patchBoardTask(board, progress.taskId, {+ projectId,+ subtaskCounts: {+ completed: progress.completed,+ total: progress.total,+ },+ }) ?? board)+ : board,+ );+ }+ })+ .catch(() => {+ if (+ !disposed &&+ activeSocket === ws &&+ taskVersions.get(taskId) === version+ )+ void queryClient.invalidateQueries({+ queryKey: ["tasks", projectId],+ });+ });+ }+ }if (message.type === "PROJECT_UPDATED") {queryClient.invalidateQueries({ queryKey: ["projects"] });@@@ -323,6 -162,6 +351,10 @@@ws.onclose = () => {if (disposed || activeSocket !== ws) return;clearPing();++ if (healthyTimeout !== null) {++ clearTimeout(healthyTimeout);++ healthyTimeout = null;++ }activeSocket = null;if (retries < MAX_RETRIES) {@@@ -340,52 -172,10 +372,54 @@@};}connect();+ function flushPending() {+ if (+ disposed ||+ flushQueued ||+ queryClient.getQueryState(["tasks", projectId])?.fetchStatus ===+ "fetching"+ )+ return;+ flushQueued = true;+ queueMicrotask(() => {+ flushQueued = false;+ if (+ disposed ||+ !activeSocket ||+ queryClient.getQueryState(["tasks", projectId])?.fetchStatus ===+ "fetching"+ )+ return;+ if (needsReconcile) {+ needsReconcile = false;+ markBoardCacheChanged(queryClient, projectId);+ void queryClient.invalidateQueries({+ queryKey: ["tasks", projectId],+ });+ }+ const messages = Array.from(pendingMessages.values());+ pendingMessages.clear();+ for (const data of messages)+ activeSocket.onmessage?.(new MessageEvent("message", { data }));+ });+ }+ const unsubscribe = queryClient.getQueryCache().subscribe(({ query }) => {+ if (+ query.queryKey[0] === "tasks" &&+ query.queryKey[1] === projectId &&+ query.state.fetchStatus === "idle"+ )+ flushPending();+ });return () => {+ unsubscribe();++ if (healthyTimeout !== null) clearTimeout(healthyTimeout);+ pendingMessages.clear();++ if (healthyTimeout !== null) clearTimeout(healthyTimeout);disposed = true;clearPing();+ if (fallbackInterval !== null) clearInterval(fallbackInterval);if (retryTimeout !== null) {clearTimeout(retryTimeout);}diff --cc apps/web/src/lib/patch-board-task.test.tsindex aac63759d,000000000..658f75ffamode 100644,000000..100644--- a/apps/web/src/lib/patch-board-task.test.ts+++ b/apps/web/src/lib/patch-board-task.test.ts@@@ -1,116 -1,0 +1,118 @@@+import { QueryClient } from "@tanstack/react-query";- import { describe, expect, it } from "vite-plus/test";++import { describe, expect, it, vi } from "vite-plus/test";+import type { ProjectWithTasks } from "@/types/project";+import {+ getBoardCacheVersion,+ markBoardCacheChanged,+} from "./board-cache-version";+import { patchBoardTask } from "./patch-board-task";+import { updateBoardTaskCache } from "./update-board-task-cache";++function board() {+ return {+ id: "p",+ columns: [+ {+ id: "todo",+ slug: "todo",+ tasks: [+ {+ id: "a",+ projectId: "p",+ status: "todo",+ title: "old",+ userId: "u",+ assigneeId: "u",+ labels: [{ id: "label" }],+ subtaskCounts: { completed: 1, total: 3 },+ },+ ],+ },+ { id: "doing", slug: "doing", tasks: [] },+ ],+ archivedTasks: [],+ plannedTasks: [],+ } as unknown as ProjectWithTasks;+}++describe("bounded board cache updates", () => {+ it("preserves metadata and the assignee when updating a single field", () => {+ const client = new QueryClient();+ client.setQueryData(["tasks", "p"], board());+ updateBoardTaskCache(client, "p", "a", { title: "new" });+ expect(+ client.getQueryData<ProjectWithTasks>(["tasks", "p"])?.columns[0]+ .tasks[0],+ ).toMatchObject({+ title: "new",+ assigneeId: "u",+ labels: [{ id: "label" }],+ subtaskCounts: { completed: 1, total: 3 },+ });+ client.clear();+ });++ it("lets a pending board load finish and applies only the newest local edit afterward", async () => {+ const client = new QueryClient();+ let finish!: (value: ProjectWithTasks) => void;+ const loading = client.fetchQuery({+ queryKey: ["tasks", "p"],+ queryFn: () =>+ new Promise<ProjectWithTasks>((resolve) => {+ finish = resolve;+ }),+ });+ updateBoardTaskCache(client, "p", "a", { title: "first" });+ updateBoardTaskCache(client, "p", "a", { title: "latest" });+ expect(client.getQueryState(["tasks", "p"])?.fetchStatus).toBe("fetching");+ finish(board());+ await loading;+ expect(+ client.getQueryData<ProjectWithTasks>(["tasks", "p"])?.columns[0].tasks[0]+ .title,+ ).toBe("latest");+ client.clear();+ });++ it("moves a refreshed task by column slug and removes tasks moved out of the project", () => {+ const moved = patchBoardTask(board(), "a", {+ projectId: "p",+ status: "doing",+ })!;+ expect(moved.columns[0].tasks).toHaveLength(0);+ expect(moved.columns[1].tasks.map((task) => task.id)).toEqual(["a"]);+ expect(+ patchBoardTask(moved, "a", { projectId: "other" })?.columns[1].tasks,+ ).toHaveLength(0);+ });+});++it("rejects a late mutation response after a newer socket patch", () => {+ const client = new QueryClient();+ client.setQueryData(["tasks", "p"], board());+ markBoardCacheChanged(client, "p", "a");+ const version = getBoardCacheVersion(client, "p", "a");++ const invalidate = vi.spyOn(client, "invalidateQueries");+ markBoardCacheChanged(client, "p", "a");+ client.setQueryData(+ ["tasks", "p"],+ patchBoardTask(board(), "a", { projectId: "p", title: "remote" }),+ );+ updateBoardTaskCache(client, "p", "a", { title: "late response" }, version);+ expect(+ client.getQueryData<ProjectWithTasks>(["tasks", "p"])?.columns[0].tasks[0]+ .title,+ ).toBe("remote");++ expect(invalidate).toHaveBeenCalledWith({ queryKey: ["tasks", "p"] });+ client.clear();+});+it("defers descriptions exceeding the UTF-8 board limit", () => {+ const updated = patchBoardTask(board(), "a", {+ projectId: "p",+ description: "😀".repeat(20000),+ });+ expect(updated?.columns[0].tasks[0]).toMatchObject({+ description: null,+ descriptionDeferred: true,+ });+});diff --cc apps/web/src/lib/update-board-task-cache.tsindex c68abd78e,000000000..5402a353cmode 100644,000000..100644--- a/apps/web/src/lib/update-board-task-cache.ts+++ b/apps/web/src/lib/update-board-task-cache.ts@@@ -1,43 -1,0 +1,45 @@@+import type { QueryClient } from "@tanstack/react-query";+import type { ProjectWithTasks } from "@/types/project";+import type Task from "@/types/task";+import {+ getBoardCacheVersion,+ markBoardCacheChanged,+} from "./board-cache-version";+import { patchBoardTask } from "./patch-board-task";++export function updateBoardTaskCache(+ queryClient: QueryClient,+ projectId: string,+ taskId: string,+ fields: Partial<Task>,+ expectedVersion?: string,+) {+ if (expectedVersion === undefined)+ markBoardCacheChanged(queryClient, projectId, taskId);+ const version =+ expectedVersion ?? getBoardCacheVersion(queryClient, projectId, taskId);+ const queryKey = ["tasks", projectId];+ const apply = () => {- if (getBoardCacheVersion(queryClient, projectId, taskId) !== version)++ if (getBoardCacheVersion(queryClient, projectId, taskId) !== version) {++ void queryClient.invalidateQueries({ queryKey });+ return;++ }+ queryClient.setQueryData<ProjectWithTasks>(queryKey, (board) =>+ board+ ? (patchBoardTask(board, taskId, { ...fields, projectId }) ?? board)+ : board,+ );+ };+ if (queryClient.getQueryState(queryKey)?.fetchStatus === "fetching") {+ const unsubscribe = queryClient+ .getQueryCache()+ .subscribe(({ query, type }) => {+ if (query.queryKey[0] !== "tasks" || query.queryKey[1] !== projectId)+ return;+ if (type === "removed" || query.state.fetchStatus === "idle") {+ unsubscribe();+ if (type !== "removed") apply();+ }+ });+ } else apply();+}