@@ -143,6 +143,8 @@ import {
143143 sortPinnedThreadsForSidebar ,
144144 sortSettledThreadsForSidebar ,
145145 sortThreadsForSidebar ,
146+ useRetainedValue ,
147+ useSidebarRowSubscriptionLease ,
146148 useThreadJumpHintVisibility ,
147149} from "./Sidebar.logic" ;
148150import { resolveLocalCheckoutBranchMismatch } from "./BranchToolbar.logic" ;
@@ -787,6 +789,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
787789 [ thread . environmentId , thread . id ] ,
788790 ) ;
789791 const threadKey = scopedThreadKey ( threadRef ) ;
792+ const { leaseLiveStatus, rowRef } = useSidebarRowSubscriptionLease ( props . isActive ) ;
790793 const isRegeneratingTitle = thread . titleRegeneration != null ;
791794 const lastVisitedAt = useUiStateStore ( ( state ) => state . threadLastVisitedAtById [ threadKey ] ) ;
792795 const isSelected = useThreadSelectionStore ( ( state ) => state . selectedThreadKeys . has ( threadKey ) ) ;
@@ -800,21 +803,25 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
800803
801804 const gitCwd = thread . worktreePath ?? props . projectCwd ;
802805 const linkedPullRequestStatus = useLinkedThreadPullRequest (
803- thread . environmentId ,
804- thread . linkedPullRequest ,
806+ leaseLiveStatus ? thread . environmentId : null ,
807+ leaseLiveStatus ? thread . linkedPullRequest : null ,
805808 ) ;
806809 const gitStatus = useEnvironmentQuery (
807- ( thread . branch != null || thread . worktreePath !== null ) && gitCwd !== null
810+ leaseLiveStatus && ( thread . branch != null || thread . worktreePath !== null ) && gitCwd !== null
808811 ? vcsEnvironment . status ( {
809812 environmentId : thread . environmentId ,
810813 input : { cwd : gitCwd } ,
811814 } )
812815 : null ,
813816 ) ;
817+ const visibleGitStatus = useRetainedValue (
818+ JSON . stringify ( [ thread . environmentId , gitCwd ] ) ,
819+ gitStatus . data ,
820+ ) ;
814821 const retainTerminalOnBranchMismatch = thread . worktreePath === null ;
815822 const pr = resolveDisplayedThreadPr ( {
816823 threadBranch : thread . branch ,
817- gitStatus : gitStatus . data ,
824+ gitStatus : visibleGitStatus ,
818825 snapshot : changeRequestSnapshot ,
819826 retainTerminalOnBranchMismatch,
820827 linkedPullRequest : thread . linkedPullRequest ,
@@ -909,11 +916,11 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
909916 effectiveEnvMode : thread . worktreePath === null ? "local" : "worktree" ,
910917 activeWorktreePath : thread . worktreePath ,
911918 activeThreadBranch : thread . branch ,
912- currentGitBranch : gitStatus . data ?. refName ?? null ,
919+ currentGitBranch : visibleGitStatus ?. refName ?? null ,
913920 } ) ;
914921 const prProvider = resolveDisplayedThreadPrProvider ( {
915922 threadBranch : thread . branch ,
916- gitStatus : gitStatus . data ,
923+ gitStatus : visibleGitStatus ,
917924 snapshot : changeRequestSnapshot ,
918925 retainTerminalOnBranchMismatch,
919926 linkedPullRequest : thread . linkedPullRequest ,
@@ -924,7 +931,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
924931 useEffect ( ( ) => {
925932 const nextSnapshot = nextThreadChangeRequestSnapshot ( {
926933 threadBranch : thread . branch ,
927- gitStatus : gitStatus . data ,
934+ gitStatus : visibleGitStatus ,
928935 snapshot : changeRequestSnapshot ,
929936 retainTerminalOnBranchMismatch,
930937 linkedPullRequest : thread . linkedPullRequest ,
@@ -934,7 +941,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
934941 onChangeRequestSnapshot ( threadKey , nextSnapshot ) ;
935942 } , [
936943 changeRequestSnapshot ,
937- gitStatus . data ,
944+ visibleGitStatus ,
938945 linkedPullRequestStatus ,
939946 onChangeRequestSnapshot ,
940947 retainTerminalOnBranchMismatch ,
@@ -1246,6 +1253,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
12461253 < TooltipTrigger
12471254 render = {
12481255 < div
1256+ ref = { rowRef }
12491257 role = "button"
12501258 tabIndex = { 0 }
12511259 data-testid = "sidebar-row-slim"
@@ -1407,6 +1415,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
14071415 < TooltipTrigger
14081416 render = {
14091417 < div
1418+ ref = { rowRef }
14101419 role = "button"
14111420 tabIndex = { 0 }
14121421 data-testid = "sidebar-row-card"
@@ -1635,22 +1644,29 @@ const SidebarSearchResultRow = memo(function SidebarSearchResultRow(props: {
16351644 onSelect : ( ) => void ;
16361645} ) {
16371646 const { thread } = props ;
1647+ const { leaseLiveStatus, rowRef } = useSidebarRowSubscriptionLease (
1648+ props . isHighlighted || props . isRouteActive ,
1649+ ) ;
16381650 // Same details tooltip as the regular rows: a search hit is still a thread,
16391651 // and the hover card is how you disambiguate identically-titled results.
16401652 const gitCwd = thread . worktreePath ?? props . projectCwd ;
16411653 const gitStatus = useEnvironmentQuery (
1642- ( thread . branch != null || thread . worktreePath !== null ) && gitCwd !== null
1654+ leaseLiveStatus && ( thread . branch != null || thread . worktreePath !== null ) && gitCwd !== null
16431655 ? vcsEnvironment . status ( {
16441656 environmentId : thread . environmentId ,
16451657 input : { cwd : gitCwd } ,
16461658 } )
16471659 : null ,
16481660 ) ;
1661+ const visibleGitStatus = useRetainedValue (
1662+ JSON . stringify ( [ thread . environmentId , gitCwd ] ) ,
1663+ gitStatus . data ,
1664+ ) ;
16491665 const branchMismatch = resolveLocalCheckoutBranchMismatch ( {
16501666 effectiveEnvMode : thread . worktreePath === null ? "local" : "worktree" ,
16511667 activeWorktreePath : thread . worktreePath ,
16521668 activeThreadBranch : thread . branch ,
1653- currentGitBranch : gitStatus . data ?. refName ?? null ,
1669+ currentGitBranch : visibleGitStatus ?. refName ?? null ,
16541670 } ) ;
16551671 const modelInstanceId = thread . session ?. providerInstanceId ?? thread . modelSelection . instanceId ;
16561672 const providerEntry = props . providerEntryByInstanceId . get ( modelInstanceId ) ?? null ;
@@ -1674,6 +1690,7 @@ const SidebarSearchResultRow = memo(function SidebarSearchResultRow(props: {
16741690 < TooltipTrigger
16751691 render = {
16761692 < button
1693+ ref = { rowRef }
16771694 id = { props . resultId }
16781695 type = "button"
16791696 role = "option"
0 commit comments