Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(views): release the drag lock on cancelled drags (MUL-6240) (#7027)
Jiayuan Zhang375ba786b75b
diff --git a/packages/views/issues/components/board-view.tsx b/packages/views/issues/components/board-view.tsxindex 611ead833b..b3c70ca2ce 100644--- a/packages/views/issues/components/board-view.tsx+++ b/packages/views/issues/components/board-view.tsx@@ -553,6 +553,16 @@ function BoardViewImpl({[groupedIssues, groups, grouping, groupingOptionIds, onMoveIssue, groupIds, groupMap, sortBy, beginSettle, columnsRef, isDraggingRef, setColumns, applyPropertyGroupValue],);+ // An aborted drag (pointercancel, window resize, tab hide, Escape) fires+ // onDragCancel instead of onDragEnd. Releasing the drag lock here keeps the+ // column mirror resyncing with the cache afterwards — see the same handler in+ // list-view for the touch path that makes this routine (MUL-6240).+ const handleDragCancel = useCallback(() => {+ isDraggingRef.current = false;+ setActiveIssue(null);+ setColumns(buildColumns(groupedIssues, groups, grouping, groupingOptionIds));+ }, [groupedIssues, groups, grouping, groupingOptionIds, setColumns, isDraggingRef]);+return (<DndContextsensors={sensors}@@ -560,6 +570,7 @@ function BoardViewImpl({onDragStart={handleDragStart}onDragOver={handleDragOver}onDragEnd={handleDragEnd}+ onDragCancel={handleDragCancel}><divref={pan.ref}diff --git a/packages/views/issues/components/list-view.test.tsx b/packages/views/issues/components/list-view.test.tsxnew file mode 100644index 0000000000..12b0c6ca85--- /dev/null+++ b/packages/views/issues/components/list-view.test.tsx@@ -0,0 +1,251 @@+import { describe, it, expect, vi, beforeEach } from "vitest";+import { render, screen, act } from "@testing-library/react";+import userEvent from "@testing-library/user-event";+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";+import { I18nProvider } from "@multica/core/i18n/react";+import type { Issue, IssueStatus } from "@multica/core/types";+import { ListView } from "./list-view";+import { IssueContextMenuProvider } from "../actions";+import { ScrollRestorationProvider } from "../../platform";+import type { IssueStatusPagination } from "../surface/use-issue-status-branches";+import enCommon from "../../locales/en/common.json";+import enIssues from "../../locales/en/issues.json";++const TEST_RESOURCES = { en: { common: enCommon, issues: enIssues } };++vi.mock("@multica/core/hooks", () => ({+ useWorkspaceId: () => "ws-1",+}));++const mockGetAgentTaskSnapshot = vi.hoisted(() => vi.fn().mockResolvedValue([]));+vi.mock("@multica/core/api", () => ({+ api: { getAgentTaskSnapshot: mockGetAgentTaskSnapshot },+ getApi: () => ({ getAgentTaskSnapshot: mockGetAgentTaskSnapshot }),+ setApiInstance: vi.fn(),+}));++vi.mock("@multica/core/paths", async () => {+ const actual =+ await vi.importActual<typeof import("@multica/core/paths")>("@multica/core/paths");+ return {+ ...actual,+ useWorkspaceSlug: () => "acme",+ useRequiredWorkspaceSlug: () => "acme",+ useWorkspacePaths: () => actual.paths.workspace("acme"),+ };+});++vi.mock("../../navigation", () => ({+ AppLink: ({ children, href, ...props }: any) => (+ <a href={href} {...props}>+ {children}+ </a>+ ),+ useNavigation: () => ({ push: vi.fn(), pathname: "/issues" }),+ resolveClickIntent: () => "push",+ useIntentNavigate: () => () => {},+ NavigationProvider: ({ children }: { children: React.ReactNode }) => children,+}));++const mockAuthUser = { id: "user-1", email: "[email protected]", name: "Test User" };+vi.mock("@multica/core/auth", () => ({+ useAuthStore: Object.assign(+ (selector?: any) => {+ const state = { user: mockAuthUser, isAuthenticated: true };+ return selector ? selector(state) : state;+ },+ { getState: () => ({ user: mockAuthUser, isAuthenticated: true }) },+ ),+ registerAuthStore: vi.fn(),+ createAuthStore: vi.fn(),+}));++// View store. `listCollapsedStatuses` is mutable so `toggleListCollapsed`+// models the real store: the accordion's expanded set is derived from it.+const mockViewState: {+ sortBy: string;+ sortDirection: string;+ cardProperties: Record<string, boolean>;+ cardPropertyIds: string[];+ listCollapsedStatuses: IssueStatus[];+ toggleListCollapsed: (status: IssueStatus) => void;+} = {+ sortBy: "position",+ sortDirection: "asc",+ cardProperties: {},+ cardPropertyIds: [],+ listCollapsedStatuses: [],+ toggleListCollapsed: vi.fn((status: IssueStatus) => {+ mockViewState.listCollapsedStatuses =+ mockViewState.listCollapsedStatuses.includes(status)+ ? mockViewState.listCollapsedStatuses.filter((s) => s !== status)+ : [...mockViewState.listCollapsedStatuses, status];+ }),+};++vi.mock("@multica/core/issues/stores/view-store-context", () => ({+ ViewStoreProvider: ({ children }: { children: React.ReactNode }) => children,+ useViewStore: (selector?: any) => (selector ? selector(mockViewState) : mockViewState),+ useViewStoreApi: () => ({+ getState: () => mockViewState,+ setState: vi.fn(),+ subscribe: vi.fn(),+ }),+}));++vi.mock("@multica/core/modals", () => ({+ useModalStore: Object.assign(+ () => ({ open: vi.fn() }),+ { getState: () => ({ open: vi.fn() }) },+ ),+}));++// Capture the DndContext callbacks so a test can drive dnd-kit's real+// lifecycle — including the cancel path, which never calls onDragEnd.+let lastOnDragStart: any = null;+let lastOnDragCancel: any = null;+const stableSetNodeRef = () => {};++vi.mock("@dnd-kit/core", () => ({+ DndContext: ({ children, onDragStart, onDragCancel }: any) => {+ lastOnDragStart = onDragStart;+ lastOnDragCancel = onDragCancel;+ return children;+ },+ DragOverlay: () => null,+ PointerSensor: class {},+ useSensor: () => ({}),+ useSensors: () => [],+ useDroppable: () => ({ setNodeRef: stableSetNodeRef, isOver: false }),+ pointerWithin: vi.fn(),+ closestCenter: vi.fn(),+}));++vi.mock("@dnd-kit/sortable", () => ({+ SortableContext: ({ children }: any) => children,+ verticalListSortingStrategy: {},+ arrayMove: <T,>(arr: T[]) => arr,+ useSortable: () => ({+ attributes: {},+ listeners: {},+ setNodeRef: vi.fn(),+ transform: null,+ transition: null,+ isDragging: false,+ }),+}));++vi.mock("@dnd-kit/utilities", () => ({+ CSS: { Transform: { toString: () => undefined } },+}));++// jsdom has no layout, so the real Virtuoso measures a 0-height viewport and+// renders nothing. Render rows inline so the panel's contents are assertable.+vi.mock("react-virtuoso", () => ({+ Virtuoso: ({ data, itemContent }: any) => (+ <div data-testid="virtuoso-mock">+ {(data ?? []).map((item: any, i: number) => (+ <div key={i}>{itemContent(i, item)}</div>+ ))}+ </div>+ ),+}));++const ISSUES: Issue[] = [+ {+ id: "issue-1",+ identifier: "MUL-1",+ title: "First todo issue",+ status: "todo",+ priority: "none",+ position: 1,+ workspace_id: "ws-1",+ created_at: "2026-01-01T00:00:00Z",+ updated_at: "2026-01-01T00:00:00Z",+ } as Issue,+ {+ id: "issue-2",+ identifier: "MUL-2",+ title: "Second todo issue",+ status: "todo",+ priority: "none",+ position: 2,+ workspace_id: "ws-1",+ created_at: "2026-01-01T00:00:00Z",+ updated_at: "2026-01-01T00:00:00Z",+ } as Issue,+];++const PAGINATION = {+ todo: {+ hasMore: false,+ isLoading: false,+ isFetching: false,+ isError: false,+ total: 2,+ loadMore: vi.fn(),+ retry: vi.fn(),+ },+} as unknown as IssueStatusPagination;++function renderListView() {+ const queryClient = new QueryClient({+ defaultOptions: { queries: { retry: false, gcTime: 0 } },+ });+ return render(+ <QueryClientProvider client={queryClient}>+ <I18nProvider resources={TEST_RESOURCES} locale="en">+ <IssueContextMenuProvider>+ <ScrollRestorationProvider adapter={{ get: () => undefined }}>+ <ListView+ issues={ISSUES}+ visibleStatuses={["todo"]}+ statusPagination={PAGINATION}+ onMoveIssue={vi.fn()}+ />+ </ScrollRestorationProvider>+ </IssueContextMenuProvider>+ </I18nProvider>+ </QueryClientProvider>,+ );+}++describe("ListView status header collapse", () => {+ beforeEach(() => {+ mockViewState.listCollapsedStatuses = [];+ lastOnDragStart = null;+ lastOnDragCancel = null;+ });++ it("collapses a status group when its header is clicked", async () => {+ const user = userEvent.setup();+ renderListView();++ const trigger = screen.getByRole("button", { expanded: true });+ await user.click(trigger);++ expect(mockViewState.listCollapsedStatuses).toEqual(["todo"]);+ });++ it("still collapses after a drag is cancelled instead of dropped", async () => {+ const user = userEvent.setup();+ renderListView();++ // dnd-kit fires onDragCancel — never onDragEnd — when the browser aborts+ // an active pointer drag. On touch that happens on every scroll gesture+ // that starts on a row: the drag activates past the 5px threshold, then+ // the browser takes the gesture over and fires pointercancel. A cancel+ // that leaves the drag lock engaged makes the header's collapse toggle a+ // permanent no-op (MUL-6240).+ expect(lastOnDragCancel).toBeTypeOf("function");+ act(() => {+ lastOnDragStart({ active: { id: "issue-1" } });+ lastOnDragCancel();+ });++ const trigger = screen.getByRole("button", { expanded: true });+ await user.click(trigger);++ expect(mockViewState.listCollapsedStatuses).toEqual(["todo"]);+ });+});diff --git a/packages/views/issues/components/list-view.tsx b/packages/views/issues/components/list-view.tsxindex 65fca09704..0481190d90 100644--- a/packages/views/issues/components/list-view.tsx+++ b/packages/views/issues/components/list-view.tsx@@ -313,6 +313,21 @@ function ListViewImpl({[issues, groups, onMoveIssue, groupIds, groupMap, sortBy, beginSettle, setColumns, columnsRef, isDraggingRef],);+ // dnd-kit fires onDragCancel — never onDragEnd — when an active drag is+ // aborted: pointercancel, window resize, tab hide, or Escape. Touch browsers+ // hit that path constantly, because a scroll gesture that starts on a row+ // moves past the 5px activation distance and *then* the browser takes the+ // gesture over for native scrolling and cancels the pointer. Without this+ // handler `isDraggingRef` stayed true for the rest of the session, which+ // froze the column mirror against cache updates and — because the accordion's+ // onValueChange is guarded by the same ref — made tapping a status header a+ // no-op, so groups could no longer be collapsed at all (MUL-6240).+ const handleDragCancel = useCallback(() => {+ isDraggingRef.current = false;+ setActiveIssue(null);+ setColumns(buildColumns(issues, groups, "status"));+ }, [issues, groups, setColumns, isDraggingRef]);+// The single scroll container is shared by every status panel's Virtuoso as// its customScrollParent, so a callback ref hands the element to the panels// once it mounts. Keeping one scroller (rather than one per panel) preserves@@ -385,6 +400,7 @@ function ListViewImpl({onDragStart={handleDragStart}onDragOver={handleDragOver}onDragEnd={handleDragEnd}+ onDragCancel={handleDragCancel}><div ref={attachScroller} data-tab-scroll-root="list" className="flex-1 min-h-0 overflow-y-auto p-2 pt-0">{content}diff --git a/packages/views/issues/components/swimlane-view.tsx b/packages/views/issues/components/swimlane-view.tsxindex f882da90ab..153e678f5f 100644--- a/packages/views/issues/components/swimlane-view.tsx+++ b/packages/views/issues/components/swimlane-view.tsx@@ -1339,6 +1339,16 @@ function SwimLaneViewImpl({],);+ // An aborted drag (pointercancel, window resize, tab hide, Escape) fires+ // onDragCancel instead of onDragEnd. Releasing the drag lock here keeps+ // localCells resyncing with the cache afterwards — see the same handler in+ // list-view for the touch path that makes this routine (MUL-6240).+ const handleDragCancel = useCallback(() => {+ isDraggingRef.current = false;+ setActiveIssue(null);+ setLocalCells(cells);+ }, [cells]);+const computeLaneKey = (_index: number, lane: LaneGroup) => lane.key;const renderLane = (index: number, lane: LaneGroup) => (<div className={index === 0 ? undefined : "pt-4"}>@@ -1368,6 +1378,7 @@ function SwimLaneViewImpl({onDragStart={handleDragStart}onDragOver={handleDragOver}onDragEnd={handleDragEnd}+ onDragCancel={handleDragCancel}><div ref={attachScroller} data-tab-scroll-root="swimlane" className="flex flex-1 min-h-0 gap-4 overflow-auto p-4"><div className="flex shrink-0 flex-col" style={{ width: `${trackWidth}px` }}>