File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed
Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " ai-elements " : patch
3+ ---
4+
5+ Adding multiple attachments sequentially breaks the prompt-input
Original file line number Diff line number Diff 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 ) => {
You can’t perform that action at this time.
0 commit comments