Skip to content

The agent that grows with you

fix(desktop): show full-resolution attachments in sent bubble and lightbox

rainbowgits189f0516794f
diff --git a/apps/desktop/src/components/assistant-ui/directive-text.tsx b/apps/desktop/src/components/assistant-ui/directive-text.tsx
index 98fc0467c57..fadb18d7cad 100644
--- a/apps/desktop/src/components/assistant-ui/directive-text.tsx
+++ b/apps/desktop/src/components/assistant-ui/directive-text.tsx
@@ -10,6 +10,7 @@ import type { I18nContextValue } from '@/i18n'
import { extractEmbeddedImages } from '@/lib/embedded-images'
import { ExternalLink, openLink } from '@/lib/external-link'
import { triggerHaptic } from '@/lib/haptics'
+import { downscaleDataUrlForPreview, FALLBACK_PLACEHOLDER } from '@/lib/image-resize'
import { gatewayMediaDataUrl, isRemoteGateway } from '@/lib/media'
import { useSessionLinkTitle } from '@/lib/session-link-title'
import { parseSessionRefValue, sessionRefFallbackLabel } from '@/lib/session-refs'
@@ -401,7 +402,12 @@ export const DirectiveText: TextMessagePartComponent = ({ text }: TextMessagePar
* across initial send and refresh. */
const DirectiveImage: FC<{ id: string; label: string }> = ({ id, label }) => {
const isUrl = /^(?:https?|data):/i.test(id)
+ // `src` is the bounded thumbnail painted inline; `zoomSrc` is the full-
+ // resolution source the lightbox and download use. Keeping inline bounded is
+ // what lets the in-flight bubble render an `@image:<path>` ref without the
+ // multi-image paint freeze the 512px cap exists to prevent (#93204).
const [src, setSrc] = useState<string | null>(isUrl ? id : null)
+ const [zoomSrc, setZoomSrc] = useState<string | null>(isUrl ? id : null)
const [failed, setFailed] = useState(false)
useEffect(() => {
@@ -417,7 +423,23 @@ const DirectiveImage: FC<{ id: string; label: string }> = ({ id, label }) => {
window.hermesDesktop && isRemoteGateway() ? gatewayMediaDataUrl(id) : window.hermesDesktop?.readFileDataUrl(id)
void Promise.resolve(load)
- .then(url => alive && url && setSrc(url))
+ .then(async url => {
+ if (!alive || !url) {
+ return
+ }
+
+ // Full resolution powers the click-to-zoom lightbox and Save; the inline
+ // <img> gets a bounded thumbnail so a turn full of screenshots does not
+ // hand Chromium multi-MB paint sources.
+ setZoomSrc(url)
+ const thumbnail = await downscaleDataUrlForPreview(url)
+
+ if (!alive) {
+ return
+ }
+
+ setSrc(thumbnail && thumbnail !== FALLBACK_PLACEHOLDER ? thumbnail : url)
+ })
.catch(() => alive && setFailed(true))
return () => {
@@ -445,6 +467,7 @@ const DirectiveImage: FC<{ id: string; label: string }> = ({ id, label }) => {
draggable={false}
slot="aui_directive-image"
src={src}
+ zoomSrc={zoomSrc ?? undefined}
/>
)
}
diff --git a/apps/desktop/src/components/chat/zoomable-image.test.tsx b/apps/desktop/src/components/chat/zoomable-image.test.tsx
new file mode 100644
index 00000000000..6cf1e834845
--- /dev/null
+++ b/apps/desktop/src/components/chat/zoomable-image.test.tsx
@@ -0,0 +1,62 @@
+import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
+import { afterEach, describe, expect, it } from 'vitest'
+
+import { I18nProvider } from '@/i18n/context'
+
+import { ZoomableImage } from './zoomable-image'
+
+// A bounded thumbnail (what the composer/optimistic bubble paints inline) and
+// the full-resolution source (what the lightbox should enlarge). Issue #93204:
+// clicking a freshly sent image enlarged the 512px thumbnail instead of the
+// original.
+const THUMB = 'data:image/png;base64,dGh1bWJuYWls'
+const FULL = 'data:image/png;base64,ZnVsbHJlc29sdXRpb24='
+
+async function renderWithI18n(ui: React.ReactNode) {
+ let result: ReturnType<typeof render>
+ await act(async () => {
+ result = render(
+ <I18nProvider configClient={{ getConfig: async () => ({}), saveConfig: async () => ({ ok: true }) }}>
+ {ui}
+ </I18nProvider>
+ )
+ })
+
+ return result!
+}
+
+describe('ZoomableImage zoomSrc', () => {
+ afterEach(() => {
+ cleanup()
+ })
+
+ it('paints the bounded src inline but enlarges the full-resolution zoomSrc (#93204)', async () => {
+ await renderWithI18n(<ZoomableImage alt="shot" src={THUMB} zoomSrc={FULL} />)
+
+ // Inline stays the cheap thumbnail — no multi-MB paint.
+ const inline = screen.getByAltText('shot') as HTMLImageElement
+ expect(inline.getAttribute('src')).toBe(THUMB)
+
+ // Click to zoom: the lightbox must show the original, not the thumbnail.
+ fireEvent.click(inline)
+
+ await waitFor(() => {
+ const full = screen.getAllByAltText('shot').find(img => img.getAttribute('src') === FULL)
+ expect(full).toBeDefined()
+ })
+
+ expect(screen.queryAllByAltText('shot').some(img => img.getAttribute('src') === THUMB)).toBe(true)
+ })
+
+ it('falls back to src for the lightbox when no zoomSrc is given', async () => {
+ await renderWithI18n(<ZoomableImage alt="shot" src={THUMB} />)
+
+ fireEvent.click(screen.getByAltText('shot'))
+
+ await waitFor(() => {
+ // Both inline and lightbox use src — backward compatible with callers that
+ // pass a single source.
+ expect(screen.getAllByAltText('shot').every(img => img.getAttribute('src') === THUMB)).toBe(true)
+ })
+ })
+})
diff --git a/apps/desktop/src/components/chat/zoomable-image.tsx b/apps/desktop/src/components/chat/zoomable-image.tsx
index 97adb6490ba..335aad61fef 100644
--- a/apps/desktop/src/components/chat/zoomable-image.tsx
+++ b/apps/desktop/src/components/chat/zoomable-image.tsx
@@ -11,6 +11,11 @@ import { cn } from '@/lib/utils'
export interface ZoomableImageProps extends ComponentProps<'img'> {
containerClassName?: string
slot?: string
+ /** Full-resolution source for the lightbox and download. When set, the inline
+ * `<img>` keeps its bounded `src` (avoiding heavy inline paints) while the
+ * zoom view and Save action use the original — so a click-to-zoom shows real
+ * detail instead of an upscaled thumbnail. Defaults to `src`. */
+ zoomSrc?: string
}
export interface ImageActionCopy {
@@ -18,10 +23,13 @@ export interface ImageActionCopy {
savingImage: string
}
-export function ZoomableImage({ className, containerClassName, src, alt, slot, ...props }: ZoomableImageProps) {
+export function ZoomableImage({ className, containerClassName, src, zoomSrc, alt, slot, ...props }: ZoomableImageProps) {
const { t } = useI18n()
const copy = t.desktop
- const { download, saving } = useImageDownload(src)
+ // The lightbox and Save action prefer the full-resolution source; the inline
+ // thumbnail (`src`) stays the cheap paint.
+ const fullSrc = zoomSrc || src || ''
+ const { download, saving } = useImageDownload(fullSrc)
const [lightboxOpen, setLightboxOpen] = useState(false)
const canOpen = Boolean(src)
@@ -52,7 +60,7 @@ export function ZoomableImage({ className, containerClassName, src, alt, slot, .
onOpenChange={setLightboxOpen}
open={lightboxOpen}
saving={saving}
- src={src}
+ src={fullSrc}
/>
)}
</>
diff --git a/apps/desktop/src/lib/chat-runtime.test.ts b/apps/desktop/src/lib/chat-runtime.test.ts
index 7f4f039e2f3..b8c91b02e49 100644
--- a/apps/desktop/src/lib/chat-runtime.test.ts
+++ b/apps/desktop/src/lib/chat-runtime.test.ts
@@ -22,33 +22,56 @@ function attachment(overrides: Partial<ComposerAttachment> & Pick<ComposerAttach
}
describe('optimisticAttachmentRef', () => {
- it('renders an image from its in-hand base64 preview (no @image: path ref)', () => {
+ it('renders a path-backed image through the same @image: ref as a reloaded turn (#93204)', () => {
const ref = optimisticAttachmentRef(attachment({ kind: 'image', detail: '/tmp/shot.png', previewUrl: DATA_URL }))
- // The raw data URL flows through extractEmbeddedImages → inline thumbnail,
- // dodging the remote /api/media 403 an @image:<localpath> ref would hit.
- expect(ref).toBe(DATA_URL)
+ // DirectiveImage paints a bounded thumbnail inline and hands the full file
+ // to the lightbox, so the in-flight bubble matches the reloaded turn instead
+ // of freezing on a 512px thumbnail. Remote gateways resolve the same path
+ // over the authenticated media API (no /api/media 403).
+ expect(ref).toBe('@image:/tmp/shot.png')
})
- it('prefers the downscaled thumbnail for the display ref when present', () => {
+ it('prefers the path ref even when a downscaled thumbnail is present (#93204)', () => {
const ref = optimisticAttachmentRef(
- attachment({ kind: 'image', detail: '/tmp/shot.png', previewUrl: DATA_URL, thumbnailUrl: THUMB_URL })
+ attachment({ kind: 'image', path: '/tmp/shot.png', previewUrl: DATA_URL, thumbnailUrl: THUMB_URL })
)
- // The bubble is display-only; full bytes are read on demand and for upload.
- expect(ref).toBe(THUMB_URL)
+ // The thumbnail no longer caps fidelity: the path lets the lightbox load the
+ // original. Full bytes are read on demand and for upload.
+ expect(ref).toBe('@image:/tmp/shot.png')
})
- it('does not render a full path-backed image while its bounded thumbnail is pending', () => {
- expect(optimisticAttachmentRef(attachment({ kind: 'image', detail: '/tmp/shot.png' }))).toBeNull()
+ it('emits the path ref for a freshly attached image before its thumbnail resolves (#93204)', () => {
+ // Previously this returned null (waiting on the resize); now the path drives
+ // an @image: ref that DirectiveImage renders bounded-inline immediately.
+ expect(optimisticAttachmentRef(attachment({ kind: 'image', detail: '/tmp/shot.png' }))).toBe('@image:/tmp/shot.png')
})
- it('does not use a path fallback for a non-data preview url', () => {
+ it('emits the path ref regardless of a non-data preview url (#93204)', () => {
const ref = optimisticAttachmentRef(
attachment({ kind: 'image', detail: '/tmp/shot.png', previewUrl: 'https://example.com/x.png' })
)
- expect(ref).toBeNull()
+ expect(ref).toBe('@image:/tmp/shot.png')
+ })
+
+ it('falls back to the bounded thumbnail for a path-less pasted image', () => {
+ // No filesystem path to rehydrate from (raw clipboard bytes): keep the
+ // inline thumbnail so the bubble still renders something.
+ const ref = optimisticAttachmentRef(attachment({ kind: 'image', previewUrl: DATA_URL, thumbnailUrl: THUMB_URL }))
+
+ expect(ref).toBe(THUMB_URL)
+ })
+
+ it('falls back to a data preview url when a path-less image has no thumbnail', () => {
+ const ref = optimisticAttachmentRef(attachment({ kind: 'image', previewUrl: DATA_URL }))
+
+ expect(ref).toBe(DATA_URL)
+ })
+
+ it('returns null for a path-less image with no renderable inline source', () => {
+ expect(optimisticAttachmentRef(attachment({ kind: 'image', previewUrl: 'https://example.com/x.png' }))).toBeNull()
})
it('passes non-image attachments straight through to attachmentDisplayText', () => {
diff --git a/apps/desktop/src/lib/chat-runtime.ts b/apps/desktop/src/lib/chat-runtime.ts
index d8b0c3140e3..363b188362d 100644
--- a/apps/desktop/src/lib/chat-runtime.ts
+++ b/apps/desktop/src/lib/chat-runtime.ts
@@ -232,9 +232,23 @@ export function optimisticAttachmentRef(attachment: ComposerAttachment): string
}
if (attachment.kind === 'image') {
+ // Prefer a filesystem-backed `@image:<path>` ref so the in-flight bubble
+ // renders through the same DirectiveImage path as a reloaded turn. That
+ // component shows a bounded thumbnail inline (no full-resolution paint, so
+ // the multi-image send freeze this design guards against does not return)
+ // and hands the full-resolution file to the lightbox/download — fixing the
+ // live-vs-reload fidelity gap where a sent screenshot stayed 512px until a
+ // session reload rehydrated it (#93204). Remote gateways resolve the same
+ // path over the authenticated media API, so no /api/media 403.
+ const pathRef = attachment.path || attachment.detail
+
+ if (pathRef) {
+ return `@image:${formatRefValue(pathRef)}`
+ }
+
if (attachment.thumbnailUrl?.startsWith('data:')) {
- // The pill and the in-flight bubble render the bounded thumbnail. Full
- // bytes are read separately for lightbox/download and model upload.
+ // No path to rehydrate from (e.g. pasted bytes): render the bounded
+ // thumbnail inline. Full bytes remain available for the model upload.
return attachment.thumbnailUrl
}
@@ -244,10 +258,9 @@ export function optimisticAttachmentRef(attachment: ComposerAttachment): string
return attachment.previewUrl
}
- // A newly attached image has no thumbnail while its queued resize is still
- // pending. Do not fall through to @image:<path>: the optimistic bubble would
- // fetch and paint the full source, recreating the freeze if Send wins the
- // race. The model upload remains path/byte based and is unaffected.
+ // A newly attached image with no path and no thumbnail yet: the queued
+ // resize is still pending. Render nothing rather than paint the full source
+ // and recreate the freeze if Send wins the race.
return null
}
diff --git a/apps/desktop/src/lib/image-resize.ts b/apps/desktop/src/lib/image-resize.ts
index 16394883635..7c77d1f85fa 100644
--- a/apps/desktop/src/lib/image-resize.ts
+++ b/apps/desktop/src/lib/image-resize.ts
@@ -16,7 +16,7 @@
*/
/** 1×1 transparent PNG — fail closed so the pill never receives the original. */
-const FALLBACK_PLACEHOLDER =
+export const FALLBACK_PLACEHOLDER =
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+GkZcAAAAASUVORK5CYII='
// Composer pills render at 32 CSS pixels. A 512px source stays sharp on