Fix inline Markdown image previews in chat - #4785
Conversation
- Resolve workspace image paths against the thread cwd - Add loading, unavailable, and expandable image states - Cover markdown image path resolution with focused tests
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| /> | ||
| ); | ||
| }, | ||
| img({ node: _node, src, alt, ...props }) { |
There was a problem hiding this comment.
🟡 Medium components/ChatMarkdown.tsx:1657
Passing onExpand to MarkdownImage unconditionally renders a <button> inside the <a> for linked-image Markdown like [](https://example.com). This produces invalid nested interactive elements (<button> inside <a>) and causes a single click to both trigger image expansion and bubble to the anchor, navigating the link. The img component override should suppress or coordinate onExpand when the image is rendered inside a link.
🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/web/src/components/ChatMarkdown.tsx around line 1657:
Passing `onExpand` to `MarkdownImage` unconditionally renders a `<button>` inside the `<a>` for linked-image Markdown like `[](https://example.com)`. This produces invalid nested interactive elements (`<button>` inside `<a>`) and causes a single click to both trigger image expansion and bubble to the anchor, navigating the link. The `img` component override should suppress or coordinate `onExpand` when the image is rendered inside a link.
What Changed
file://paths.Why
When the T3 Code server runs on one device and the web client is opened on another, local image paths from assistant messages cannot be loaded directly by the browser. They currently render as broken images with only their alt text visible.
Using the existing thread-scoped asset flow lets the environment that owns the workspace serve the image securely to the connected client without broadening filesystem access.
UI Changes
Before
Workspace-local Markdown images render as broken image icons and alt text.
Before screenshot to be attached.
After
Images render as compact previews with a subtle outline. Clicking a preview opens the existing expanded-image dialog, and Escape closes it again.
After screenshot and short interaction recording to be attached.
Verification
vp test run apps/web/src/markdown-images.test.ts apps/web/src/components/chat/MessagesTimeline.test.tsx— 18 tests passed.vp run --filter @t3tools/web typecheckpassed./api/assets/, displayed as 288×288 previews, expanded on click, and closed with Escape.Checklist
Note
Fix inline Markdown image previews in chat
MarkdownImagerenderer toChatMarkdownthat routes<img>tags through a workspace asset resolution pipeline or renders them directly.useAssetUrlStateand show loading/unavailable states while fetching or on failure.onImageExpandcallback (wired throughMessagesTimeline) to open an expanded preview.resolveMarkdownImageFilein markdown-images.ts to detect whether an image src refers to a workspace file path.📊 Macroscope summarized d9e6b6e. 3 files reviewed, 0 issues evaluated, 0 issues filtered, 0 comments posted
🗂️ Filtered Issues
No issues evaluated.