Skip to content

feat(web): render Mermaid diagrams in markdown - #4989

Closed
jdalmeida wants to merge 3 commits into
pingdotgg:mainfrom
jdalmeida:agent/add-mermaid-markdown-support
Closed

feat(web): render Mermaid diagrams in markdown#4989
jdalmeida wants to merge 3 commits into
pingdotgg:mainfrom
jdalmeida:agent/add-mermaid-markdown-support

Conversation

@jdalmeida

@jdalmeida jdalmeida commented Jul 30, 2026

Copy link
Copy Markdown

What Changed

T3 Code now renders fenced Mermaid diagrams in chat messages and rendered Markdown file previews.

The diagram viewport supports pointer controls, keyboard controls, bounded pan, 50–300 percent zoom, and a reset action.

Why

Markdown diagrams appeared as source code. This made agent plans and architecture notes harder to read.

A stable Markdown component prevents diagram flicker when thread data changes. The viewport limits zoom and pan positions.

Fixes #4571

UI Changes

Before

Mermaid source rendered as code

After

Mermaid diagram rendered in a clean Codex thread

Interaction

Watch the zoom, pan, and reset controls

Checklist

  • This PR is focused on Mermaid rendering.
  • I explained what changed and why.
  • I included before and after images.
  • I included a video for the zoom and pan controls.

About 790 changed lines come from the generated lockfile update for Mermaid.

Validation

  • pnpm exec vp test run apps/web/src/components/MermaidDiagram.test.ts
  • pnpm exec vp lint apps/web/src/components/MermaidDiagram.tsx apps/web/src/components/MermaidDiagram.test.ts apps/web/src/components/ChatMarkdown.tsx apps/web/src/components/FileMarkdownViewer.tsx
  • pnpm --filter @t3tools/web typecheck
  • pnpm --filter @t3tools/web build
  • Local web test with an isolated T3 home and one new GPT-5.6-Sol thread.

Model: GPT-5.6 Codex

Harness: T3 Code Codex harness

Note

Render Mermaid diagrams in chat markdown with pan/zoom support

  • Adds a MermaidDiagram component (MermaidDiagram.tsx) that renders mermaid code fences as interactive diagrams with toolbar controls for zoom in/out and reset.
  • Diagrams render in strict security mode, respect the current light/dark theme, and serialize renders via a global queue to avoid concurrent conflicts.
  • Introduces MarkdownRenderContext in ChatMarkdown.tsx to pass diffThemeName, isStreaming, and resolvedTheme to child renderers without prop drilling.
  • Mermaid code fences are only rendered as diagrams when not streaming; during streaming they fall back to standard Shiki-highlighted code blocks.
  • Risk: adds the mermaid package (~11.x) as a dependency, which is dynamically imported at render time.

Macroscope summarized 22a0072.

@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e329852a-a42a-4626-8000-9578b88debfa

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:XXL 1,000+ changed lines (additions + deletions). labels Jul 30, 2026
Comment thread apps/web/src/index.css Outdated
@jdalmeida
jdalmeida marked this pull request as ready for review July 30, 2026 14:04
@macroscopeapp

macroscopeapp Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Needs human review

This PR introduces a new feature with ~400 lines of new component code for rendering Mermaid diagrams with interactive pan/zoom controls. New user-facing capabilities with substantial new logic warrant human review.

You can customize Macroscope's approvability policy. Learn more.

sandscooling pushed a commit to sandscooling/t3code that referenced this pull request Aug 20, 2026
sandscooling pushed a commit to sandscooling/t3code that referenced this pull request Aug 20, 2026
PR pingdotgg#4989 was based on code predating pingdotgg#5301, so its Mermaid container
reintroduced the bordered/rounded/muted frame that pingdotgg#5301 had just removed
from code blocks. Diagrams rendered with a heavier frame than the code
fences beside them.

Follow pingdotgg#5301's structure rather than only dropping the border: the frame
lives in Tailwind classes on the element, and the stylesheet keeps just
margin, overflow, and radius.

- .chat-markdown-mermaid: drop hardcoded border, 0.75rem radius, and
  muted background; use border-radius: var(--radius)
- MermaidDiagram container: adopt the same class string MarkdownCodeBlock
  uses (border-border/70, bg-secondary, dark variants)
- toolbar: drop border-bottom and muted background; match the code block
  header's padding and color-mix(foreground 72%) text
- toolbar buttons: add chat-markdown-chrome-action so hover and pressed
  states track the code block controls

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 98ed283bbff799e6721ddb0730f5e7e771232848)
(cherry picked from commit 1c4035e46136ffb224740ea35ad7c192c33e5824)
(cherry picked from commit 35e5d4569bda9c36627df15b9102e43fc5084781)
sandscooling pushed a commit to sandscooling/t3code that referenced this pull request Aug 20, 2026
Both go in the Fixes table ahead of the build, so the fork overview ships
current. No change to the carried pull requests: pingdotgg#4989 and pingdotgg#5114 are both still
open upstream as of today, and pingdotgg#5114's head is still the pinned b9f2090.

Written by Claude Opus 5 in T3 Code.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@t3dotgg

t3dotgg commented Aug 28, 2026

Copy link
Copy Markdown
Member

Note

🤖 GPT-5.6 Sol responding on behalf of Theo

We're closing this PR as we clean up the T3 Code backlog. Thank you for taking the time to put this together.

#6191 is the smaller and safer Mermaid implementation. It lazy-loads Mermaid, uses strict security mode, preserves source text, handles failures, and covers shared Markdown views without this branch's extra pan and zoom code.

If you believe we closed this in error, please reopen the PR and leave a comment explaining what we missed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL 1,000+ changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: mermaid render support within the markdown render view

2 participants