Fix: Enable cancellation of attachment uploads in progress #1098
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The attachment cancel buttons (X) were disabled during file upload, preventing users from cancelling ongoing uploads. This was caused by the
disabled={selectedFile.uploading}attribute on the cancel buttons, which made them unclickable while files were being uploaded.Solution
Implemented the AbortController API to enable upload cancellation at any time. Users can now click the cancel button while files are uploading to immediately stop the upload and remove the file from the UI.
Changes
1. Added AbortController Support
Added an
abortControllerfield to theSelectedFileinterface to track ongoing uploads:2. Enhanced Upload Function
Modified the
uploadFilesfunction to:AbortControllerfor each file before starting the uploadsignal: abortController?.signalAbortErrorwhen uploads are cancelled (no error toast shown)3. Updated Remove Function
Enhanced the
removeFilefunction to:abortController.abort()to cancel the ongoing fetch requestuploadingFilesCountwhen cancelling4. Enabled Cancel Buttons
Both cancel buttons (image preview overlay and list view) now:
disabledattribute removedTechnical Flow
When upload starts:
When user clicks cancel:
removeFile()finds the file by IDabortController.abort()to cancel the requestAbortError(caught silently)When upload completes normally:
Benefits
Testing
To test the fix:
Closes #[issue-number]
Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.