Skip to content

Commit 7ab4693

Browse files
fix(assetDownload): handle race condition and add listener cleanup
- Remove early return that skipped completion/failure events for untracked tasks - Add processedTaskIds set to deduplicate terminal events - Add teardown() method to properly remove event listener on unmount - Use strict equality operator in useUploadModelWizard
1 parent 9129692 commit 7ab4693

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

src/platform/assets/composables/useUploadModelWizard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ export function useUploadModelWizard(modelTypes: Ref<ModelTypeOption[]>) {
233233
preview_id: previewId
234234
})
235235

236-
if (result.type === 'async' && result.task.status != 'completed') {
236+
if (result.type === 'async' && result.task.status !== 'completed') {
237237
if (selectedModelType.value) {
238238
assetDownloadStore.trackDownload(
239239
result.task.task_id,

src/stores/assetDownloadStore.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const useAssetDownloadStore = defineStore('assetDownload', () => {
2929
const activeDownloads = ref<Map<string, AssetDownload>>(new Map())
3030
const pendingModelTypes = new Map<string, string>()
3131
const lastToastTime = new Map<string, number>()
32+
const processedTaskIds = new Set<string>()
3233

3334
const hasActiveDownloads = computed(() => activeDownloads.value.size > 0)
3435
const downloadList = computed(() =>
@@ -61,12 +62,8 @@ export const useAssetDownloadStore = defineStore('assetDownload', () => {
6162
const data = e.detail
6263

6364
if (data.status === 'completed' || data.status === 'failed') {
64-
if (
65-
!activeDownloads.value.has(data.task_id) &&
66-
!pendingModelTypes.has(data.task_id)
67-
) {
68-
return
69-
}
65+
if (processedTaskIds.has(data.task_id)) return
66+
processedTaskIds.add(data.task_id)
7067
}
7168

7269
const download: AssetDownload = {
@@ -125,15 +122,23 @@ export const useAssetDownloadStore = defineStore('assetDownload', () => {
125122
}
126123
}
127124

125+
let stopListener: (() => void) | undefined
126+
128127
function setup() {
129-
useEventListener(api, 'asset_download', handleAssetDownload)
128+
stopListener = useEventListener(api, 'asset_download', handleAssetDownload)
129+
}
130+
131+
function teardown() {
132+
stopListener?.()
133+
stopListener = undefined
130134
}
131135

132136
return {
133137
activeDownloads,
134138
hasActiveDownloads,
135139
downloadList,
136140
trackDownload,
137-
setup
141+
setup,
142+
teardown
138143
}
139144
})

src/views/GraphView.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ onBeforeUnmount(() => {
273273
api.removeEventListener('reconnecting', onReconnecting)
274274
api.removeEventListener('reconnected', onReconnected)
275275
executionStore.unbindExecutionEvents()
276+
assetDownloadStore.teardown()
276277
277278
// Clean up page visibility listener
278279
if (visibilityListener) {

0 commit comments

Comments
 (0)