@@ -65,13 +65,15 @@ import {
6565 withDiffStat ,
6666 writePullRequestListSnapshot ,
6767 scorePullRequestMatch ,
68+ pullRequestStatsRefreshBatches ,
6869 pullRequestStatsRequestBatches ,
6970 retainVisiblePullRequestStatsBatches ,
7071 type EnvironmentPullRequestEntry ,
7172 type MergedPullRequestList ,
7273 type PullRequestDiffStats ,
7374 type PullRequestStatsBatch ,
7475 type PullRequestStatsPolicy ,
76+ type PullRequestStatsScope ,
7577 type PullRequestPartitionsSnapshot ,
7678} from "../components/pullRequest/pullRequestList.logic" ;
7779import { assignProjectsToEnvironments } from "../components/pullRequest/pullRequestProjectAssignment.logic" ;
@@ -621,6 +623,8 @@ function PullRequestsRouteView() {
621623 // Page size is view state, not a URL concern: a shared link should open the first page.
622624 const scopeKey = `${ environmentKey } :${ assignmentKey } :${ search . state } :${ search . involvement } :${ scopedProjectId ?? "" } :${ search . host ?? "" } :${ search . draft ?? "" } :${ search . review ?? "" } :${ search . checks ?? "" } :${ search . author ?? "" } :${ search . labels ?. join ( "\u0000" ) ?? "" } ` ;
623625 const filterKey = `${ scopeKey } :${ sentQuery } ` ;
626+ const statsScopeRef = useRef < PullRequestStatsScope > ( { key : filterKey , policy : statsPolicy } ) ;
627+ statsScopeRef . current = { key : filterKey , policy : statsPolicy } ;
624628 // Where the next slice carries on from, per repository within each environment, as that
625629 // environment handed it back. Sending it is what makes a second page cost a second page rather
626630 // than the whole list again — and a repository it does not name has run out and is not read a
@@ -794,6 +798,7 @@ function PullRequestsRouteView() {
794798 // of its own work is a button that gets pressed again, and buys the whole cascade twice.
795799 const [ invalidating , setInvalidating ] = useState ( false ) ;
796800 const refreshFromHost = async ( ) => {
801+ const requestedStatsScope = statsScopeRef . current ;
797802 setInvalidating ( true ) ;
798803 try {
799804 // Every environment the page is reading, since what the reader pressed refresh for is the
@@ -810,16 +815,17 @@ function PullRequestsRouteView() {
810815 authoredQuery . refresh ( ) ;
811816 reviewingQuery . refresh ( ) ;
812817 const visible = visibleStatsKeys . current ;
813- const batches = pullRequestStatsRequestBatches ( {
818+ const batches = pullRequestStatsRefreshBatches ( {
819+ requestedScope : requestedStatsScope ,
820+ currentScope : statsScopeRef . current ,
814821 entriesByKey : entriesByStatsKey . current ,
815- candidateKeys : visible . key === filterKey ? visible . values : new Set ( ) ,
816- policy : statsPolicy ,
817- activeBatches : [ ] ,
822+ candidateKeys : visible . key === requestedStatsScope . key ? visible . values : new Set ( ) ,
818823 statsByRow : statsByRowRef . current ,
819- refresh : true ,
820824 } ) ;
821- setStatsTargetState ( { key : filterKey , batches } ) ;
822- statsQuery . refresh ( batches . map ( ( { environmentId, input } ) => ( { environmentId, input } ) ) ) ;
825+ if ( batches !== null ) {
826+ setStatsTargetState ( { key : requestedStatsScope . key , batches } ) ;
827+ statsQuery . refresh ( batches . map ( ( { environmentId, input } ) => ( { environmentId, input } ) ) ) ;
828+ }
823829 setDetailRefreshToken ( ( token ) => token + 1 ) ;
824830 } ;
825831 const refreshing = invalidating || listQuery . isPending ;
0 commit comments