@@ -4,6 +4,7 @@ import { pullRequestHostOf, resolveEnvironmentMachineKind } from "@t3tools/contr
44import type {
55 EnvironmentId ,
66 ProjectId ,
7+ PullRequestAction ,
78 PullRequestInvolvement ,
89 PullRequestListCursors ,
910 PullRequestListFilters ,
@@ -77,6 +78,10 @@ import {
7778 type PullRequestStatsPolicy ,
7879 type PullRequestStatsScope ,
7980 type PullRequestPartitionsSnapshot ,
81+ applyPullRequestOverrides ,
82+ type PullRequestListOverride ,
83+ pullRequestOverrideAfterAction ,
84+ reusePullRequestEntries ,
8085} from "../components/pullRequest/pullRequestList.logic" ;
8186import {
8287 pullRequestListPreferences ,
@@ -914,6 +919,18 @@ function PullRequestsRouteView() {
914919 key : string ;
915920 entries : ReadonlyArray < EnvironmentPullRequestEntry > ;
916921 } | null > ( null ) ;
922+ // What the reader just did to a row, shown before any host confirms it. A closed pull request
923+ // leaves an "open" list on the click; the reads that follow are slow, and until one lands the
924+ // row says what was asked of it. Cleared when a whole-page answer arrives after the action.
925+ const [ overrides , setOverrides ] = useState < ReadonlyMap < string , PullRequestListOverride > > (
926+ ( ) => new Map ( ) ,
927+ ) ;
928+ const overrideEntry = ( entry : EnvironmentPullRequestEntry , action : PullRequestAction ) => {
929+ const override = pullRequestOverrideAfterAction ( entry , action , new Date ( ) . toISOString ( ) ) ;
930+ if ( override === null ) return false ;
931+ setOverrides ( ( current ) => new Map ( current ) . set ( pullRequestEntryKey ( entry ) , override ) ) ;
932+ return true ;
933+ } ;
917934 // A reload recreates the registry the queries live in, so with nothing held the page would
918935 // cold-start into skeletons even though almost every row is unchanged. The last answer for
919936 // this set of environments is kept across reloads and hydrated here as the carried rows: they
@@ -1077,8 +1094,17 @@ function PullRequestsRouteView() {
10771094 // since the last read at the bottom of the page — below rows a week older — where "the
10781095 // latest" is exactly what a refresh was for. The host answers in the order the page
10791096 // reads, so its order stands; a row that moved was updated, and moving is the news.
1080- return { key : filterKey , entries : rankPullRequestMatches ( answered . entries , sentParsed . text ) } ;
1097+ return {
1098+ key : filterKey ,
1099+ entries : reusePullRequestEntries (
1100+ previous . entries ,
1101+ rankPullRequestMatches ( answered . entries , sentParsed . text ) ,
1102+ pullRequestEntryKey ,
1103+ ) ,
1104+ } ;
10811105 } ) ;
1106+ // A whole answer read after the action is the host's word, which outranks the reader's.
1107+ setOverrides ( ( current ) => ( current . size === 0 ? current : new Map ( ) ) ) ;
10821108 } , [
10831109 answered ,
10841110 filterKey ,
@@ -1210,7 +1236,12 @@ function PullRequestsRouteView() {
12101236 ) ;
12111237
12121238 const entries = useMemo ( ( ) => {
1213- const known = ordered ?. key === filterKey ? ordered . entries : ( listData ?. entries ?? [ ] ) ;
1239+ const known = applyPullRequestOverrides (
1240+ ordered ?. key === filterKey ? ordered . entries : ( listData ?. entries ?? [ ] ) ,
1241+ overrides ,
1242+ pullRequestEntryKey ,
1243+ search . state ,
1244+ ) ;
12141245 const involvementEntries = filterPullRequestsByInvolvement ( known , viewers , search . involvement ) ;
12151246 // The hosts search more than the row shows — a body, a review, a commit message — so once
12161247 // their answer is in, narrowing it again here would throw away matches the reader asked for.
@@ -1245,8 +1276,10 @@ function PullRequestsRouteView() {
12451276 localFilters ,
12461277 listData ,
12471278 ordered ,
1279+ overrides ,
12481280 querySettled ,
12491281 search . involvement ,
1282+ search . state ,
12501283 searchingHosts ,
12511284 showingCarried ,
12521285 typedParsed . text ,
@@ -2067,8 +2100,16 @@ function PullRequestsRouteView() {
20672100 refreshToken = { detailRefreshToken }
20682101 // Host actions can change both readiness and diff size, so refresh the counts
20692102 // alongside the list. The panel already refreshes itself after each action.
2070- onActed = { ( ) => {
2071- // Mutations already invalidate the host's affected caches.
2103+ onActed = { ( action ) => {
2104+ // An action that only moves a row's state is written onto the row at once; the
2105+ // host has invalidated its caches, so the next scheduled read confirms it. The
2106+ // rest change what the counts and checks say, and those need the reads now.
2107+ const acted = listedPullRequestsBySurface . get (
2108+ pullRequestListEntryId ( renderedPullRequestSurface ) ,
2109+ ) ;
2110+ if ( action !== undefined && acted !== undefined && overrideEntry ( acted , action ) ) {
2111+ return ;
2112+ }
20722113 refreshListAndStats ( undefined , panelEnvironmentId ) ;
20732114 } }
20742115 />
0 commit comments