From 7455472c347de3255a8f9f1306b8c4cd96eac5d4 Mon Sep 17 00:00:00 2001 From: "cursor[bot]" <206951365+cursor[bot]@users.noreply.github.com> Date: Thu, 7 May 2026 21:44:30 -0700 Subject: [PATCH] Reduce sidebar selection rerenders (#2560) Co-authored-by: Cursor Agent Co-authored-by: Julius Marminge --- apps/web/src/components/Sidebar.tsx | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsx index b14bc5b9d2bf12bf2e9e5c52af7423a32cc51e66..3d0ccd3ab7caaab3ef0185e26688645775b369b0 100644 --- a/apps/web/src/components/Sidebar.tsx +++ b/apps/web/src/components/Sidebar.tsx @@ -341,7 +341,6 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP const threadKey = scopedThreadKey(threadRef); const lastVisitedAt = useUiStateStore((state) => state.threadLastVisitedAtById[threadKey]); const isSelected = useThreadSelectionStore((state) => state.selectedThreadKeys.has(threadKey)); - const hasSelection = useThreadSelectionStore((state) => state.selectedThreadKeys.size > 0); const runningTerminalIds = useTerminalStateStore( (state) => selectThreadTerminalState(state.terminalStateByThreadKey, threadRef).runningTerminalIds, @@ -427,6 +426,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP const handleRowContextMenu = useCallback( (event: React.MouseEvent) => { event.preventDefault(); + const hasSelection = useThreadSelectionStore.getState().hasSelection(); if (hasSelection && isSelected) { void handleMultiSelectContextMenu({ x: event.clientX, @@ -443,14 +443,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP y: event.clientY, }); }, - [ - clearSelection, - handleMultiSelectContextMenu, - handleThreadContextMenu, - hasSelection, - isSelected, - threadRef, - ], + [clearSelection, handleMultiSelectContextMenu, handleThreadContextMenu, isSelected, threadRef], ); const handlePrClick = useCallback( (event: React.MouseEvent) => { @@ -964,7 +957,6 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec const clearSelection = useThreadSelectionStore((state) => state.clearSelection); const removeFromSelection = useThreadSelectionStore((state) => state.removeFromSelection); const setSelectionAnchor = useThreadSelectionStore((state) => state.setAnchor); - const selectedThreadCount = useThreadSelectionStore((state) => state.selectedThreadKeys.size); const { copyToClipboard: copyThreadIdToClipboard } = useCopyToClipboard<{ threadId: ThreadId; }>({ @@ -1235,7 +1227,7 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec event.stopPropagation(); return; } - if (selectedThreadCount > 0) { + if (useThreadSelectionStore.getState().hasSelection()) { clearSelection(); } toggleProject(project.projectKey); @@ -1244,7 +1236,6 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec clearSelection, dragInProgressRef, project.projectKey, - selectedThreadCount, suppressProjectClickAfterDragRef, suppressProjectClickForContextMenuRef, toggleProject, @@ -2833,7 +2824,6 @@ export default function Sidebar() { const suppressProjectClickAfterDragRef = useRef(false); const suppressProjectClickForContextMenuRef = useRef(false); const [desktopUpdateState, setDesktopUpdateState] = useState(null); - const selectedThreadCount = useThreadSelectionStore((s) => s.selectedThreadKeys.size); const clearSelection = useThreadSelectionStore((s) => s.clearSelection); const setSelectionAnchor = useThreadSelectionStore((s) => s.setAnchor); const platform = navigator.platform; @@ -3279,7 +3269,7 @@ export default function Sidebar() { useEffect(() => { const onMouseDown = (event: globalThis.MouseEvent) => { - if (selectedThreadCount === 0) return; + if (!useThreadSelectionStore.getState().hasSelection()) return; const target = event.target instanceof HTMLElement ? event.target : null; if (!shouldClearThreadSelectionOnMouseDown(target)) return; clearSelection(); @@ -3289,7 +3279,7 @@ export default function Sidebar() { return () => { window.removeEventListener("mousedown", onMouseDown); }; - }, [clearSelection, selectedThreadCount]); + }, [clearSelection]); useEffect(() => { if (!isElectron) return; -- 2.54.0