perf(ui): update the download progress once per visible change
fetchWithProgress reports every network chunk; only re-render when the "x MB / y MB" label actually changes (#1). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6533c31704
commit
855b7f4ad6
1 file changed
+5
-1
+5
-1
@@ -152,10 +152,14 @@ export function App() {
|
|||||||
let name: string
|
let name: string
|
||||||
if (source.kind === "url") {
|
if (source.kind === "url") {
|
||||||
name = source.name ?? nameFromUrl(source.url)
|
name = source.name ?? nameFromUrl(source.url)
|
||||||
|
let lastLabel = ""
|
||||||
buf = await fetchWithProgress(source.url, (loaded, total) => {
|
buf = await fetchWithProgress(source.url, (loaded, total) => {
|
||||||
if (stale()) return
|
if (stale()) return
|
||||||
const size = total ? `${formatBytes(loaded)} / ${formatBytes(total)}` : formatBytes(loaded)
|
const size = total ? `${formatBytes(loaded)} / ${formatBytes(total)}` : formatBytes(loaded)
|
||||||
setLoadState({ label: `도면 내려받는 중 (${size})`, value: total ? Math.round(Math.min(1, loaded / total) * 50) : null, busy: true })
|
const label = `도면 내려받는 중 (${size})`
|
||||||
|
if (label === lastLabel) return // one update per visible change, not per network chunk
|
||||||
|
lastLabel = label
|
||||||
|
setLoadState({ label, value: total ? Math.round(Math.min(1, loaded / total) * 50) : null, busy: true })
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
name = source.file.name
|
name = source.file.name
|
||||||
|
|||||||
Reference in new issue
Block a user