@devries-cameron20 / t3code Mirror · read-only / commits / 7455472c34
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 25, 05:00 UTC

Reduce sidebar selection rerenders (#2560)

Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>

cursor[bot] committed May 7, 2026 at 21:44 UTC 7455472c347de3255a8f9f1306b8c4cd96eac5d4
1 file changed +5 -15
apps/web/src/components/Sidebar.tsx
+5 -15
@@ -341,7 +341,6 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
341 const threadKey = scopedThreadKey(threadRef);
342 const lastVisitedAt = useUiStateStore((state) => state.threadLastVisitedAtById[threadKey]);
343 const isSelected = useThreadSelectionStore((state) => state.selectedThreadKeys.has(threadKey));
344 - const hasSelection = useThreadSelectionStore((state) => state.selectedThreadKeys.size > 0);
344 const runningTerminalIds = useTerminalStateStore(
345 (state) =>
346 selectThreadTerminalState(state.terminalStateByThreadKey, threadRef).runningTerminalIds,
@@ -427,6 +426,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
426 const handleRowContextMenu = useCallback(
427 (event: React.MouseEvent) => {
428 event.preventDefault();
429 + const hasSelection = useThreadSelectionStore.getState().hasSelection();
430 if (hasSelection && isSelected) {
431 void handleMultiSelectContextMenu({
432 x: event.clientX,
@@ -443,14 +443,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
443 y: event.clientY,
444 });
445 },
446 - [
447 - clearSelection,
448 - handleMultiSelectContextMenu,
449 - handleThreadContextMenu,
450 - hasSelection,
451 - isSelected,
452 - threadRef,
453 - ],
446 + [clearSelection, handleMultiSelectContextMenu, handleThreadContextMenu, isSelected, threadRef],
447 );
448 const handlePrClick = useCallback(
449 (event: React.MouseEvent<HTMLButtonElement>) => {
@@ -964,7 +957,6 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec
957 const clearSelection = useThreadSelectionStore((state) => state.clearSelection);
958 const removeFromSelection = useThreadSelectionStore((state) => state.removeFromSelection);
959 const setSelectionAnchor = useThreadSelectionStore((state) => state.setAnchor);
967 - const selectedThreadCount = useThreadSelectionStore((state) => state.selectedThreadKeys.size);
960 const { copyToClipboard: copyThreadIdToClipboard } = useCopyToClipboard<{
961 threadId: ThreadId;
962 }>({
@@ -1235,7 +1227,7 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec
1227 event.stopPropagation();
1228 return;
1229 }
1238 - if (selectedThreadCount > 0) {
1230 + if (useThreadSelectionStore.getState().hasSelection()) {
1231 clearSelection();
1232 }
1233 toggleProject(project.projectKey);
@@ -1244,7 +1236,6 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec
1236 clearSelection,
1237 dragInProgressRef,
1238 project.projectKey,
1247 - selectedThreadCount,
1239 suppressProjectClickAfterDragRef,
1240 suppressProjectClickForContextMenuRef,
1241 toggleProject,
@@ -2833,7 +2824,6 @@ export default function Sidebar() {
2824 const suppressProjectClickAfterDragRef = useRef(false);
2825 const suppressProjectClickForContextMenuRef = useRef(false);
2826 const [desktopUpdateState, setDesktopUpdateState] = useState<DesktopUpdateState | null>(null);
2836 - const selectedThreadCount = useThreadSelectionStore((s) => s.selectedThreadKeys.size);
2827 const clearSelection = useThreadSelectionStore((s) => s.clearSelection);
2828 const setSelectionAnchor = useThreadSelectionStore((s) => s.setAnchor);
2829 const platform = navigator.platform;
@@ -3279,7 +3269,7 @@ export default function Sidebar() {
3269
3270 useEffect(() => {
3271 const onMouseDown = (event: globalThis.MouseEvent) => {
3282 - if (selectedThreadCount === 0) return;
3272 + if (!useThreadSelectionStore.getState().hasSelection()) return;
3273 const target = event.target instanceof HTMLElement ? event.target : null;
3274 if (!shouldClearThreadSelectionOnMouseDown(target)) return;
3275 clearSelection();
@@ -3289,7 +3279,7 @@ export default function Sidebar() {
3279 return () => {
3280 window.removeEventListener("mousedown", onMouseDown);
3281 };
3292 - }, [clearSelection, selectedThreadCount]);
3282 + }, [clearSelection]);
3283
3284 useEffect(() => {
3285 if (!isElectron) return;