feat(studio): render Mermaid in Markdown previews - #4459
Open
ranxi2001 wants to merge 2 commits into
Open
Conversation
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.
Description
Web Studio currently renders fenced
mermaidblocks in resource Markdown files as syntax-highlighted source. This change detects those blocks at React Markdown's component boundary and renders them with the official Streamdown Mermaid plugin.The diagram renderer is lazy-loaded only when a Mermaid fence is present. It follows the current light or dark application theme, localizes its loading and error states, preserves parser diagnostics and source on failure, and keeps wide diagrams readable inside a contained horizontal scroller.
Ordinary Markdown files keep the existing React Markdown path, including internal resource links, images, raw HTML sanitization, and non-Mermaid code highlighting.
Human Involvement
Related Issue
Fixes #4453
Type of Change
Changes Made
@streamdown/mermaidrenderer behind a lazy component;code.language-mermaidblocks using the current application theme and localized preview states;Testing
Local checks:
npm cinpm test -- --maxWorkers=1(57 files, 219 tests passed)npm test -- src/routes/resources/-components/mermaid-diagram.test.tsx src/routes/resources/-components/file-preview.test.tsx src/routes/resources/-components/file-preview-html.test.tsx --maxWorkers=1(3 files, 12 tests passed)npm run buildgit diff --checkA real Mermaid parser test renders the issue's flowchart into SVG under JSDOM; the test only supplies the SVG
getBBoxAPI that JSDOM does not implement. The ordinary file-preview production chunk remains 54.54 kB (18.76 kB gzip), and Mermaid remains lazy-loaded in separate chunks.Full
npx tsc --noEmitstill reports the repository's existing diagnostics, with none in the changedfile-previewormermaid-diagramfiles. Vite retains its general warning for chunks over 500 kB. Repository-wide lint and format checks also remain red in unchanged files outside this PR.Checklist
Screenshots (if applicable)
Light theme
Dark theme
The captures cover the issue chart, a wide flowchart, and localized invalid-source handling.
Additional Notes
The plugin's default Mermaid configuration uses
securityLevel: "strict"and suppresses Mermaid's own error SVG. The resource preview owns its visible loading and error states; optional copy, download, fullscreen, and pan-zoom controls are outside this issue's rendering scope. Session messages, directory summaries, and JSONL previews are intentionally unchanged.