@@ -345,9 +345,6 @@ function PullRequestsRouteView() {
345345 sort === "ready" || sort === "largest" || sort === "smallest" ? "eager" : "visible" ;
346346 const navigate = useNavigate ( { from : Route . fullPath } ) ;
347347 const keybindings = useAtomValue ( primaryServerKeybindingsAtom ) ;
348- const { environments } = useEnvironments ( ) ;
349- const allProjects = useProjects ( ) ;
350- const projectsKnown = useAllEnvironmentShellsBootstrapped ( ) ;
351348 const {
352349 capableEnvironments,
353350 scopedEnvironmentId,
@@ -365,7 +362,8 @@ function PullRequestsRouteView() {
365362 assignmentKey,
366363 linkedSelection,
367364 expectedHosts,
368- } = usePullRequestScope ( environments , allProjects , projectsKnown , search ) ;
365+ projectsKnown,
366+ } = usePullRequestScope ( search ) ;
369367 const rightPanelRef = capableEnvironments . length === 0 ? null : PULL_REQUESTS_PANEL_REF ;
370368 const openPanelPullRequestUrl = useOpenPanelPullRequestUrl ( rightPanelRef ) ;
371369 const rightPanelState = useRightPanelStore ( ( state ) =>
@@ -448,9 +446,9 @@ function PullRequestsRouteView() {
448446
449447 const typedQuery = ( search . q ?? "" ) . trim ( ) ;
450448 const [ filtersOpen , setFiltersOpen ] = useState ( false ) ;
451- const sentQuery = useDebouncedValue ( typedQuery , SEARCH_DEBOUNCE_MS ) ;
452- const querySettled = typedQuery === sentQuery ;
453449 const {
450+ sentQuery,
451+ querySettled,
454452 typedParsed,
455453 sentParsed,
456454 menuFilters,
@@ -459,7 +457,7 @@ function PullRequestsRouteView() {
459457 hasFilters,
460458 localFilters,
461459 hasLocalFilters,
462- } = usePullRequestQueryFilters ( search , typedQuery , sentQuery ) ;
460+ } = usePullRequestQueryFilters ( search , typedQuery ) ;
463461 const turnRefreshes = usePullRequestTurnRefreshes (
464462 environmentQueries . map ( ( { environmentId } ) => environmentId ) ,
465463 ) ;
@@ -883,7 +881,7 @@ function PullRequestsRouteView() {
883881 groups,
884882 entriesByStatsKey,
885883 heldPullRequestsBySurface,
886- } = usePullRequestGroups ( {
884+ } = pullRequestGroups ( {
887885 known : ordered ?. key === filterKey ? ordered . entries : ( listData ?. entries ?? [ ] ) ,
888886 providers : baselineQuery . data ?. providers ?? listData ?. providers ?? [ ] ,
889887 viewers,
@@ -1071,37 +1069,28 @@ function PullRequestsRouteView() {
10711069 refreshListAndStats ( requestedStatsScope ) ;
10721070 setDetailRefreshToken ( ( token ) => token + 1 ) ;
10731071 } ;
1074- const [ hostsState , setHostsState ] = useState < {
1075- readonly source : MergedPullRequestList | null ;
1076- readonly host : string | undefined ;
1077- readonly hosts : PullRequestListResult [ "providers" ] ;
1078- } > ( { source : null , host : undefined , hosts : [ ] } ) ;
1079- if ( answered !== null && ( hostsState . source !== answered || hostsState . host !== search . host ) ) {
1080- setHostsState ( {
1081- source : answered ,
1082- host : search . host ,
1083- hosts :
1084- search . host === undefined || hostsState . hosts . length === 0
1085- ? answered . providers
1086- : hostsState . hosts ,
1087- } ) ;
1088- }
1089- const hosts = hostsState . hosts ;
1072+ const {
1073+ hosts,
1074+ displayGroups,
1075+ shownCount,
1076+ hostActionsOf,
1077+ closeSweepRows,
1078+ listedPullRequestsBySurface,
1079+ } = usePullRequestDisplayGroups ( {
1080+ answered,
1081+ host : search . host ,
1082+ groups,
1083+ statsByRow,
1084+ overrides,
1085+ state : search . state ,
1086+ localFilters,
1087+ hasLocalFilters,
1088+ viewers,
1089+ sort,
1090+ text : typedParsed . text ,
1091+ involvement : search . involvement ,
1092+ } ) ;
10901093 const showProvider = hosts . length > 1 ;
1091- const { displayGroups, shownCount, hostActionsOf, closeSweepRows, listedPullRequestsBySurface } =
1092- usePullRequestDisplayGroups ( {
1093- groups,
1094- statsByRow,
1095- overrides,
1096- state : search . state ,
1097- localFilters,
1098- hasLocalFilters,
1099- viewers,
1100- sort,
1101- text : typedParsed . text ,
1102- involvement : search . involvement ,
1103- hosts,
1104- } ) ;
11051094 const [ closeSweepKeys , setCloseSweepKeys ] = useState < ReadonlySet < string > > ( ( ) => new Set ( ) ) ;
11061095 const closeSensorRef = useRef < SidebarPointerSensor | null > ( null ) ;
11071096 // A sweep spans many renders; each step reads the rows on screen at that moment.
@@ -1777,14 +1766,10 @@ function PullRequestsRouteView() {
17771766}
17781767
17791768/** Which servers and projects the page reads, from the URL and what this client knows. */
1780- function usePullRequestScope (
1781- environments : ReturnType < typeof useEnvironments > [ "environments" ] ,
1782- allProjects : ReturnType < typeof useProjects > ,
1783- projectsKnown : boolean ,
1784- search : PullRequestsSearch ,
1785- ) {
1786- // Calls no hooks, so the compiler needs the directive to memoize it.
1787- "use memo" ;
1769+ function usePullRequestScope ( search : PullRequestsSearch ) {
1770+ const { environments } = useEnvironments ( ) ;
1771+ const allProjects = useProjects ( ) ;
1772+ const projectsKnown = useAllEnvironmentShellsBootstrapped ( ) ;
17881773 const capableEnvironments = environments
17891774 . filter (
17901775 ( environment ) => environment . serverConfig ?. environment . capabilities . pullRequests === true ,
@@ -1913,16 +1898,12 @@ function usePullRequestScope(
19131898 assignmentKey,
19141899 linkedSelection,
19151900 expectedHosts,
1901+ projectsKnown,
19161902 } ;
19171903}
19181904
1919- function usePullRequestQueryFilters (
1920- search : PullRequestsSearch ,
1921- typedQuery : string ,
1922- sentQuery : string ,
1923- ) {
1924- // Calls no hooks, so the compiler needs the directive to memoize it.
1925- "use memo" ;
1905+ function usePullRequestQueryFilters ( search : PullRequestsSearch , typedQuery : string ) {
1906+ const sentQuery = useDebouncedValue ( typedQuery , SEARCH_DEBOUNCE_MS ) ;
19261907 const typedParsed = parsePullRequestQuery ( typedQuery ) ;
19271908 const sentParsed = parsePullRequestQuery ( sentQuery ) ;
19281909
@@ -1939,6 +1920,8 @@ function usePullRequestQueryFilters(
19391920 const localFilters = { ...menuFilters , ...typedParsed . filters } ;
19401921 const hasLocalFilters = Object . keys ( localFilters ) . length > 0 ;
19411922 return {
1923+ sentQuery,
1924+ querySettled : typedQuery === sentQuery ,
19421925 typedParsed,
19431926 sentParsed,
19441927 menuFilters,
@@ -1951,7 +1934,7 @@ function usePullRequestQueryFilters(
19511934}
19521935
19531936/** The held rows narrowed to what the reader asked for, in the groups the list shows. */
1954- function usePullRequestGroups ( {
1937+ function pullRequestGroups ( {
19551938 known,
19561939 providers,
19571940 viewers,
@@ -1980,8 +1963,6 @@ function usePullRequestGroups({
19801963 reviewing : ReadonlyArray < EnvironmentPullRequestEntry > | undefined ;
19811964 partitionsWanted : boolean ;
19821965} ) {
1983- // Calls no hooks, so the compiler needs the directive to memoize it.
1984- "use memo" ;
19851966 const searchingHosts = new Set (
19861967 providers . flatMap ( ( provider ) => ( provider . searchesOnHost ? [ provider . host ] : [ ] ) ) ,
19871968 ) ;
@@ -2057,8 +2038,13 @@ function usePullRequestGroups({
20572038 } ;
20582039}
20592040
2060- /** The groups as shown: with measured sizes, optimistic actions, and the reader's sort. */
2041+ /**
2042+ * The hosts the list has answered for (kept while a host filter narrows the answer), and the
2043+ * groups as shown with measured sizes, optimistic actions, and the reader's sort.
2044+ */
20612045function usePullRequestDisplayGroups ( {
2046+ answered,
2047+ host,
20622048 groups,
20632049 statsByRow,
20642050 overrides,
@@ -2069,8 +2055,9 @@ function usePullRequestDisplayGroups({
20692055 sort,
20702056 text,
20712057 involvement,
2072- hosts,
20732058} : {
2059+ answered : MergedPullRequestList | null ;
2060+ host : string | undefined ;
20742061 groups : ReadonlyArray < PullRequestGroup < EnvironmentPullRequestEntry > > ;
20752062 statsByRow : PullRequestDiffStats ;
20762063 overrides : ReadonlyMap < string , PullRequestListOverride > ;
@@ -2081,13 +2068,24 @@ function usePullRequestDisplayGroups({
20812068 sort : PullRequestListSort ;
20822069 text : string ;
20832070 involvement : PullRequestInvolvement ;
2084- hosts : PullRequestListResult [ "providers" ] ;
20852071} ) {
2086- // Calls no hooks, so the compiler needs the directive to memoize it.
2087- "use memo" ;
2072+ const [ hostsState , setHostsState ] = useState < {
2073+ readonly source : MergedPullRequestList | null ;
2074+ readonly host : string | undefined ;
2075+ readonly hosts : PullRequestListResult [ "providers" ] ;
2076+ } > ( { source : null , host : undefined , hosts : [ ] } ) ;
2077+ if ( answered !== null && ( hostsState . source !== answered || hostsState . host !== host ) ) {
2078+ setHostsState ( {
2079+ source : answered ,
2080+ host,
2081+ hosts :
2082+ host === undefined || hostsState . hosts . length === 0 ? answered . providers : hostsState . hosts ,
2083+ } ) ;
2084+ }
2085+ const hosts = hostsState . hosts ;
20882086 const displayGroups = ( ( ) => {
20892087 const enriched = groups . map ( ( group ) => {
2090- const answered = applyPullRequestOverrides (
2088+ const overridden = applyPullRequestOverrides (
20912089 group . entries . map ( ( entry ) => withDiffStat ( entry , statsByRow ) ) ,
20922090 overrides ,
20932091 pullRequestEntryKey ,
@@ -2097,7 +2095,7 @@ function usePullRequestDisplayGroups({
20972095 ...group ,
20982096 entries :
20992097 hasLocalFilters && overrides . size > 0
2100- ? answered . filter (
2098+ ? overridden . filter (
21012099 ( entry ) =>
21022100 ! overrides . has ( pullRequestEntryKey ( entry ) ) ||
21032101 matchesPullRequestFilters (
@@ -2106,7 +2104,7 @@ function usePullRequestDisplayGroups({
21062104 pullRequestEntryViewer ( entry , viewers ) ,
21072105 ) ,
21082106 )
2109- : answered ,
2107+ : overridden ,
21102108 } ;
21112109 } ) ;
21122110 return sortPullRequestGroups (
@@ -2134,6 +2132,7 @@ function usePullRequestDisplayGroups({
21342132 ) ;
21352133
21362134 return {
2135+ hosts,
21372136 displayGroups,
21382137 shownCount,
21392138 hostActionsOf,
0 commit comments