feat: use aspect-ratio and preload=none for video/image attachments

This commit is contained in:
Jannis Braun
2026-03-21 17:20:54 +01:00
parent 561c9bc4f3
commit 7ec61c16fd
@@ -29,12 +29,16 @@ export function AttachmentRenderer({ attachment }: AttachmentRendererProps) {
const { mimetype, originalName, size } = attachment; const { mimetype, originalName, size } = attachment;
if (mimetype.startsWith('image/')) { if (mimetype.startsWith('image/')) {
const { width, height } = attachment;
return ( return (
<div className="max-w-fit mt-1 rounded-lg overflow-hidden border border-white/[0.06]"> <div
className="max-w-fit mt-1 rounded-lg overflow-hidden border border-white/[0.06]"
style={width && height ? { aspectRatio: `${width}/${height}`, maxWidth: Math.min(width, 550), maxHeight: 350 } : undefined}
>
<img <img
src={thumbUrl ?? attUrl} src={thumbUrl ?? attUrl}
alt={originalName} alt={originalName}
className="max-w-full max-h-[350px] object-contain cursor-pointer hover:brightness-95 transition-all" className="w-full h-full object-contain cursor-pointer hover:brightness-95 transition-all"
onClick={() => openImagePreview(attUrl)} onClick={() => openImagePreview(attUrl)}
loading="lazy" loading="lazy"
/> />
@@ -43,13 +47,18 @@ export function AttachmentRenderer({ attachment }: AttachmentRendererProps) {
} }
if (mimetype.startsWith('video/')) { if (mimetype.startsWith('video/')) {
const { width, height } = attachment;
const hasDimensions = width && height;
return ( return (
<div className="mt-1 max-w-[520px]"> <div
className="mt-1 max-w-[520px] rounded-lg overflow-hidden"
style={hasDimensions ? { aspectRatio: `${width}/${height}`, maxHeight: 400 } : undefined}
>
<video <video
controls controls
preload="metadata" preload={hasDimensions ? 'none' : 'metadata'}
poster={thumbUrl ?? undefined} poster={thumbUrl ?? undefined}
className="max-w-full max-h-[400px] rounded-lg" className="w-full h-full rounded-lg"
> >
<source src={attUrl} type={mimetype} /> <source src={attUrl} type={mimetype} />
Your browser does not support video playback. Your browser does not support video playback.