@@ -34,7 +34,7 @@ export default function () {
34
34
const [ isLoading , setIsLoading ] = useState < boolean > ( false ) ;
35
35
const [ isLoadingBranches , setIsLoadingBranches ] = useState < boolean > ( false ) ;
36
36
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 ( ) ) ;
38
38
const [ prebuildLoaders ] = useState < Set < string > > ( new Set ( ) ) ;
39
39
40
40
const [ searchFilter , setSearchFilter ] = useState < string | undefined > ( ) ;
@@ -122,31 +122,31 @@ export default function () {
122
122
} ) ;
123
123
} ;
124
124
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 ) {
128
128
// do not await here.
129
129
loadPrebuild ( branch ) ;
130
130
}
131
- return lastPrebuild ;
131
+ return matchingPrebuild ;
132
132
} ;
133
133
134
134
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.
137
137
// TODO(at): this need to be revised once prebuild events are integrated
138
138
return ;
139
139
}
140
140
if ( ! project ) {
141
141
return ;
142
142
}
143
143
prebuildLoaders . add ( branch . name ) ;
144
- const lastPrebuild = await getGitpodService ( ) . server . findPrebuilds ( {
144
+ const branchPrebuilds = await getGitpodService ( ) . server . findPrebuilds ( {
145
145
projectId : project . id ,
146
146
branch : branch . name ,
147
147
latest : true ,
148
148
} ) ;
149
- setLastPrebuilds ( ( prev ) => new Map ( prev ) . set ( branch . name , lastPrebuild [ 0 ] ) ) ;
149
+ setPrebuilds ( ( prev ) => new Map ( prev ) . set ( branch . name , branchPrebuilds [ 0 ] ) ) ;
150
150
prebuildLoaders . delete ( branch . name ) ;
151
151
} ;
152
152
@@ -269,8 +269,10 @@ export default function () {
269
269
. filter ( filter )
270
270
. slice ( 0 , 10 )
271
271
. 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
+ }
274
276
const avatar = branch . changeAuthorAvatar && (
275
277
< img
276
278
className = "rounded-full w-4 h-4 inline-block align-text-bottom mr-2 overflow-hidden"
@@ -360,7 +362,8 @@ export default function () {
360
362
title : "Cancel Prebuild" ,
361
363
customFontStyle :
362
364
"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 ) ,
364
367
} ,
365
368
]
366
369
: [ ]
0 commit comments