From 6e3dbf645293a04cfa5a7b39659b7f088304d018 Mon Sep 17 00:00:00 2001 From: Autumn-27 <53844290+Autumn-27@users.noreply.github.com> Date: Thu, 17 Sep 2026 12:40:38 -0400 Subject: [PATCH] =?UTF-8?q?fix(web):=20=E4=BF=AE=E5=A4=8D=E6=96=B0?= =?UTF-8?q?=E5=AF=B9=E8=AF=9D=E6=9C=AA=E5=88=9B=E5=BB=BA=E6=97=B6=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E6=96=87=E4=BB=B6=E6=8A=A5=E3=80=8C=E7=BC=BA=E5=B0=91?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E3=80=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Composer 的 file input onChange 里同步执行 e.target.value = "" 清空了与 input 活绑定的 FileList。DraftChat 的 pickFiles 要先 await 建会话才取文件, 恢复执行时 FileList 已空,FormData 里没有 file 字段,后端返回 400。 改为在清空 value 之前把 FileList 快照成 File[] 再回调,onPickFiles 签名 随之改为 (files: File[]),调用方去掉各自的 Array.from。 --- web/src/app/(main)/chat/page.tsx | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/web/src/app/(main)/chat/page.tsx b/web/src/app/(main)/chat/page.tsx index a96b05d..952ae07 100644 --- a/web/src/app/(main)/chat/page.tsx +++ b/web/src/app/(main)/chat/page.tsx @@ -171,7 +171,7 @@ function Composer({ stopDisabled?: boolean; // 方式1 文件上传:传了 onPickFiles 才显示回形针按钮 + 附件 chip 预览。 attachments?: ChatAttachment[]; - onPickFiles?: (files: FileList | null) => void; + onPickFiles?: (files: File[]) => void; onRemoveAttachment?: (path: string) => void; uploading?: boolean; allowBtw?: boolean; @@ -222,8 +222,11 @@ function Composer({ multiple className="hidden" onChange={(e) => { - onPickFiles(e.target.files); + // FileList 与 input 元素活绑定:必须先快照成数组,再清空 value, + // 否则异步的 onPickFiles(比如草稿态要先建会话)恢复执行时会拿到空列表。 + const picked = Array.from(e.target.files ?? []); e.target.value = ""; // allow re-picking the same file + if (picked.length > 0) onPickFiles(picked); }} />