fix(web): guard empty multiFiles array in getProcessedInputs#37528
Open
he-yufeng wants to merge 1 commit into
Open
fix(web): guard empty multiFiles array in getProcessedInputs#37528he-yufeng wants to merge 1 commit into
he-yufeng wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
getProcessedInputsthrows when a multi-file chat input has an empty array value.In
web/app/components/base/chat/chat/utils.tsthe multiFiles branch does:When the field value is
[],inputValue[0]isundefined, so theinoperator throwsTypeError: Cannot use 'in' operator to search for 'transfer_method' in undefined. An empty array is notnull, so the earlierinputValue == nullguard does not catch it. This takes down the whole input-processing step before the message is sent whenever a chat app has a multi-file form field that the user leaves empty.The fix guards the element access:
An empty array now falls through to
getProcessedFiles(inputValue), which returns[]. Server-file arrays (first element carriestransfer_method) and local-file arrays keep their existing behavior.Screenshots
N/A, logic fix with no UI change.
How I verified
Added a regression case to the existing suite (
web/app/components/base/chat/chat/__tests__/utils.spec.ts) that throws on currentmainand passes with the fix:I exercised the multiFiles branch against the suite's
getProcessedFilesmock: on currentmainan empty array throws theTypeErrorabove, and with the guard it returns[]. The server-file and local-file cases are unchanged. I could not run the fullwebvitest suite locally (deps would not install on my machine), so CI is the source of truth for the suite run.Checklist
make lint && make type-check(backend) andcd web && pnpm exec vp staged(frontend) to appease the lint godsFrom Claude Code