From 00a922c429db9c822b55aabc8f38d321a451cafd Mon Sep 17 00:00:00 2001 From: "chihao.ou" Date: Wed, 30 Sep 2026 02:50:29 +0800 Subject: [PATCH] fix(backup): prevent polling from restarting after navigation --- frontend/src/views/admin/BackupView.vue | 4 ++++ .../views/admin/__tests__/BackupView.spec.ts | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/frontend/src/views/admin/BackupView.vue b/frontend/src/views/admin/BackupView.vue index b9f7600a19..82fbdc56ab 100644 --- a/frontend/src/views/admin/BackupView.vue +++ b/frontend/src/views/admin/BackupView.vue @@ -537,6 +537,7 @@ const downloadPartsModalOpen = ref(false) const pollingTimer = ref | null>(null) const restoringPollingTimer = ref | null>(null) const MAX_POLL_COUNT = 900 +let disposed = false function updateRecordInList(updated: BackupRecord) { const idx = backups.value.findIndex(r => r.id === updated.id) @@ -546,6 +547,7 @@ function updateRecordInList(updated: BackupRecord) { } function startPolling(backupId: string) { + if (disposed) return stopPolling() let count = 0 pollingTimer.value = setInterval(async () => { @@ -582,6 +584,7 @@ function stopPolling() { } function startRestorePolling(backupId: string) { + if (disposed) return stopRestorePolling() let count = 0 restoringPollingTimer.value = setInterval(async () => { @@ -930,6 +933,7 @@ onMounted(async () => { }) onBeforeUnmount(() => { + disposed = true stopPolling() stopRestorePolling() document.removeEventListener('visibilitychange', handleVisibilityChange) diff --git a/frontend/src/views/admin/__tests__/BackupView.spec.ts b/frontend/src/views/admin/__tests__/BackupView.spec.ts index 8c1e1563bc..933e70228c 100644 --- a/frontend/src/views/admin/__tests__/BackupView.spec.ts +++ b/frontend/src/views/admin/__tests__/BackupView.spec.ts @@ -108,6 +108,27 @@ describe('admin BackupView', () => { document.body.innerHTML = '' }) + it.each(['backup', 'restore'])('does not resume %s polling after navigation during initial loading', async (operation) => { + vi.useFakeTimers() + let finish!: (value: object) => void + listBackups.mockImplementationOnce(() => new Promise(resolve => { finish = resolve })) + const wrapper = mountBackupView() + try { + await flushPromises() + wrapper.unmount() + finish({ items: [{ ...baseRecord('pending'), + status: operation === 'backup' ? 'running' : 'completed', + restore_status: operation === 'restore' ? 'running' : undefined, + }] }) + await flushPromises() + expect(vi.getTimerCount()).toBe(0) + } finally { + wrapper.unmount() + vi.clearAllTimers() + vi.useRealTimers() + } + }) + it('显示分卷数并在下载时列出每个分卷链接', async () => { listBackups.mockResolvedValue({ items: [baseRecord('split', [{ index: 1 }, { index: 2 }, { index: 3 }])],