@@ -143,10 +143,15 @@ import {
143143import { resolveLocalCheckoutBranchMismatch } from "./BranchToolbar.logic" ;
144144import {
145145 ThreadWorktreeIndicator ,
146+ nextThreadChangeRequestSnapshot ,
146147 prStatusIndicator ,
147- resolveThreadPr ,
148+ resolveDisplayedThreadPr ,
149+ resolveDisplayedThreadPrProvider ,
150+ setThreadChangeRequestSnapshot ,
148151 settledPrHoverColorClass ,
149152 terminalStatusFromRunningIds ,
153+ threadChangeRequestSnapshotsAtom ,
154+ type ThreadChangeRequestSnapshot ,
150155 type TerminalStatusIndicator ,
151156} from "./ThreadStatusIndicators" ;
152157import {
@@ -729,11 +734,16 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
729734 onUnsnooze : ( threadRef : ScopedThreadRef ) => void ;
730735 onUnpin : ( threadRef : ScopedThreadRef ) => void ;
731736 onAcknowledgeWoke : ( threadRef : ScopedThreadRef , visitedAt : string ) => void ;
732- onChangeRequestState : ( threadKey : string , state : "open" | "closed" | "merged" | null ) => void ;
737+ changeRequestSnapshot : ThreadChangeRequestSnapshot | null ;
738+ onChangeRequestSnapshot : (
739+ threadKey : string ,
740+ snapshot : ThreadChangeRequestSnapshot | null ,
741+ ) => void ;
733742} ) {
734743 const {
735744 isRenaming,
736- onChangeRequestState,
745+ changeRequestSnapshot,
746+ onChangeRequestSnapshot,
737747 onCancelRename,
738748 onCommitRename,
739749 onContextMenu,
@@ -778,9 +788,12 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
778788 } )
779789 : null ,
780790 ) ;
781- const pr = resolveThreadPr ( {
791+ const retainTerminalOnBranchMismatch = thread . worktreePath === null ;
792+ const pr = resolveDisplayedThreadPr ( {
782793 threadBranch : thread . branch ,
783794 gitStatus : gitStatus . data ,
795+ snapshot : changeRequestSnapshot ,
796+ retainTerminalOnBranchMismatch,
784797 } ) ;
785798 const prState = pr ?. state ?? null ;
786799
@@ -874,13 +887,31 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
874887 activeThreadBranch : thread . branch ,
875888 currentGitBranch : gitStatus . data ?. refName ?? null ,
876889 } ) ;
877- const prStatus = prStatusIndicator ( pr , gitStatus . data ?. sourceControlProvider ) ;
890+ const prProvider = resolveDisplayedThreadPrProvider ( {
891+ threadBranch : thread . branch ,
892+ gitStatus : gitStatus . data ,
893+ snapshot : changeRequestSnapshot ,
894+ retainTerminalOnBranchMismatch,
895+ } ) ;
896+ const prStatus = prStatusIndicator ( pr , prProvider ) ;
878897 const settledPrHoverClass = pr ? settledPrHoverColorClass ( pr . state ) : undefined ;
879- // Report the PR state so the parent can apply the configured merge rule
880- // and the always-on close rule during partitioning.
881898 useEffect ( ( ) => {
882- onChangeRequestState ( threadKey , prState ) ;
883- } , [ onChangeRequestState , prState , threadKey ] ) ;
899+ const nextSnapshot = nextThreadChangeRequestSnapshot ( {
900+ threadBranch : thread . branch ,
901+ gitStatus : gitStatus . data ,
902+ snapshot : changeRequestSnapshot ,
903+ retainTerminalOnBranchMismatch,
904+ } ) ;
905+ if ( nextSnapshot === undefined ) return ;
906+ onChangeRequestSnapshot ( threadKey , nextSnapshot ) ;
907+ } , [
908+ changeRequestSnapshot ,
909+ gitStatus . data ,
910+ onChangeRequestSnapshot ,
911+ retainTerminalOnBranchMismatch ,
912+ thread . branch ,
913+ threadKey ,
914+ ] ) ;
884915
885916 const modelInstanceId = thread . session ?. providerInstanceId ?? thread . modelSelection . instanceId ;
886917 const providerEntry = props . providerEntryByInstanceId . get ( modelInstanceId ) ?? null ;
@@ -1858,26 +1889,7 @@ export default function Sidebar() {
18581889 // fresh clock whenever it recomputes.
18591890 const [ snoozeWakeTick , bumpSnoozeWakeTick ] = useState ( 0 ) ;
18601891
1861- // PR states stream in per-row. The next partition applies the configured
1862- // merge rule and the always-on close rule.
1863- const [ changeRequestStateByKey , setChangeRequestStateByKey ] = useState <
1864- ReadonlyMap < string , "open" | "closed" | "merged" >
1865- > ( ( ) => new Map ( ) ) ;
1866- const handleChangeRequestState = useCallback (
1867- ( threadKey : string , state : "open" | "closed" | "merged" | null ) => {
1868- setChangeRequestStateByKey ( ( current ) => {
1869- if ( ( current . get ( threadKey ) ?? null ) === state ) return current ;
1870- const next = new Map ( current ) ;
1871- if ( state === null ) {
1872- next . delete ( threadKey ) ;
1873- } else {
1874- next . set ( threadKey , state ) ;
1875- }
1876- return next ;
1877- } ) ;
1878- } ,
1879- [ ] ,
1880- ) ;
1892+ const changeRequestSnapshotByKey = useAtomValue ( threadChangeRequestSnapshotsAtom ) ;
18811893
18821894 // Project scope: one menu above the list. Scoping filters the list without
18831895 // making the header width depend on the number or length of project names.
@@ -1993,7 +2005,11 @@ export default function Sidebar() {
19932005 const supportsSnooze =
19942006 serverConfigs . get ( thread . environmentId ) ?. environment . capabilities . threadSnooze === true ;
19952007 const threadKey = scopedThreadKey ( scopeThreadRef ( thread . environmentId , thread . id ) ) ;
1996- const changeRequestState = changeRequestStateByKey . get ( threadKey ) ?? null ;
2008+ const snapshot = changeRequestSnapshotByKey . get ( threadKey ) ;
2009+ const changeRequestState =
2010+ snapshot != null && ( thread . worktreePath === null || snapshot . branch === thread . branch )
2011+ ? snapshot . pr . state
2012+ : null ;
19972013 // Snooze outranks everything, including a pin: "hide until Tuesday"
19982014 // temporarily suspends "keep on top". The pin survives underneath —
19992015 // and so does its pinOrderKey, so on wake the thread reappears at
@@ -2051,7 +2067,7 @@ export default function Sidebar() {
20512067 } , [
20522068 autoSettleAfterDays ,
20532069 autoSettleOnMerge ,
2054- changeRequestStateByKey ,
2070+ changeRequestSnapshotByKey ,
20552071 nowMinute ,
20562072 scopedProjectKeys ,
20572073 serverConfigs ,
@@ -3686,7 +3702,8 @@ export default function Sidebar() {
36863702 onUnsnooze = { attemptUnsnooze }
36873703 onUnpin = { attemptUnpin }
36883704 onAcknowledgeWoke = { acknowledgeWoke }
3689- onChangeRequestState = { handleChangeRequestState }
3705+ changeRequestSnapshot = { changeRequestSnapshotByKey . get ( threadKey ) ?? null }
3706+ onChangeRequestSnapshot = { setThreadChangeRequestSnapshot }
36903707 />
36913708 ) ;
36923709 } ;
0 commit comments