Repository navigation
feat(web): mermaid diagrams in chat (upstream #15067) - #261
Merged
Merged
Conversation
Ports upstream pingdotgg#15067 by maria. Settled mermaid fences render as diagrams inside the fork's code block chrome, with a code/diagram toggle, copy, and click to expand into the image dialog. Mermaid and DOMPurify load lazily on first diagram, renders are serialized and cached, SVG output is sanitized, and invalid diagrams show the parser message above the highlighted source. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This was referenced Oct 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What users get
Mermaid code blocks in chat (assistant messages, plans, side questions, anywhere
ChatMarkdownrenders) now render as diagrams once the response finishes streaming. The block keeps its normal code block header with a new Show code / Show diagram toggle, copy still copies the source, and clicking the diagram opens it in the existing zoomable image dialog. Diagrams follow the light and dark theme. An invalid diagram shows the parser error above the normal highlighted code, so nothing is lost.How it was ported
Upstream pingdotgg#15067 (by maria), re-expressed against the fork's diverged
ChatMarkdown.tsx:apps/web/src/components/chat/MermaidDiagram.tsxcarries the upstream render queue, cache, strict Mermaid config, and DOMPurify SVG hardening.mermaidanddompurifyare both dynamically imported on first diagram, so neither lands in the main bundle (upstream imported DOMPurify statically).expandMediacontext, so the diagram portals the existingExpandedImageDialogitself and revokes its blob URL on close or unmount.MarkdownCodeBlockgains two optional props (leadingActions,canWrap), and the Shiki subtree is hoisted into a variable so both paths share it.No follow-up upstream mermaid commits exist after pingdotgg#15067.
Left out
third-party-licenses.config.json: the fork has no generated npm license notices.apps/web/THIRD_PARTY_NOTICES.mdonly covers vendored source.@pierre/diffs@1.5.2dist internals (newCodeViewSearchmodule, CodeView scroll and reveal hooks). The fork is on@pierre/diffs@1.3.0-beta.10, so porting it means rewriting a library patch against a different internal version. Skipped.Verification
tsgo --noEmit -p apps/web/tsconfig.json: cleanvp linton changed files: no errors. The 8no-unstable-nested-componentswarnings inChatMarkdown.tsxwere already on main.vp fmt: cleanvp test run apps/web/src/markdown-links.test.ts apps/web/src/components/chat/ExpandedImageDialog.test.tsx: 37 passedvp run check:avicode: passed.vp run test:avicode: 7/7 passed.vp run --filter @t3tools/web build: passed. Mermaid is code-split:mermaid.core35.9 kB (12.0 kB gzip),purify.es28.1 kB, and per-diagram chunks such assequenceDiagram116 kB,katex259 kB, andcytoscape436 kB, all loaded on demand. Mermaid and DOMPurify internals are absent from theindexchunk.🤖 Generated with Claude Code