Skip to content

fix(web): guard empty multiFiles array in getProcessedInputs#37528

Open
he-yufeng wants to merge 1 commit into
langgenius:mainfrom
he-yufeng:fix/chat-empty-multifiles
Open

fix(web): guard empty multiFiles array in getProcessedInputs#37528
he-yufeng wants to merge 1 commit into
langgenius:mainfrom
he-yufeng:fix/chat-empty-multifiles

Conversation

@he-yufeng

Copy link
Copy Markdown

Summary

getProcessedInputs throws when a multi-file chat input has an empty array value.

In web/app/components/base/chat/chat/utils.ts the multiFiles branch does:

if ('transfer_method' in inputValue[0])

When the field value is [], inputValue[0] is undefined, so the in operator throws TypeError: Cannot use 'in' operator to search for 'transfer_method' in undefined. An empty array is not null, so the earlier inputValue == null guard 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:

if (inputValue[0] && 'transfer_method' in inputValue[0])

An empty array now falls through to getProcessedFiles(inputValue), which returns []. Server-file arrays (first element carries transfer_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 current main and passes with the fix:

it('handles an empty multiFiles array without throwing', () => {
  const inputs = { files1: [] }
  const inputsForm = [{ variable: 'files1', type: InputVarType.multiFiles as string }]
  const result = getProcessedInputs(inputs, inputsForm as InputForm[])
  expect(result.files1).toEqual([])
})

I exercised the multiFiles branch against the suite's getProcessedFiles mock: on current main an empty array throws the TypeError above, and with the guard it returns []. The server-file and local-file cases are unchanged. I could not run the full web vitest suite locally (deps would not install on my machine), so CI is the source of truth for the suite run.

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran make lint && make type-check (backend) and cd web && pnpm exec vp staged (frontend) to appease the lint gods

From Claude Code

@he-yufeng he-yufeng requested review from iamjoel and zxhlyh as code owners June 16, 2026 10:58
@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jun 16, 2026
@github-actions github-actions Bot added the web This relates to changes on the web. label Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS This PR changes 0-9 lines, ignoring generated files. web This relates to changes on the web.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant