-
Notifications
You must be signed in to change notification settings - Fork 56
fix: XYNE-157 attachement removal while it is in uploading state #1096
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -889,7 +889,7 @@ export const ChatBox = React.forwardRef<ChatBoxRef, ChatBoxProps>( | |
}) | ||
return null | ||
} finally { | ||
setUploadingFilesCount((prev) => prev - 1) | ||
setUploadingFilesCount((prev) => Math.max(prev - 1, 0)) | ||
} | ||
Comment on lines
891
to
893
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While adding To fix this, we should only decrement the count here if the file has not been removed by the user in the meantime. We can use
|
||
}) | ||
|
||
|
@@ -1001,6 +1001,9 @@ export const ChatBox = React.forwardRef<ChatBoxRef, ChatBoxProps>( | |
} | ||
|
||
// Remove from UI | ||
if(fileToRemove){ | ||
setUploadingFilesCount((prev) => Math.max(prev - (fileToRemove?.uploading ? 1 : 0), 0)) | ||
} | ||
setSelectedFiles((prev) => { | ||
if (fileToRemove?.preview) { | ||
URL.revokeObjectURL(fileToRemove.preview) | ||
|
@@ -2256,7 +2259,7 @@ export const ChatBox = React.forwardRef<ChatBoxRef, ChatBoxProps>( | |
handleSendMessage, | ||
], | ||
) | ||
|
||
return ( | ||
<div className="relative flex flex-col w-full max-w-3xl pb-5"> | ||
{persistedAgentId && displayAgentName && ( | ||
|
@@ -2862,7 +2865,7 @@ export const ChatBox = React.forwardRef<ChatBoxRef, ChatBoxProps>( | |
<button | ||
onClick={() => removeFile(selectedFile.id)} | ||
className="absolute top-1 right-1 bg-black bg-opacity-60 text-white rounded-full p-1 hover:bg-opacity-80 transition-opacity" | ||
disabled={selectedFile.uploading} | ||
// disabled={selectedFile.uploading} | ||
> | ||
<X size={10} /> | ||
</button> | ||
|
@@ -2918,7 +2921,7 @@ export const ChatBox = React.forwardRef<ChatBoxRef, ChatBoxProps>( | |
<button | ||
onClick={() => removeFile(selectedFile.id)} | ||
className="text-gray-400 hover:text-red-500 transition-colors p-1" | ||
disabled={selectedFile.uploading} | ||
// disabled={selectedFile.uploading} | ||
> | ||
<X size={12} /> | ||
</button> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical: Double-decrement bug when removing files during upload.
When a file is removed while uploading,
uploadingFilesCount
is decremented twice:removeFile
(line 1005): decrements by 1 iffileToRemove.uploading
is truefinally
block: decrements by 1 when the upload promise completesThis causes the count to drop by 2 for a single file, leading to incorrect state and potentially allowing premature message sending.
Solution: Only decrement in the
finally
block, not inremoveFile
. The upload promise should be the single source of truth for decrementing the counter.Apply this diff to fix the issue:
Note: The
Math.max(..., 0)
clamping here masks the double-decrement issue but doesn't fix the root cause. The upload promise'sfinally
block is sufficient to manage the counter correctly.📝 Committable suggestion
🤖 Prompt for AI Agents