Compare commits

...
Author SHA1 Message Date
Cursor AgentandJulius Marminge 237ffdb790 Add react-scan sidebar rerender recordings
Co-authored-by: Julius Marminge <[email protected]>
2026-06-01 16:14:47 +00:00
Cursor AgentandJulius Marminge e24259db42 Optimize sidebar unseen status subscriptions
Co-authored-by: Julius Marminge <[email protected]>
2026-06-01 16:12:00 +00:00
5 changed files with 88 additions and 33 deletions

No files matched your search

@@ -10,6 +10,7 @@ import {
getVisibleThreadsForProject,
getProjectSortTimestamp,
hasUnseenCompletion,
hasUnseenCompletionSinceVisit,
isContextMenuPointerDown,
orderItemsByPreferredIds,
resolveProjectStatusIndicator,
@@ -67,6 +68,32 @@ describe("hasUnseenCompletion", () => {
});
});
describe("hasUnseenCompletionSinceVisit", () => {
it("returns false when repeated visit updates stay after the completion", () => {
expect(
hasUnseenCompletionSinceVisit({
completedAt: "2026-03-09T10:05:00.000Z",
lastVisitedAt: "2026-03-09T10:06:00.000Z",
}),
).toBe(false);
expect(
hasUnseenCompletionSinceVisit({
completedAt: "2026-03-09T10:05:00.000Z",
lastVisitedAt: "2026-03-09T10:07:00.000Z",
}),
).toBe(false);
});
it("preserves the invalid last-visit fallback as unseen", () => {
expect(
hasUnseenCompletionSinceVisit({
completedAt: "2026-03-09T10:05:00.000Z",
lastVisitedAt: "not-a-date",
}),
).toBe(true);
});
});
describe("createThreadJumpHintVisibilityController", () => {
beforeEach(() => {
vi.useFakeTimers();
+15 -5
View File
@@ -144,17 +144,27 @@ export function useThreadJumpHintVisibility(): {
};
}
export function hasUnseenCompletion(thread: ThreadStatusInput): boolean {
if (!thread.latestTurn?.completedAt) return false;
const completedAt = Date.parse(thread.latestTurn.completedAt);
export function hasUnseenCompletionSinceVisit(input: {
completedAt: string | null | undefined;
lastVisitedAt?: string | null | undefined;
}): boolean {
if (!input.completedAt) return false;
const completedAt = Date.parse(input.completedAt);
if (Number.isNaN(completedAt)) return false;
if (!thread.lastVisitedAt) return true;
if (!input.lastVisitedAt) return true;
const lastVisitedAt = Date.parse(thread.lastVisitedAt);
const lastVisitedAt = Date.parse(input.lastVisitedAt);
if (Number.isNaN(lastVisitedAt)) return true;
return completedAt > lastVisitedAt;
}
export function hasUnseenCompletion(thread: ThreadStatusInput): boolean {
return hasUnseenCompletionSinceVisit({
completedAt: thread.latestTurn?.completedAt,
lastVisitedAt: thread.lastVisitedAt,
});
}
export function shouldClearThreadSelectionOnMouseDown(target: HTMLElement | null): boolean {
if (target === null) return true;
return !target.closest(THREAD_SELECTION_SAFE_SELECTOR);
+46 -28
View File
@@ -160,6 +160,7 @@ import { useThreadSelectionStore } from "../threadSelectionStore";
import { useCommandPaletteStore } from "../commandPaletteStore";
import {
getSidebarThreadIdsToPrewarm,
hasUnseenCompletionSinceVisit,
resolveAdjacentThreadId,
isContextMenuPointerDown,
resolveProjectStatusIndicator,
@@ -1047,14 +1048,21 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec
const projectExpanded = useUiStateStore(
(state) => state.projectExpandedById[project.projectKey] ?? true,
);
const threadLastVisitedAts = useUiStateStore(
useShallow((state) =>
projectThreads.map(
(thread) =>
state.threadLastVisitedAtById[
scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id))
] ?? null,
),
const projectThreadHasUnseenCompletions = useUiStateStore(
useShallow(
useMemo(() => {
const completionInputs = projectThreads.map((thread) => ({
completedAt: thread.latestTurn?.completedAt ?? null,
threadKey: scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id)),
}));
return (state) =>
completionInputs.map(({ completedAt, threadKey }) =>
hasUnseenCompletionSinceVisit({
completedAt,
lastVisitedAt: state.threadLastVisitedAtById[threadKey],
}),
);
}, [projectThreads]),
),
);
const [renamingThreadKey, setRenamingThreadKey] = useState<string | null>(null);
@@ -1099,20 +1107,25 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec
}, [memberProjectByScopedKey, project.memberProjects, projectThreads]);
const { projectStatus, visibleProjectThreads, orderedProjectThreadKeys } = useMemo(() => {
const lastVisitedAtByThreadKey = new Map(
projectThreads.map((thread, index) => [
scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id)),
threadLastVisitedAts[index] ?? null,
]),
const hasUnseenCompletionByThreadKey = new Map(
projectThreads.map(
(thread, index) =>
[
scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id)),
projectThreadHasUnseenCompletions[index] ?? false,
] as const,
),
);
const resolveProjectThreadStatus = (thread: SidebarThreadSummary) => {
const lastVisitedAt = lastVisitedAtByThreadKey.get(
scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id)),
);
const threadKey = scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id));
const hasUnseenCompletion = hasUnseenCompletionByThreadKey.get(threadKey) ?? false;
const lastVisitedAt = hasUnseenCompletion
? undefined
: (thread.latestTurn?.completedAt ?? undefined);
return resolveThreadStatusPill({
thread: {
...thread,
...(lastVisitedAt !== null && lastVisitedAt !== undefined ? { lastVisitedAt } : {}),
...(lastVisitedAt !== undefined ? { lastVisitedAt } : {}),
},
});
};
@@ -1130,7 +1143,7 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec
projectStatus,
visibleProjectThreads,
};
}, [projectThreads, threadLastVisitedAts, threadSortOrder]);
}, [projectThreadHasUnseenCompletions, projectThreads, threadSortOrder]);
const pinnedCollapsedThread = useMemo(() => {
const activeThreadKey = activeRouteThreadKey ?? undefined;
@@ -1152,20 +1165,25 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec
showEmptyThreadState,
shouldShowThreadPanel,
} = useMemo(() => {
const lastVisitedAtByThreadKey = new Map(
projectThreads.map((thread, index) => [
scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id)),
threadLastVisitedAts[index] ?? null,
]),
const hasUnseenCompletionByThreadKey = new Map(
projectThreads.map(
(thread, index) =>
[
scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id)),
projectThreadHasUnseenCompletions[index] ?? false,
] as const,
),
);
const resolveProjectThreadStatus = (thread: SidebarThreadSummary) => {
const lastVisitedAt = lastVisitedAtByThreadKey.get(
scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id)),
);
const threadKey = scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id));
const hasUnseenCompletion = hasUnseenCompletionByThreadKey.get(threadKey) ?? false;
const lastVisitedAt = hasUnseenCompletion
? undefined
: (thread.latestTurn?.completedAt ?? undefined);
return resolveThreadStatusPill({
thread: {
...thread,
...(lastVisitedAt !== null && lastVisitedAt !== undefined ? { lastVisitedAt } : {}),
...(lastVisitedAt !== undefined ? { lastVisitedAt } : {}),
},
});
};
@@ -1202,8 +1220,8 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec
pinnedCollapsedThread,
projectExpanded,
projectThreads,
projectThreadHasUnseenCompletions,
sidebarThreadPreviewCount,
threadLastVisitedAts,
visibleProjectThreads,
]);
Binary file not shown.
Binary file not shown.