Skip to content

Commit 9cff2b7

Browse files
committed
fix(files): guard the archive download against concurrent clicks
Navigating to the route meant a second click just re-navigated. Fetching the archive instead means each click starts another download that holds the whole zip in tab memory, and the Download button gave no sign anything was happening. The button now reflects the in-flight download alongside the existing move and delete states. The ref guard is there as well as the state because two clicks in the same tick would both pass a state check.
1 parent 9840f37 commit 9cff2b7

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

  • apps/sim/app/workspace/[workspaceId]/files

apps/sim/app/workspace/[workspaceId]/files/files.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1072,13 +1072,24 @@ export function Files() {
10721072
setShowDeleteConfirm(true)
10731073
}, [selectedFileIds, selectedFolderIds, files, folders])
10741074

1075+
const [isDownloadingArchive, setIsDownloadingArchive] = useState(false)
1076+
// Ref as well as state: two clicks in the same tick would both pass a state check,
1077+
// and each concurrent archive holds the whole zip in tab memory.
1078+
const archiveDownloadInFlightRef = useRef(false)
1079+
10751080
const downloadArchive = useCallback(
10761081
async (selection: { fileIds?: string[]; folderIds?: string[] }) => {
1082+
if (archiveDownloadInFlightRef.current) return
1083+
archiveDownloadInFlightRef.current = true
1084+
setIsDownloadingArchive(true)
10771085
try {
10781086
await triggerArchiveDownload({ workspaceId, ...selection })
10791087
} catch (err) {
10801088
logger.error('Failed to download selection:', err)
10811089
toast.error(getErrorMessage(err, 'Failed to download the selected files'))
1090+
} finally {
1091+
archiveDownloadInFlightRef.current = false
1092+
setIsDownloadingArchive(false)
10821093
}
10831094
},
10841095
[workspaceId]
@@ -1991,7 +2002,9 @@ export function Files() {
19912002
onMove={canEdit ? handleContextMenuMove : undefined}
19922003
moveOptions={canEdit ? contextMenuMoveOptions : undefined}
19932004
onDelete={canEdit ? handleBulkDelete : undefined}
1994-
isLoading={bulkArchiveItems.isPending || moveItems.isPending}
2005+
isLoading={
2006+
bulkArchiveItems.isPending || moveItems.isPending || isDownloadingArchive
2007+
}
19952008
/>
19962009
{isDraggingOver ? (
19972010
<div className='pointer-events-none absolute inset-0 z-[var(--z-dropdown)] flex flex-col items-center justify-center gap-2 border border-[var(--brand-secondary)] border-dashed bg-[var(--surface-4)] transition-colors'>

0 commit comments

Comments
 (0)