From 13a719e90883a795ecc611fc897062ce8063dc63 Mon Sep 17 00:00:00 2001 From: Joel Date: Tue, 3 Nov 2026 19:11:49 +0530 Subject: [PATCH 01/13] fix: reject failed media downloads --- frontend/src/components/Chat/MessageList.tsx | 46 +++++++++++++------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/frontend/src/components/Chat/MessageList.tsx b/frontend/src/components/Chat/MessageList.tsx index 5281361791..2944189447 100644 --- a/frontend/src/components/Chat/MessageList.tsx +++ b/frontend/src/components/Chat/MessageList.tsx @@ -444,12 +444,22 @@ export default function MessageList({ const styles = useMessageListStyles() const messagesEndRef = useRef(null) const copyMenuId = useId() + const [downloadErrors, setDownloadErrors] = useState>({}) + + const handleDownload = async (att: MessageAttachment, downloadKey: string) => { + setDownloadErrors((current) => { + const next = { ...current } + delete next[downloadKey] + return next + }) - const handleDownload = async (att: MessageAttachment) => { try { // Convert the URL (data URI or same-origin) to a Blob, then create // an object URL so the browser reliably triggers a file download. const resp = await fetch(att.url) + if (!resp.ok) { + throw new Error(`Media download failed with HTTP ${resp.status}`) + } const blob = await resp.blob() const objectUrl = URL.createObjectURL(blob) const link = document.createElement('a') @@ -460,8 +470,8 @@ export default function MessageList({ document.body.removeChild(link) URL.revokeObjectURL(objectUrl) } catch { - // Fallback: open in a new tab rather than navigating away - window.open(att.url, '_blank') + // Keep the download action available so the user can retry. + setDownloadErrors((current) => ({ ...current, [downloadKey]: 'Download failed. Please try again.' })) } } @@ -707,18 +717,24 @@ export default function MessageList({ )} {/* Download: non-text media only */} - {!isUser && message.attachments && message.attachments.filter(a => a.type !== 'file' && a.url).map((att, ai) => ( - - {downloadErrors[downloadKey] &&
{downloadErrors[downloadKey]}
}