Skip to content

Commit 75b32c0

Browse files
committed
Comment
1 parent 6b21f00 commit 75b32c0

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

site/src/components/WorkspaceBuildProgress/WorkspaceBuildProgress.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ const estimateFinish = (
2020
const realPercentage = dayjs().diff(startedAt) / templateAverage
2121

2222
// Showing a full bar is frustrating.
23-
if (realPercentage > 0.95) {
24-
return [0.95, "Any moment now..."]
23+
const maxPercentage = 0.99
24+
if (realPercentage > maxPercentage) {
25+
return [maxPercentage, "Any moment now..."]
2526
}
2627

2728
return [
@@ -61,22 +62,27 @@ export const WorkspaceBuildProgress: FC<WorkspaceBuildProgressProps> = ({
6162
buildEstimate,
6263
}) => {
6364
const styles = useStyles()
64-
6565
const job = workspace.latest_build.job
66-
6766
const [progressValue, setProgressValue] = useState(0)
67+
6868
// By default workspace is updated every second, which can cause visual stutter
6969
// when the build estimate is a few seconds. The timer ensures no observable
7070
// stutter in all cases.
7171
useEffect(() => {
7272
const updateProgress = () => {
73+
if (job.status !== "running") {
74+
setProgressValue(0)
75+
return
76+
}
7377
setProgressValue(
7478
estimateFinish(dayjs(job.started_at), buildEstimate)[0] * 100,
7579
)
7680
}
7781
setTimeout(updateProgress, 100)
78-
}, [progressValue, job.started_at, buildEstimate])
82+
}, [progressValue, job, buildEstimate])
7983

84+
// buildEstimate may be undefined if the template is new or coderd hasn't
85+
// finished initial metrics collection.
8086
if (buildEstimate === undefined) {
8187
return (
8288
<div className={styles.stack}>

0 commit comments

Comments
 (0)