@@ -34,7 +34,7 @@ export default function () {
3434 const [ isLoading , setIsLoading ] = useState < boolean > ( false ) ;
3535 const [ isLoadingBranches , setIsLoadingBranches ] = useState < boolean > ( false ) ;
3636 const [ branches , setBranches ] = useState < Project . BranchDetails [ ] > ( [ ] ) ;
37- const [ lastPrebuilds , setLastPrebuilds ] = useState < Map < string , PrebuildWithStatus | undefined > > ( new Map ( ) ) ;
37+ const [ prebuilds , setPrebuilds ] = useState < Map < string , PrebuildWithStatus | undefined > > ( new Map ( ) ) ;
3838 const [ prebuildLoaders ] = useState < Set < string > > ( new Set ( ) ) ;
3939
4040 const [ searchFilter , setSearchFilter ] = useState < string | undefined > ( ) ;
@@ -122,31 +122,31 @@ export default function () {
122122 } ) ;
123123 } ;
124124
125- const lastPrebuild = ( branch : Project . BranchDetails ) => {
126- const lastPrebuild = lastPrebuilds . get ( branch . name ) ;
127- if ( ! lastPrebuild ) {
125+ const matchingPrebuild = ( branch : Project . BranchDetails ) => {
126+ const matchingPrebuild = prebuilds . get ( branch . name ) ;
127+ if ( ! matchingPrebuild ) {
128128 // do not await here.
129129 loadPrebuild ( branch ) ;
130130 }
131- return lastPrebuild ;
131+ return matchingPrebuild ;
132132 } ;
133133
134134 const loadPrebuild = async ( branch : Project . BranchDetails ) => {
135- if ( prebuildLoaders . has ( branch . name ) || lastPrebuilds . has ( branch . name ) ) {
136- // `lastPrebuilds .has(branch.name)` will be true even if loading finished with no prebuild found.
135+ if ( prebuildLoaders . has ( branch . name ) || prebuilds . has ( branch . name ) ) {
136+ // `prebuilds .has(branch.name)` will be true even if loading finished with no prebuild found.
137137 // TODO(at): this need to be revised once prebuild events are integrated
138138 return ;
139139 }
140140 if ( ! project ) {
141141 return ;
142142 }
143143 prebuildLoaders . add ( branch . name ) ;
144- const lastPrebuild = await getGitpodService ( ) . server . findPrebuilds ( {
144+ const branchPrebuilds = await getGitpodService ( ) . server . findPrebuilds ( {
145145 projectId : project . id ,
146146 branch : branch . name ,
147147 latest : true ,
148148 } ) ;
149- setLastPrebuilds ( ( prev ) => new Map ( prev ) . set ( branch . name , lastPrebuild [ 0 ] ) ) ;
149+ setPrebuilds ( ( prev ) => new Map ( prev ) . set ( branch . name , branchPrebuilds [ 0 ] ) ) ;
150150 prebuildLoaders . delete ( branch . name ) ;
151151 } ;
152152
@@ -269,8 +269,10 @@ export default function () {
269269 . filter ( filter )
270270 . slice ( 0 , 10 )
271271 . map ( ( branch , index ) => {
272- const prebuild = lastPrebuild ( branch ) ; // this might lazily trigger fetching of prebuild details
273-
272+ let prebuild = matchingPrebuild ( branch ) ; // this might lazily trigger fetching of prebuild details
273+ if ( prebuild && prebuild . info . changeHash !== branch . changeHash ) {
274+ prebuild = undefined ;
275+ }
274276 const avatar = branch . changeAuthorAvatar && (
275277 < img
276278 className = "rounded-full w-4 h-4 inline-block align-text-bottom mr-2 overflow-hidden"
@@ -360,7 +362,8 @@ export default function () {
360362 title : "Cancel Prebuild" ,
361363 customFontStyle :
362364 "text-red-600 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300" ,
363- onClick : ( ) => cancelPrebuild ( prebuild . info . id ) ,
365+ onClick : ( ) =>
366+ prebuild && cancelPrebuild ( prebuild . info . id ) ,
364367 } ,
365368 ]
366369 : [ ]
0 commit comments