mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-05-21 23:46:50 +00:00
fix(frontend): wait for async chat submit before clearing (#2940)
* fix(frontend): wait for async chat submit before clearing * test(frontend): cover pending attachment uploads * fix(frontend): preserve sync submit semantics
This commit is contained in:
@@ -499,6 +499,10 @@ export const PromptInput = ({
|
||||
// Keep a ref to files for cleanup on unmount (avoids stale closure)
|
||||
const filesRef = useRef(files);
|
||||
filesRef.current = files;
|
||||
const providerTextRef = useRef("");
|
||||
if (usingProvider) {
|
||||
providerTextRef.current = controller.textInput.value;
|
||||
}
|
||||
|
||||
const openFileDialogLocal = useCallback(() => {
|
||||
inputRef.current?.click();
|
||||
@@ -768,6 +772,24 @@ export const PromptInput = ({
|
||||
}
|
||||
|
||||
// Convert blob URLs to data URLs asynchronously
|
||||
const submittedFileIds = files.map((file) => file.id);
|
||||
const clearSubmittedState = () => {
|
||||
const currentFileIds = new Set(filesRef.current.map((file) => file.id));
|
||||
const submittedFileIdsStillPresent = submittedFileIds.filter((id) =>
|
||||
currentFileIds.has(id),
|
||||
);
|
||||
if (submittedFileIdsStillPresent.length === filesRef.current.length) {
|
||||
clear();
|
||||
} else {
|
||||
for (const id of submittedFileIdsStillPresent) {
|
||||
remove(id);
|
||||
}
|
||||
}
|
||||
if (usingProvider && providerTextRef.current === text) {
|
||||
controller.textInput.clear();
|
||||
}
|
||||
};
|
||||
|
||||
Promise.all(
|
||||
files.map(async ({ id, ...item }) => {
|
||||
if (item.file instanceof File) {
|
||||
@@ -793,20 +815,14 @@ export const PromptInput = ({
|
||||
if (result instanceof Promise) {
|
||||
result
|
||||
.then(() => {
|
||||
clear();
|
||||
if (usingProvider) {
|
||||
controller.textInput.clear();
|
||||
}
|
||||
clearSubmittedState();
|
||||
})
|
||||
.catch(() => {
|
||||
// Don't clear on error - user may want to retry
|
||||
});
|
||||
} else {
|
||||
// Sync function completed without throwing, clear attachments
|
||||
clear();
|
||||
if (usingProvider) {
|
||||
controller.textInput.clear();
|
||||
}
|
||||
clearSubmittedState();
|
||||
}
|
||||
} catch {
|
||||
// Don't clear on error - user may want to retry
|
||||
|
||||
Reference in New Issue
Block a user