Skip to content

Commit 82f2be0

Browse files
committed
fix(composer): keep a path failure from speaking for the whole drop
A mixed drop (images + other files) reported path failures through setThreadError, the single banner the image attach path also writes: a successful image attach alongside an unsupported path read as though the whole drop had failed. Path failures now go to a toast, which coexists with the banner, and the 'composer is busy' refusal is suppressed when images were in the same drop, since that refusal comes from the state that already rejected them — one drop never says it twice. insertDroppedFilePaths now reports whether it inserted, so focusComposer() is skipped only when text actually landed. The stale-state rationale applies to a successful insert; on failure there is nothing to lose and focus behaves as it always did.
1 parent d16df52 commit 82f2be0

1 file changed

Lines changed: 31 additions & 24 deletions

File tree

‎apps/web/src/components/chat/ChatComposer.tsx‎

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2565,34 +2565,41 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
25652565
};
25662566

25672567
/**
2568-
* Insert dropped non-image files as filesystem paths. Only the desktop app
2569-
* can resolve a path from a dropped File, so in a browser tab this reports
2570-
* why nothing was inserted instead of silently swallowing the drop.
2568+
* Insert dropped non-image files as filesystem paths, reporting to a toast
2569+
* rather than the thread error banner: a mixed drop's images own that banner,
2570+
* and a path failure there would read as though the whole drop failed. Only
2571+
* the desktop app can resolve a path from a dropped File, so in a browser tab
2572+
* this says so instead of silently swallowing the drop. Returns whether text
2573+
* was actually inserted.
25712574
*/
2572-
const insertDroppedFilePaths = (files: File[]) => {
2575+
const insertDroppedFilePaths = (files: File[], hadImages: boolean): boolean => {
2576+
const reportFailure = (description: string) => {
2577+
toastManager.add({ type: "error", title: "Unable to add to chat", description });
2578+
};
25732579
const resolvePath = window.desktopBridge?.getPathForFile;
25742580
if (!resolvePath) {
2575-
setThreadError(
2576-
activeThreadId,
2581+
reportFailure(
25772582
"Attaching files by path needs the desktop app. Paste an image, or type the path.",
25782583
);
2579-
return;
2584+
return false;
25802585
}
25812586
const paths = files
25822587
.map((file) => resolvePath(file))
25832588
.filter((path): path is string => path !== null);
25842589
const text = formatDroppedFilePaths(paths);
25852590
if (text.length === 0) {
2586-
setThreadError(activeThreadId, "Could not read the location of the dropped file(s).");
2587-
return;
2591+
reportFailure("Could not read the location of the dropped file(s).");
2592+
return false;
25882593
}
25892594
if (!insertComposerTextAtEnd(text, { ensureLeadingBoundary: true })) {
2590-
toastManager.add({
2591-
type: "error",
2592-
title: "Unable to add to chat",
2593-
description: "The composer is busy; try again once it is ready.",
2594-
});
2595+
// This refusal comes from the same composer state that already rejected
2596+
// the images, so one drop never says it twice.
2597+
if (!hadImages) {
2598+
reportFailure("The composer is busy; try again once it is ready.");
2599+
}
2600+
return false;
25952601
}
2602+
return true;
25962603
};
25972604

25982605
const insertComposerTextAtEnd = (
@@ -2725,17 +2732,17 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
27252732
if (images.length > 0) {
27262733
void addComposerImages(images);
27272734
}
2728-
if (nonImages.length > 0) {
2729-
// Deliberately no focusComposer() on this path. `applyPromptReplacement`
2730-
// focuses on the next frame, once Lexical has reconciled; focusing
2731-
// synchronously here makes the not-yet-reconciled editor sync its stale
2732-
// empty state back over the text we just inserted, so the drop looks
2733-
// like it silently did nothing. Same footgun the file-tree mention drop
2734-
// documents in makeComposerMentionDragHandlers.
2735-
insertDroppedFilePaths(nonImages);
2736-
return;
2735+
const insertedPath =
2736+
nonImages.length > 0 && insertDroppedFilePaths(nonImages, images.length > 0);
2737+
// Focus unless a path just landed. `applyPromptReplacement` focuses on the
2738+
// next frame, once Lexical has reconciled; focusing synchronously right
2739+
// after the insert makes the not-yet-reconciled editor sync its stale empty
2740+
// state back over the text, so the drop looks like it silently did nothing
2741+
// — the footgun makeComposerMentionDragHandlers documents for the mention
2742+
// drop. Nothing inserted means nothing to lose, so focus as before.
2743+
if (!insertedPath) {
2744+
focusComposer();
27372745
}
2738-
focusComposer();
27392746
},
27402747
insertTextAtEnd: insertComposerTextAtEnd,
27412748
openModelPicker: () => {

0 commit comments

Comments
 (0)