You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Due for payment 2026-05-18] [$250] Drag and Drop - Incorrect error shown at first attemp to upload +30 images #87470
A React state race condition in useFilesValidation.tsx:105-108. When >30 files are dropped, validateFiles calls setIsValidatingMultipleFiles(true) at line 297, but React batches state updates — the value doesn't change until the next render. Immediately after, setErrorAndOpenModal is called at line 304, which reads the stale isValidatingMultipleFiles (still false) from the closure and creates the error object as {error: MAX_FILE_LIMIT_EXCEEDED, isValidatingMultipleFiles: false}.
In FileUtils.ts:718, getFileValidationErrorText only returns the correct "Some files can't be uploaded" message when isValidatingMultipleFiles is true. Since it's false, the code falls through to the generic default at line 780, showing "Attachment error" / "An error occurred while selecting a corrupted attachment" with only a "Close" button.
On the second attempt it works correctly because the state is now true from the first call's batched update.
What changes do you think we should make in order to solve the problem?
In setErrorAndOpenModal (useFilesValidation.tsx:105-108), accept an optional isMultipleFiles parameter that overrides the state value. Then in validateFiles, pass the locally computed validationState.isValidatingMultipleFiles (which is already correct at line 294) when calling setErrorAndOpenModal at line 304.
This way the error object uses the already-computed local value instead of waiting on the React state update. All other callers of setErrorAndOpenModal that don't pass the parameter will continue to use the state value as before.
What alternative solutions did you explore? (Optional)
An alternative is to use a ref alongside the state variable to track isValidatingMultipleFiles synchronously, but that adds unnecessary complexity since the correct value is already available as a local variable at the call site.
Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, @MelvinBot <your feedback> to refine this analysis, or explain why you are rejecting Melvin's proposal.
changed the title [-]Drag and Drop - Incorrect error shown at first attemp to upload +30 images[/-][+][$250] Drag and Drop - Incorrect error shown at first attemp to upload +30 images[/+]on Apr 9, 2026
Please re-state the problem that we are trying to solve in this issue.
When a user drags and drops more than 30 files at once into the chat area, an incorrect generic "Attachment error" modal is shown instead of the expected "Some files can't be uploaded" modal explaining the 30-receipt limit.
What is the root cause of that problem?
In useFilesValidation, the validateFiles function computes a validationState object that includes isValidatingMultipleFiles: true when more than one file is dropped. It then calls setIsValidatingMultipleFiles(validationState.isValidatingMultipleFiles) to update React state, immediately followed by setErrorAndOpenModal(...) which constructs the error object using the isValidatingMultipleFiles state variable from the current closure. Because React state updates are asynchronous, that state variable still holds its previous value (false) at the time the error object is assembled. The resulting FileValidationError therefore has isValidatingMultipleFiles: false, so getFileValidationErrorText falls through to the single-file switch block, which has no case for MAX_FILE_LIMIT_EXCEEDED and returns the generic "Attachment error" text instead of "Some files can't be uploaded."
What changes do you think we should make in order to solve the problem?
setErrorAndOpenModal should be replaced by an inline call that uses validationState.isValidatingMultipleFiles directly — the value we already have at hand — rather than reading the stale React state. This ensures the error object is built with the correct isValidatingMultipleFiles value regardless of when the state flush occurs.
The setErrorAndOpenModal helper is only used in the MAX_FILE_LIMIT_EXCEEDED branch, so it can be removed entirely. All other error paths inside validateAndResizeFiles already push errors into collectedErrors.current with the correct isValidatingMultipleFiles from the validationState parameter, so they are unaffected.
What alternative solutions did you explore? (Optional)
Please re-state the problem that we are trying to solve in this issue.
When a user drags and drops more than 30 files at once into the chat area, an incorrect generic "Attachment error" modal is shown instead of the expected "Some files can't be uploaded" modal explaining the 30-receipt limit.
What is the root cause of that problem?
When uploading more than 30 files, validateFiles() correctly detects the limit breach, but it builds the modal error payload using isValidatingMultipleFiles from React state. At that exact moment, the state update from setIsValidatingMultipleFiles(...) is not guaranteed to be applied yet, so the modal can be created as a single-file error.
Because that isValidatingMultipleFiles flag can be false in fileError, getFileValidationErrorText() skips the multi-file branch (which contains maxFileLimitExceeded) and falls back to a generic/incorrect modal path.
What changes do you think we should make in order to solve the problem?
We should make the max-limit modal rely on the synchronous validationState.isValidatingMultipleFiles value instead of the asynchronous React state value. This guarantees MAX_FILE_LIMIT_EXCEEDED is always treated as a multi-file validation error for 32-file drops and consistently shows the expected copy.
⚠️@abbasifaizan70 Thanks for your proposal. Please update it to follow the proposal template, as proposals are only reviewed if they follow that format (note the mandatory sections).
⚠️@wildan-m Your proposal is a duplicate of an already existing proposal and has been automatically withdrawn to prevent spam. Please review the existing proposals before submitting a new one.
Activity
MelvinBot commentedon Apr 9, 2026
Proposal
What is the root cause of that problem?
A React state race condition in
useFilesValidation.tsx:105-108. When >30 files are dropped,validateFilescallssetIsValidatingMultipleFiles(true)at line 297, but React batches state updates — the value doesn't change until the next render. Immediately after,setErrorAndOpenModalis called at line 304, which reads the staleisValidatingMultipleFiles(stillfalse) from the closure and creates the error object as{error: MAX_FILE_LIMIT_EXCEEDED, isValidatingMultipleFiles: false}.In
FileUtils.ts:718,getFileValidationErrorTextonly returns the correct "Some files can't be uploaded" message whenisValidatingMultipleFilesistrue. Since it'sfalse, the code falls through to the generic default at line 780, showing "Attachment error" / "An error occurred while selecting a corrupted attachment" with only a "Close" button.On the second attempt it works correctly because the state is now
truefrom the first call's batched update.What changes do you think we should make in order to solve the problem?
In
setErrorAndOpenModal(useFilesValidation.tsx:105-108), accept an optionalisMultipleFilesparameter that overrides the state value. Then invalidateFiles, pass the locally computedvalidationState.isValidatingMultipleFiles(which is already correct at line 294) when callingsetErrorAndOpenModalat line 304.This way the error object uses the already-computed local value instead of waiting on the React state update. All other callers of
setErrorAndOpenModalthat don't pass the parameter will continue to use the state value as before.What alternative solutions did you explore? (Optional)
An alternative is to use a ref alongside the state variable to track
isValidatingMultipleFilessynchronously, but that adds unnecessary complexity since the correct value is already available as a local variable at the call site.Next Steps for Contributor+ team: Reply with
@MelvinBot implement thisto create a draft PR,@MelvinBot <your feedback>to refine this analysis, or explain why you are rejecting Melvin's proposal.melvin-bot commentedon Apr 9, 2026
Triggered auto assignment to Contributor-plus team member for initial proposal review - @eh2077 (
External)[-]Drag and Drop - Incorrect error shown at first attemp to upload +30 images[/-][+][$250] Drag and Drop - Incorrect error shown at first attemp to upload +30 images[/+]melvin-bot commentedon Apr 9, 2026
Job added to Upwork: https://www.upwork.com/jobs/~022042170885304839006
MobileMage commentedon Apr 9, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
When a user drags and drops more than 30 files at once into the chat area, an incorrect generic "Attachment error" modal is shown instead of the expected "Some files can't be uploaded" modal explaining the 30-receipt limit.
What is the root cause of that problem?
In
useFilesValidation, thevalidateFilesfunction computes avalidationStateobject that includesisValidatingMultipleFiles: truewhen more than one file is dropped. It then callssetIsValidatingMultipleFiles(validationState.isValidatingMultipleFiles)to update React state, immediately followed bysetErrorAndOpenModal(...)which constructs the error object using theisValidatingMultipleFilesstate variable from the current closure. Because React state updates are asynchronous, that state variable still holds its previous value (false) at the time the error object is assembled. The resultingFileValidationErrortherefore hasisValidatingMultipleFiles: false, sogetFileValidationErrorTextfalls through to the single-fileswitchblock, which has no case forMAX_FILE_LIMIT_EXCEEDEDand returns the generic "Attachment error" text instead of "Some files can't be uploaded."App/src/hooks/useFilesValidation.tsx
Lines 299 to 308 in 441332c
What changes do you think we should make in order to solve the problem?
setErrorAndOpenModalshould be replaced by an inline call that usesvalidationState.isValidatingMultipleFilesdirectly — the value we already have at hand — rather than reading the stale React state. This ensures the error object is built with the correctisValidatingMultipleFilesvalue regardless of when the state flush occurs.App/src/hooks/useFilesValidation.tsx
Lines 105 to 108 in 441332c
The
setErrorAndOpenModalhelper is only used in theMAX_FILE_LIMIT_EXCEEDEDbranch, so it can be removed entirely. All other error paths insidevalidateAndResizeFilesalready push errors intocollectedErrors.currentwith the correctisValidatingMultipleFilesfrom thevalidationStateparameter, so they are unaffected.What alternative solutions did you explore? (Optional)
N/A
abbasifaizan70 commentedon Apr 9, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
When a user drags and drops more than 30 files at once into the chat area, an incorrect generic "Attachment error" modal is shown instead of the expected "Some files can't be uploaded" modal explaining the 30-receipt limit.
What is the root cause of that problem?
When uploading more than 30 files,
validateFiles()correctly detects the limit breach, but it builds the modal error payload usingisValidatingMultipleFilesfrom React state. At that exact moment, the state update fromsetIsValidatingMultipleFiles(...)is not guaranteed to be applied yet, so the modal can be created as a single-file error.App/src/hooks/useFilesValidation.tsx
Lines 105 to 108 in 441332c
App/src/hooks/useFilesValidation.tsx
Lines 292 to 305 in 441332c
Because that
isValidatingMultipleFilesflag can be false infileError,getFileValidationErrorText()skips the multi-file branch (which containsmaxFileLimitExceeded) and falls back to a generic/incorrect modal path.App/src/libs/fileDownload/FileUtils.ts
Lines 718 to 739 in 441332c
What changes do you think we should make in order to solve the problem?
We should make the max-limit modal rely on the synchronous
validationState.isValidatingMultipleFilesvalue instead of the asynchronous React state value. This guaranteesMAX_FILE_LIMIT_EXCEEDEDis always treated as a multi-file validation error for 32-file drops and consistently shows the expected copy.App/src/hooks/useFilesValidation.tsx
Lines 105 to 108 in 441332c
App/src/hooks/useFilesValidation.tsx
Lines 299 to 305 in 441332c
Demo
Screen.Recording.2026-04-09.at.2.31.47.PM.mov
github-actions commentedon Apr 9, 2026
wildan-m commentedon Apr 9, 2026
🚫 Duplicated proposal withdrawn by 🤖 ProposalPolice.
github-actions commentedon Apr 9, 2026
47 remaining items
melvin-bot commentedon May 17, 2026
Triggered auto assignment to @mallenexpensify (
Awaiting Payment)melvin-bot commentedon May 20, 2026
@mallenexpensify Whoops! This issue is 2 days overdue. Let's get this updated quick!
melvin-bot commentedon May 22, 2026
@mallenexpensify Huh... This is 4 days overdue. Who can take care of this?
mallenexpensify commentedon May 23, 2026
Payment Summary
Contributor: @MobileMage paid $250 via Upwork
Contributor+: @eh2077 due $250 via NewDot
^ Test case created. Thx
laurenreidexpensify commentedon May 23, 2026
$250 approved for @eh2077