@@ -126,6 +126,7 @@ import {
126126 isStackedPullRequestBase ,
127127 pullRequestActionNeedsHostRefresh ,
128128 pullRequestCheckoutCommand ,
129+ pullRequestCommentLinkMayLoad ,
129130 pullRequestCommentLinkTarget ,
130131 pullRequestConversationItems ,
131132 pullRequestFindingKey ,
@@ -305,7 +306,8 @@ export function PullRequestDetailPanel({
305306 onTabChange ?: ( ( tab : PullRequestDetailTab ) => void ) | undefined ;
306307 /** A link that may name one of this pull request's comments, waiting to be shown. */
307308 revealUrl ?: string | undefined ;
308- onRevealSettled ?: ( ( ) => void ) | undefined ;
309+ /** Reports the link it was given shown or missing, so a newer link is left pending. */
310+ onRevealSettled ?: ( ( revealUrl : string ) => void ) | undefined ;
309311} ) {
310312 const environmentConfigs = useServerConfigs ( ) ;
311313 const projects = useProjects ( ) ;
@@ -363,13 +365,14 @@ export function PullRequestDetailPanel({
363365 detail,
364366 } = usePullRequestDetail ( environmentId , reference , matchingListEntry ) ;
365367 const [ selectedTab , setTab ] = useState < PullRequestDetailTab > ( initialTab ) ;
366- const revealCommentId =
368+ const revealItems =
367369 revealUrl === undefined || detail === null
368370 ? null
369- : ( pullRequestCommentLinkTarget (
370- pullRequestConversationItems ( detail . comments , detail . reviewThreads ) ,
371- revealUrl ,
372- ) ?. commentId ?? null ) ;
371+ : pullRequestConversationItems ( detail . comments , detail . reviewThreads ) ;
372+ const revealCommentId =
373+ revealItems === null || revealUrl === undefined
374+ ? null
375+ : ( pullRequestCommentLinkTarget ( revealItems , revealUrl ) ?. commentId ?? null ) ;
373376 // A comment link shows the conversation holding it.
374377 if ( revealCommentId !== null && ! tabOnPage && selectedTab !== "summary" ) setTab ( "summary" ) ;
375378 const reviewGuidesEnabled = useEnvironmentSettings (
@@ -585,6 +588,7 @@ export function PullRequestDetailPanel({
585588 ! activityQuery . isPending
586589 ? activityQuery . dataUpdatedAt
587590 : null ;
591+ const revealReadFailed = revealMissedAt !== null && activityQuery . error !== null ;
588592 const refreshDetail = ( ) => {
589593 detailQuery . refresh ( ) ;
590594 activityQuery . refresh ( ) ;
@@ -651,27 +655,37 @@ export function PullRequestDetailPanel({
651655 const revealHostRead = useRef < { readonly url : string ; readonly after : number | null } | null > (
652656 null ,
653657 ) ;
654- const settleRevealMiss = ( ) => {
658+ // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- a host read outliving the panel must not settle a later link
659+ useEffect (
660+ ( ) => ( ) => {
661+ revealHostRead . current = null ;
662+ } ,
663+ [ ] ,
664+ ) ;
665+ const settleReveal = ( url : string ) => {
655666 revealHostRead . current = null ;
656- onRevealSettled ?.( ) ;
667+ onRevealSettled ?.( url ) ;
657668 } ;
658669 const showRevealedComment = useEffectEvent ( ( ) => {
659670 if ( revealCommentId === null ) {
660- if ( revealUrl === undefined ) return ;
671+ if ( revealUrl === undefined || revealItems === null ) return ;
661672 const read = revealHostRead . current ;
662673 if ( read ?. url !== revealUrl ) {
674+ if ( ! pullRequestCommentLinkMayLoad ( revealItems , revealUrl ) ) return settleReveal ( revealUrl ) ;
663675 const request = { url : revealUrl , after : null } ;
664676 revealHostRead . current = request ;
665677 void refetchFromHost ( ) . then ( ( invalidated ) => {
666678 if ( revealHostRead . current !== request ) return ;
667679 // Without an invalidation the refetch could only repeat the cached read.
668- if ( ! invalidated ) return settleRevealMiss ( ) ;
680+ if ( ! invalidated ) return settleReveal ( request . url ) ;
669681 revealHostRead . current = { url : request . url , after : Date . now ( ) } ;
670682 } ) ;
671683 return ;
672684 }
673685 // A read that finished before the invalidation cannot show the comment is missing.
674- if ( read . after !== null && ( revealMissedAt ?? 0 ) > read . after ) settleRevealMiss ( ) ;
686+ if ( read . after !== null && ( revealReadFailed || ( revealMissedAt ?? 0 ) > read . after ) ) {
687+ settleReveal ( revealUrl ) ;
688+ }
675689 return ;
676690 }
677691 // A later click on the same link gets its own host read.
@@ -682,8 +696,11 @@ export function PullRequestDetailPanel({
682696 } ) ;
683697 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- the tab and the pending link live in stores outside the panel
684698 useEffect ( ( ) => {
685- if ( revealCommentId !== null || revealMissedAt !== null ) showRevealedComment ( ) ;
686- } , [ revealCommentId , revealMissedAt ] ) ;
699+ if ( revealCommentId !== null || revealMissedAt !== null || revealReadFailed ) {
700+ // oxlint-disable-next-line react/set-state-in-effect -- a missed comment starts a host read, which marks itself refreshing before it awaits
701+ showRevealedComment ( ) ;
702+ }
703+ } , [ revealCommentId , revealMissedAt , revealReadFailed ] ) ;
687704 const runAction = useAtomCommand ( pullRequestEnvironment . runAction , {
688705 reportFailure : false ,
689706 } ) ;
@@ -1819,7 +1836,9 @@ export function PullRequestDetailPanel({
18191836 detail = { detail }
18201837 activityPending = { activityPending }
18211838 revealCommentId = { tab === "summary" ? revealCommentId : null }
1822- { ...( onRevealSettled ? { onCommentRevealed : onRevealSettled } : { } ) }
1839+ { ...( onRevealSettled && revealUrl !== undefined
1840+ ? { onCommentRevealed : ( ) => onRevealSettled ( revealUrl ) }
1841+ : { } ) }
18231842 checksStale = { checksStale }
18241843 activityError = { activityError }
18251844 pendingFinding = { handoff }
0 commit comments