Skip to content

Commit a5eeca4

Browse files
committed
Resolves #254
1 parent 478dcbd commit a5eeca4

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

.changeset/chatty-sloths-run.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"ai-elements": patch
3+
---
4+
5+
Adding multiple attachments sequentially breaks the prompt-input

packages/elements/src/prompt-input.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,10 @@ export const PromptInput = ({
474474
const [items, setItems] = useState<(FileUIPart & { id: string })[]>([]);
475475
const files = usingProvider ? controller.attachments.files : items;
476476

477+
// Keep a ref to files for cleanup on unmount (avoids stale closure)
478+
const filesRef = useRef(files);
479+
filesRef.current = files;
480+
477481
const openFileDialogLocal = useCallback(() => {
478482
inputRef.current?.click();
479483
}, []);
@@ -641,12 +645,13 @@ export const PromptInput = ({
641645
useEffect(
642646
() => () => {
643647
if (!usingProvider) {
644-
for (const f of files) {
648+
for (const f of filesRef.current) {
645649
if (f.url) URL.revokeObjectURL(f.url);
646650
}
647651
}
648652
},
649-
[usingProvider, files]
653+
// eslint-disable-next-line react-hooks/exhaustive-deps -- cleanup only on unmount; filesRef always current
654+
[usingProvider]
650655
);
651656

652657
const handleChange: ChangeEventHandler<HTMLInputElement> = (event) => {

0 commit comments

Comments
 (0)