From a6715e9956dc67ea423ab37a13531ac7a00a6de2 Mon Sep 17 00:00:00 2001 From: Mao Nakamoto <41178744+maonakamoto@users.noreply.github.com> Date: Fri, 3 Jul 2026 10:57:53 +0200 Subject: [PATCH] fix(control): freeze project-rail row positions during live refreshes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Priority re-ranking reshuffled rows under the cursor on every state refresh — two misdispatches on 2026-07-03 (one to the wrong project, one swallowed by a re-render). Row order now recomputes only when the sort mode, the query, or the set of visible projects changes; live refreshes update card content in place. Co-Authored-By: Claude Fable 5 --- .../control/ProjectOperationsView.tsx | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/components/control/ProjectOperationsView.tsx b/src/components/control/ProjectOperationsView.tsx index 8ae322095..4405f5f16 100644 --- a/src/components/control/ProjectOperationsView.tsx +++ b/src/components/control/ProjectOperationsView.tsx @@ -1,6 +1,6 @@ "use client"; -import { useMemo, useState } from "react"; +import { useMemo, useRef, useState } from "react"; import { Search } from "lucide-react"; import { cn } from "@/lib/utils"; import { compactRelativeDate } from "@/lib/dates"; @@ -65,6 +65,12 @@ export function ProjectOperationsView({ const workingCount = sourceSnapshots.filter(isWorking).length; const openIdleCount = sourceSnapshots.filter(isIdle).length; const normalizedQuery = query.trim().toLowerCase(); + // Row positions FREEZE while the user is aiming: live state refreshes update + // card content but must not reshuffle rows mid-click (priority re-ranking + // moved the target under the cursor twice on 2026-07-03 — one dispatch went + // to the wrong project, one vanished). The ranking recomputes only when the + // sort mode, the query, or the SET of visible projects changes. + const frozenOrderRef = useRef<{ key: string; order: string[] }>({ key: "", order: [] }); const visibleSnapshots = useMemo(() => { const filtered = normalizedQuery ? sourceSnapshots.filter((snapshot) => { @@ -80,11 +86,18 @@ export function ProjectOperationsView({ }) : sourceSnapshots; - return [...filtered].sort((a, b) => { + const ranked = [...filtered].sort((a, b) => { if (sort === "az") return a.project.tab.localeCompare(b.project.tab); if (sort === "recent") return snapshotActivityMs(b) - snapshotActivityMs(a) || a.project.tab.localeCompare(b.project.tab); return sourceSnapshots.indexOf(a) - sourceSnapshots.indexOf(b); }); + + const setKey = `${sort}|${normalizedQuery}|${filtered.map((s) => s.project.tab).sort().join(",")}`; + if (frozenOrderRef.current.key !== setKey) { + frozenOrderRef.current = { key: setKey, order: ranked.map((s) => s.project.tab) }; + } + const order = frozenOrderRef.current.order; + return [...filtered].sort((a, b) => order.indexOf(a.project.tab) - order.indexOf(b.project.tab)); }, [normalizedQuery, sourceSnapshots, sort]); const selected = sourceSnapshots.find((snapshot) => snapshot.project.tab === selectedTab) ??