Skip to content

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

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

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 4, 2026
sandscooling pushed a commit to sandscooling/t3code that referenced this pull request Aug 4, 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>
sandscooling pushed a commit to sandscooling/t3code that referenced this pull request Aug 6, 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 98ed283)
sandscooling pushed a commit to sandscooling/t3code that referenced this pull request Aug 7, 2026
Upstream be1a836, 54 commits. Both carried pull requests (pingdotgg#4989 mermaid,
pingdotgg#5114 inline images) are still open upstream, so this is a plain merge rather
than the reset-and-replay that a landed pull request forces.

Five files conflicted across eight hunks:

ActivityPayloadProjection.ts: dropStaleRateLimitActivities (local) and
dropSupersededToolUpdatedActivities (upstream b7d1981) were inserted at the
same point. Independent filters, so both are kept and composed.

ClaudeAdapter.ts: upstream pingdotgg#5557 fixes the same interrupt bug as the local
4429c29, and fixes it better. It reads the CLI's own terminal_reason field
rather than tracking an interrupt flag across the session, and separately
filters [ede_diagnostic] strings out of the error banner. Upstream's version
is taken and all nine pieces of the local fix are reverted, along with the two
tests that covered the reverted implementation. The third test in that group,
which asserts a genuine failure still reports as an error, passes against
upstream's fix and is kept. Local plan-usage work in the same file is
untouched.

ChatView.tsx: the local turnInterruptionNotice and upstream's new turnPlans
argument collided on one call. deriveTimelineEntries takes both, so both are
passed.

ComposerPendingUserInputPanel.tsx: local collapsible chrome versus upstream's
theme library restyle (85b1734). Upstream's change to this file is five
className token swaps and nothing structural, so the local structure is kept
and the five swaps applied to it.

pnpm-lock.yaml: regenerated on upstream's lockfile; mermaid re-added.

Verified: web 1983 tests pass, web and server typechecks clean. The server
suite fails 30 files / 116 tests on Windows, which is pre-existing and not
from this merge. Every failing file was compared against the pre-merge tree:
27 fail identically, 2 more outside src/ fail identically, one test in
ProviderRegistry that failed before now passes, and the only new failures are
3 brand new upstream tests in cloud/http.test.ts that hit a pre-existing
Windows incompatibility (fsync on a directory handle in serviceLauncher.ts,
from upstream pingdotgg#5181, already present in the base). Upstream CI runs Ubuntu and
macOS only, so this suite has never been green on Windows.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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

1 participant