Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@uppy/status-bar: fix ETA when Uppy recovers its state #4525

Merged
merged 1 commit into from
Jun 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions packages/@uppy/status-bar/src/StatusBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ export default class StatusBar extends UIPlugin {
return 0
}

// When state is restored, lastUpdateTime is still nullish at this point.
this.#lastUpdateTime ??= performance.now()
const dt = performance.now() - this.#lastUpdateTime
if (dt === 0) {
return Math.round((this.#previousETA ?? 0) / 100) / 10
Expand Down Expand Up @@ -130,14 +132,20 @@ export default class StatusBar extends UIPlugin {
startUpload = () => {
const { recoveredState } = this.uppy.getState()

this.#previousSpeed = null
this.#previousETA = null
if (recoveredState) {
this.#previousUploadedBytes = Object.values(recoveredState.files)
.reduce((pv, { progress }) => pv + progress.bytesUploaded, 0)

// We don't set `#lastUpdateTime` at this point because the upload won't
// actually resume until the user asks for it.

this.uppy.emit('restore-confirmed')
return undefined
}
this.#lastUpdateTime = performance.now()
this.#previousUploadedBytes = 0
this.#previousSpeed = null
this.#previousETA = null
return this.uppy.upload().catch(() => {
// Error logged in Core
})
Expand Down