diff --git a/frontend/src/components/message/MessagePart.test.tsx b/frontend/src/components/message/MessagePart.test.tsx
index 8ff528b9..57272eeb 100644
--- a/frontend/src/components/message/MessagePart.test.tsx
+++ b/frontend/src/components/message/MessagePart.test.tsx
@@ -1,5 +1,5 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
-import { render, screen, fireEvent } from '@testing-library/react'
+import { render, screen, fireEvent, within } from '@testing-library/react'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { MemoryRouter } from 'react-router-dom'
import { MessagePart } from './MessagePart'
@@ -175,6 +175,22 @@ describe('MessagePart', () => {
expect(container.querySelector('img')).toBeNull()
})
+
+ it('renders a linked image without a nested expand button', () => {
+ renderWithProviders(
+ ,
+ )
+
+ const link = screen.getByRole('link')
+ expect(within(link).getByAltText('logo')).toHaveAttribute('src', 'https://example.com/a.png')
+ expect(within(link).queryByRole('button')).toBeNull()
+ })
+
+ it('renders an expand button for an unlinked image', () => {
+ renderWithProviders()
+
+ expect(screen.getByRole('button', { name: 'Expand image: logo' })).toBeInTheDocument()
+ })
})
describe('reasoning', () => {
diff --git a/frontend/src/components/ui/inline-image.test.tsx b/frontend/src/components/ui/inline-image.test.tsx
index fab0ef5f..d3ecde34 100644
--- a/frontend/src/components/ui/inline-image.test.tsx
+++ b/frontend/src/components/ui/inline-image.test.tsx
@@ -22,4 +22,33 @@ describe('InlineImage', () => {
expect(screen.queryByRole('button')).not.toBeInTheDocument()
expect(screen.getByText('shot.png')).toBeInTheDocument()
})
+
+ it('retries a new source after an image failure', () => {
+ const { rerender } = render()
+
+ fireEvent.error(screen.getByAltText('shot.png'))
+
+ expect(screen.queryByRole('button')).not.toBeInTheDocument()
+ expect(screen.getByText('shot.png')).toBeInTheDocument()
+
+ rerender()
+
+ expect(screen.getByAltText('shot.png')).toHaveAttribute('src', 'data:image/png;base64,aGVsbG8=')
+ expect(screen.getByRole('button', { name: 'Expand image: shot.png' })).toBeInTheDocument()
+ })
+
+ it('renders only the image without an expand button when not expandable', () => {
+ render()
+
+ expect(screen.getByAltText('shot.png')).toHaveAttribute('src', 'data:image/png;base64,aGVsbG8=')
+ expect(screen.queryByRole('button')).not.toBeInTheDocument()
+ })
+
+ it('falls back to the alt text for a non-expandable image that fails to load', () => {
+ render()
+
+ fireEvent.error(screen.getByAltText('shot.png'))
+
+ expect(screen.getByText('shot.png')).toBeInTheDocument()
+ })
})
diff --git a/frontend/src/components/ui/inline-image.tsx b/frontend/src/components/ui/inline-image.tsx
index 7fd5f185..6870f9a9 100644
--- a/frontend/src/components/ui/inline-image.tsx
+++ b/frontend/src/components/ui/inline-image.tsx
@@ -3,17 +3,46 @@ import { cn } from '@/lib/utils'
import { Dialog, DialogContent, DialogTitle } from '@/components/ui/dialog'
/**
- * Renders an image as a bounded thumbnail button that opens a full-size preview dialog.
- * Falls back to a muted alt-text span (or nothing) when the image fails to load.
+ * Renders an image as a bounded thumbnail that opens a full-size preview dialog when expandable.
+ * Falls back to a muted alt-text span (or nothing) when the image fails to load, retrying when the source changes.
*/
-export function InlineImage({ src, alt, className }: { src: string; alt?: string; className?: string }) {
+export function InlineImage({
+ src,
+ alt,
+ className,
+ expandable = true,
+}: {
+ src: string
+ alt?: string
+ className?: string
+ expandable?: boolean
+}) {
const [open, setOpen] = useState(false)
- const [failed, setFailed] = useState(false)
+ const [failedSrc, setFailedSrc] = useState(null)
+ const failed = failedSrc === src
if (failed) {
return alt ? {alt} : null
}
+ const image = (
+
setFailedSrc(src)}
+ className={cn(
+ 'max-w-full max-h-80 rounded-lg border border-border object-contain',
+ expandable && 'cursor-zoom-in',
+ className,
+ )}
+ />
+ )
+
+ if (!expandable) {
+ return image
+ }
+
return (
<>