@@ -95,11 +95,14 @@ export function useLinkedThreadPullRequest(
9595 branchPullRequest ?: ThreadLinkedPullRequest | null ,
9696) : LinkedThreadPullRequestStatus | null {
9797 const supportsLinks = useSupportsMultiplePullRequests ( environmentId ) ;
98- const { current, currentStatus } = useCurrentPullRequestLink ( supportsLinks , pullRequests ) ;
98+ const current = supportsLinks ? resolveThreadCurrentPullRequestLink ( pullRequests ?? [ ] ) : null ;
99+ // Callers key on the returned status, so it stays cached across the query hooks.
100+ const currentStatus = current === null ? null : linkedPullRequestSnapshotStatus ( current ) ;
99101 const fallback =
100102 current === null ? ( ( ! supportsLinks ? linkedPullRequest : null ) ?? branchPullRequest ) : null ;
101- // A sidebar row must not touch the summary cache on every render.
102- const reference = useLinkedPullRequestReference ( fallback ) ;
103+ // The query atom and shared summary effect key on this object, and a sidebar row
104+ // must not touch the summary cache on every render.
105+ const reference = fallback == null ? null : linkedPullRequestReference ( fallback ) ;
103106 const queried = useEnvironmentQuery (
104107 ! enabled || environmentId === null || reference === null
105108 ? null
@@ -121,24 +124,7 @@ export function useLinkedThreadPullRequest(
121124 } ;
122125}
123126
124- // Callers key on the returned status, so it stays stable across the query hooks.
125- function useCurrentPullRequestLink (
126- supportsLinks : boolean ,
127- pullRequests : ReadonlyArray < ThreadPullRequestLink > | undefined ,
128- ) {
129- "use memo" ;
130- const current = supportsLinks ? resolveThreadCurrentPullRequestLink ( pullRequests ?? [ ] ) : null ;
131- return {
132- current,
133- currentStatus : current === null ? null : linkedPullRequestSnapshotStatus ( current ) ,
134- } ;
135- }
136-
137- // The query atom and shared summary effect key on this object, so it stays
138- // stable per link across the hooks that read it.
139- function useLinkedPullRequestReference ( fallback : ThreadLinkedPullRequest | null | undefined ) {
140- "use memo" ;
141- if ( fallback == null ) return null ;
127+ function linkedPullRequestReference ( fallback : ThreadLinkedPullRequest ) {
142128 const host = parseChangeRequestUrl ( fallback . url ) ?. host ;
143129 return { ...fallback , ...( host === undefined ? { } : { host } ) } ;
144130}
0 commit comments