From f488b8762d833e67fae100a637de8882f2185ba7 Mon Sep 17 00:00:00 2001
From: Chris Scott <>
Date: Tue, 13 Oct 2026 01:46:51 +0000
Subject: [PATCH] fix(markdown): address inline image review feedback
Keep the leading slash when resolving relative paths against an absolute
markdown file, retry an inline image when its source changes after a load
failure, and render linked markdown images without a nested expand button.
---
.../components/message/MessagePart.test.tsx | 18 ++++++-
.../src/components/ui/inline-image.test.tsx | 29 +++++++++++
frontend/src/components/ui/inline-image.tsx | 48 +++++++++++++------
frontend/src/components/ui/markdown-image.tsx | 5 +-
frontend/src/components/ui/markdown-link.tsx | 15 ++++--
frontend/src/lib/markdownLinks.test.ts | 12 +++++
frontend/src/lib/markdownLinks.ts | 13 +++--
7 files changed, 118 insertions(+), 22 deletions(-)
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 (
<>