From 7f1949ec9fa88050a3242f573794435eae7c9427 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Fri, 29 May 2026 16:18:29 +0000 Subject: [PATCH] Optimize sidebar PR status rerenders Co-authored-by: Julius Marminge --- apps/web/src/components/Sidebar.tsx | 105 +++++++++++++++------------- 1 file changed, 58 insertions(+), 47 deletions(-) diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsx index 1b96bb71cb..a4b3f24ce2 100644 --- a/apps/web/src/components/Sidebar.tsx +++ b/apps/web/src/components/Sidebar.tsx @@ -278,7 +278,6 @@ function buildThreadJumpLabelMap(input: { interface SidebarThreadRowProps { thread: SidebarThreadSummary; - projectCwd: string | null; orderedProjectThreadKeys: readonly string[]; isActive: boolean; jumpLabel: string | null; @@ -313,6 +312,61 @@ interface SidebarThreadRowProps { openPrLink: (event: React.MouseEvent, prUrl: string) => void; } +interface SidebarThreadPrStatusButtonProps { + thread: SidebarThreadSummary; + openPrLink: (event: React.MouseEvent, prUrl: string) => void; +} + +const SidebarThreadPrStatusButton = memo(function SidebarThreadPrStatusButton( + props: SidebarThreadPrStatusButtonProps, +) { + const { thread, openPrLink } = props; + const threadProjectCwd = useStore( + useMemo( + () => (state: import("../store").AppState) => + selectProjectByRef(state, scopeProjectRef(thread.environmentId, thread.projectId))?.cwd ?? + null, + [thread.environmentId, thread.projectId], + ), + ); + const gitCwd = thread.worktreePath ?? threadProjectCwd; + const gitStatus = useGitStatus({ + environmentId: thread.environmentId, + cwd: thread.branch != null ? gitCwd : null, + }); + const pr = resolveThreadPr(thread.branch, gitStatus.data); + const prStatus = prStatusIndicator(pr, gitStatus.data?.sourceControlProvider); + const handlePrClick = useCallback( + (event: React.MouseEvent) => { + if (!prStatus) return; + openPrLink(event, prStatus.url); + }, + [openPrLink, prStatus], + ); + + if (!prStatus) { + return null; + } + + return ( + + + + + } + /> + {prStatus.tooltip} + + ); +}); + const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowProps) { const { orderedProjectThreadKeys, @@ -358,22 +412,6 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP const threadEnvironmentLabel = isRemoteThread ? (remoteEnvLabel ?? remoteEnvSavedLabel ?? "Remote") : null; - // For grouped projects, the thread may belong to a different environment - // than the representative project. Look up the thread's own project cwd - // so git status (and thus PR detection) queries the correct path. - const threadProjectCwd = useStore( - useMemo( - () => (state: import("../store").AppState) => - selectProjectByRef(state, scopeProjectRef(thread.environmentId, thread.projectId))?.cwd ?? - null, - [thread.environmentId, thread.projectId], - ), - ); - const gitCwd = thread.worktreePath ?? threadProjectCwd ?? props.projectCwd; - const gitStatus = useGitStatus({ - environmentId: thread.environmentId, - cwd: thread.branch != null ? gitCwd : null, - }); const isHighlighted = isActive || isSelected; const isThreadRunning = thread.session?.status === "running" && thread.session.activeTurnId != null; @@ -383,8 +421,6 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP lastVisitedAt, }, }); - const pr = resolveThreadPr(thread.branch, gitStatus.data); - const prStatus = prStatusIndicator(pr, gitStatus.data?.sourceControlProvider); const terminalStatus = terminalStatusFromRunningIds(runningTerminalIds); const isConfirmingArchive = confirmingArchiveThreadKey === threadKey && !isThreadRunning; const threadMetaClassName = isConfirmingArchive @@ -446,13 +482,6 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP }, [clearSelection, handleMultiSelectContextMenu, handleThreadContextMenu, isSelected, threadRef], ); - const handlePrClick = useCallback( - (event: React.MouseEvent) => { - if (!prStatus) return; - openPrLink(event, prStatus.url); - }, - [openPrLink, prStatus], - ); const handleRenameInputRef = useCallback( (element: HTMLInputElement | null) => { if (element && renamingInputRef.current !== element) { @@ -559,23 +588,9 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP onContextMenu={handleRowContextMenu} >
- {prStatus && ( - - - - - } - /> - {prStatus.tooltip} - - )} + {thread.branch !== null ? ( + + ) : null} {threadStatus && } {renamingThreadKey === threadKey ? ( ; appSettingsConfirmThreadArchive: boolean; @@ -778,7 +792,6 @@ const SidebarProjectThreadList = memo(function SidebarProjectThreadList( showEmptyThreadState, shouldShowThreadPanel, isThreadListExpanded, - projectCwd, activeRouteThreadKey, threadJumpLabelByKey, appSettingsConfirmThreadArchive, @@ -828,7 +841,6 @@ const SidebarProjectThreadList = memo(function SidebarProjectThreadList(