Fix inline Markdown image previews in chat #4785
main fromrefs/pull/4785/head·opened View on GitHubWhat Changed#
- Render Markdown images in assistant messages as compact inline previews.
- Resolve workspace-local image paths through T3 Code's existing signed asset route, including relative, absolute, and
file://paths. - Add loading and unavailable states while preserving external image URLs.
- Reuse the existing expanded-image dialog when an inline preview is clicked.
- Keep linked Markdown images under the surrounding link's interaction instead of nesting an image-preview button inside the anchor.
- Add focused tests for Markdown image path resolution and linked-image semantics.
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— 19 tests passed.vp run --filter @t3tools/web typecheckpassed.- Targeted formatting and linting completed without errors.
- Integrated browser verification in an isolated T3 environment confirmed that workspace images were served through
/api/assets/; standalone images expanded and closed with Escape, while a linked image opened only its link without rendering a nested button or opening the image dialog.
Checklist#
- This PR is small and focused
- I explained what changed and why
- I included before/after screenshots for any UI changes
- I included a video for animation/interaction changes
Note
Medium Risk Touches chat rendering and workspace file asset URLs for assistant messages; scope is bounded to image paths and existing asset APIs, but remote clients now depend on signed asset delivery for local paths.
Overview
Assistant chat Markdown now renders img nodes as inline previews instead of raw broken <img> tags when paths point at workspace images.
Workspace-local sources (relative, absolute, and file://) are resolved with new resolveMarkdownImageFile and loaded through the existing thread-scoped signed asset route via useAssetUrlState, with loading and unavailable placeholders. External URLs still use direct src. Standalone previews can open the existing expanded-image dialog through a new onImageExpand prop wired from MessagesTimeline.
Linked images ([](url)) no longer nest a zoom button inside the anchor—a context flag disables expand so the link keeps sole click behavior.
Tests cover path resolution and linked-vs-standalone image semantics in the timeline markup.
Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit a8dbe3e2ad7d14f3c882744fec435929a183bea3. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).Note
Fix inline Markdown image previews in chat with workspace file resolution and expansion#
- Adds a custom image renderer in ChatMarkdown.tsx that resolves workspace-relative image paths to asset URLs, shows loading/unavailable placeholders, and triggers an
onImageExpandcallback on click. - Introduces markdown-images.ts with
resolveMarkdownImageFileto determine when a markdown image src refers to a workspace file eligible for asset resolution. - Images nested inside links (anchor tags) suppress the expansion button and remain link-clickable only, detected via a new
MarkdownImageInsideLinkContext. - Wires
onImageExpandthroughAssistantTimelineRowin MessagesTimeline.tsx so assistant message images trigger the timeline's existing image expansion handler.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/web/src/components/ChatMarkdown.tsx line 1661Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1490,3 +1654,4 @@14901654 />14911655 );14921656 },1657+ img({ node: _node, src, alt, ...props }) {
🟡 Medium
components/ChatMarkdown.tsx:1657Passing
onExpandtoMarkdownImageunconditionally 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. Theimgcomponent override should suppress or coordinateonExpandwhen the image is rendered inside a link.✅ Resolved in a8dbe3e2ad7d14f3c882744fec435929a183bea3
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot).
Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.
Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit a8dbe3e2ad7d14f3c882744fec435929a183bea3. Configure [here](https://www.cursor.com/dashboard/bugbot).@@ -122,3 +127,4 @@122127 className?: string;123128 /** Treat single newlines as hard breaks — chat-style user input. */124129 lineBreaks?: boolean;130+ onImageExpand?: ((preview: ExpandedImagePreview) => void) | undefined;File image URLs sanitized away#
Medium Severity
Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit a8dbe3e2ad7d14f3c882744fec435929a183bea3. Configure [here](https://www.cursor.com/dashboard/bugbot).rehype-sanitizestripsfile://imagesrcattributes becauseCHAT_MARKDOWN_SANITIZE_SCHEMAonly permits thefileprotocol forhref. This preventsfile://workspace images from rendering, as the custom image component never receives the original source to process.@Aculnaj can you please take a look?
Approvability#
Verdict: Needs human review
This PR introduces a new feature (inline Markdown image previews) with multiple new components and UI capabilities. There is also an unresolved review comment identifying a potential bug where file:// URLs get sanitized, which could prevent workspace images from rendering correctly.
You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).When the T3 Code server runs on one device and the web client is opened on another
It doesn't matter if this is on one device/client or another. You can't just see any pics in the chat, which is very sad :( Just prompt:
Take the screenshot of https://example.com/ and paste it here
Note
🤖 GPT-5.6 Sol responding on behalf of Theo
Closing this PR after an automated pass over open pull requests. Workspace image rendering already shipped in #6433.
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.

Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
a4a354d3-5d8f-485e-b335-0c5e4ec3e64fYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.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.
❤️ Share