fix: fall back to file icon when document thumbnail fails to load
Render the 52x52 preview with an empty alt and an onError handler, so a broken thumbnail no longer shows the browser's broken-image box (which leaked the raw filename) — it falls back to the file-type icon instead. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -19,6 +19,7 @@ function AttachmentRow({ postId, att }: { postId: string; att: Attachment }) {
|
|||||||
const { Icon, color } = fileIcon({ mime: att.mime, filename: att.filename });
|
const { Icon, color } = fileIcon({ mime: att.mime, filename: att.filename });
|
||||||
const displayFilename = filenameWithExtension(att.filename, att.mime);
|
const displayFilename = filenameWithExtension(att.filename, att.mime);
|
||||||
const [isDownloading, setIsDownloading] = useState(false);
|
const [isDownloading, setIsDownloading] = useState(false);
|
||||||
|
const [previewFailed, setPreviewFailed] = useState(false);
|
||||||
|
|
||||||
const handleDownload = async () => {
|
const handleDownload = async () => {
|
||||||
if (isDownloading) return;
|
if (isDownloading) return;
|
||||||
@@ -39,11 +40,12 @@ function AttachmentRow({ postId, att }: { postId: string; att: Attachment }) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="group flex h-[52px] items-center gap-3">
|
<div className="group flex h-[52px] items-center gap-3">
|
||||||
{previewUrl ? (
|
{previewUrl && !previewFailed ? (
|
||||||
<img
|
<img
|
||||||
src={previewUrl}
|
src={previewUrl}
|
||||||
alt={displayFilename}
|
alt=""
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
|
onError={() => setPreviewFailed(true)}
|
||||||
className="h-[52px] w-[52px] shrink-0 rounded-full object-cover"
|
className="h-[52px] w-[52px] shrink-0 rounded-full object-cover"
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
Reference in New Issue
Block a user