fix: file tree attachment bridge stale closure — use ref for attachments

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
7418andClaude Opus 4.6 committed 2026-02-12 02:12:40 +08:00
1 parent 181da8cf09
commit d3a7fd745e
1 file changed
+7 -2
+7 -2
View File
@@ -256,6 +256,11 @@ function AttachFileButton() {
*/
function FileTreeAttachmentBridge() {
const attachments = usePromptInputAttachments();
const attachmentsRef = useRef(attachments);
useEffect(() => {
attachmentsRef.current = attachments;
}, [attachments]);
useEffect(() => {
const handler = async (e: Event) => {
@@ -269,7 +274,7 @@ function FileTreeAttachmentBridge() {
const blob = await res.blob();
const filename = filePath.split('/').pop() || 'file';
const file = new File([blob], filename, { type: blob.type || 'application/octet-stream' });
attachments.add([file]);
attachmentsRef.current.add([file]);
} catch {
// Silently fail if file fetch fails
}
@@ -277,7 +282,7 @@ function FileTreeAttachmentBridge() {
window.addEventListener('attach-file-to-chat', handler);
return () => window.removeEventListener('attach-file-to-chat', handler);
}, [attachments]);
}, []);
return null;
}