@@ -12,9 +12,8 @@ import { connectionAtomRuntime } from "../connection/runtime";
1212import { appAtomRegistry } from "./atom-registry" ;
1313import { useEnvironmentQuery } from "./query" ;
1414import { presentThreadPr , type ThreadPrPresentation } from "./thread-pr-presentation" ;
15- import { vcsEnvironment } from "./vcs" ;
1615
17- const linkedPullRequestDetailAtom = createLinkedPullRequestSummaryAtomFamily ( connectionAtomRuntime ) ;
16+ const pullRequestSummaryAtom = createLinkedPullRequestSummaryAtomFamily ( connectionAtomRuntime ) ;
1817const MAX_THREAD_PR_SNAPSHOTS = 500 ;
1918
2019interface ThreadPrSnapshot {
@@ -23,7 +22,7 @@ interface ThreadPrSnapshot {
2322}
2423
2524// One bounded cache survives row virtualization without retaining one live
26- // atom for every thread, branch, directory, or linked pull request ever seen.
25+ // atom for every thread or pull request ever seen.
2726const threadPrSnapshotsAtom = Atom . make < ReadonlyMap < string , ThreadPrSnapshot > > ( new Map ( ) ) . pipe (
2827 Atom . keepAlive ,
2928 Atom . withLabel ( "mobile:thread-pr-snapshots" ) ,
@@ -36,20 +35,13 @@ export {
3635} from "./thread-pr-presentation" ;
3736
3837/**
39- * Live PR status for a thread's branch. Subscriptions are deduplicated per
40- * (environmentId, cwd) by the atom family, so many rows on the same worktree
41- * or project root share one stream — and virtualization means only visible
42- * rows subscribe at all.
38+ * Live status for a thread's server-provided PR. Visible rows share a summary
39+ * request for the same PR in the same environment.
4340 */
44- export function useThreadPr (
45- thread : EnvironmentThreadShell ,
46- projectCwd : string | null ,
47- ) : ThreadPrPresentation | null {
48- const cwd = thread . worktreePath ?? projectCwd ;
41+ export function useThreadPr ( thread : EnvironmentThreadShell ) : ThreadPrPresentation | null {
42+ const pullRequestRef = thread . linkedPullRequest ?? thread . branchPullRequest ?? null ;
4943 const threadKey = scopedThreadKey ( scopeThreadRef ( thread . environmentId , thread . id ) ) ;
50- const snapshotIdentity = JSON . stringify (
51- thread . linkedPullRequest ?? { branch : thread . branch , cwd } ,
52- ) ;
44+ const snapshotIdentity = JSON . stringify ( pullRequestRef ) ;
5345 // Select this row's entry so writes for other rows do not re-render it.
5446 const snapshotEntry = useAtomValue (
5547 threadPrSnapshotsAtom ,
@@ -59,45 +51,30 @@ export function useThreadPr(
5951 ) ,
6052 ) ;
6153 const snapshot = snapshotEntry ?. identity === snapshotIdentity ? snapshotEntry . presentation : null ;
62- const gitStatus = useEnvironmentQuery (
63- thread . linkedPullRequest == null && thread . branch !== null && cwd !== null
64- ? vcsEnvironment . status ( {
65- environmentId : thread . environmentId ,
66- input : { cwd } ,
67- } )
68- : null ,
69- ) ;
70- const linkedPullRequest = useEnvironmentQuery (
71- thread . linkedPullRequest == null
54+ const pullRequestSummary = useEnvironmentQuery (
55+ pullRequestRef === null
7256 ? null
73- : linkedPullRequestDetailAtom ( {
57+ : pullRequestSummaryAtom ( {
7458 environmentId : thread . environmentId ,
7559 input : {
76- projectId : thread . linkedPullRequest . projectId ,
77- repository : thread . linkedPullRequest . repository ,
78- number : thread . linkedPullRequest . number ,
60+ projectId : pullRequestRef . projectId ,
61+ repository : pullRequestRef . repository ,
62+ number : pullRequestRef . number ,
7963 } ,
8064 } ) ,
8165 ) ;
8266
8367 const live = useMemo < ThreadPrPresentation | null | undefined > ( ( ) => {
84- if ( thread . linkedPullRequest != null ) {
85- const detail = linkedPullRequest . data ;
86- return detail === null
87- ? undefined
88- : presentThreadPr ( pullRequestDetailToVcsStatus ( detail ) , {
89- kind : detail . provider ,
90- name : detail . provider ,
91- baseUrl : "" ,
92- } ) ;
93- }
94-
95- const status = gitStatus . data ;
96- if ( thread . branch === null ) return null ;
97- if ( status === null ) return undefined ;
98- if ( status . refName !== thread . branch || ! status . pr ) return null ;
99- return presentThreadPr ( status . pr , status . sourceControlProvider ) ;
100- } , [ gitStatus . data , linkedPullRequest . data , thread . branch , thread . linkedPullRequest ] ) ;
68+ if ( pullRequestRef === null ) return null ;
69+ const summary = pullRequestSummary . data ;
70+ return summary === null
71+ ? undefined
72+ : presentThreadPr ( pullRequestDetailToVcsStatus ( summary ) , {
73+ kind : summary . provider ,
74+ name : summary . provider ,
75+ baseUrl : "" ,
76+ } ) ;
77+ } , [ pullRequestRef , pullRequestSummary . data ] ) ;
10178
10279 useEffect ( ( ) => {
10380 if ( live === undefined ) return ;
0 commit comments