feat(editor): render Mermaid diagrams in code blocks with live preview - #9787
feat(editor): render Mermaid diagrams in code blocks with live preview#9787Liewzheng wants to merge 2 commits into
Conversation
- New MermaidDiagram component: lazy dynamic import of mermaid, theme-aware rendering following the editor's data-theme attribute, debounced re-render on source/theme changes, graceful error state showing source + message - Code block NodeView renders the diagram below the editable code when language is mermaid - Slash commands: new Diagram item that inserts a mermaid code block - Pure helpers (isMermaidLanguage, getMermaidTheme, formatMermaidError) in @plane/utils with vitest coverage - i18n: slash_commands.diagram keys in editor.json for all locales (en and zh-CN translated, others fall back to English) - Styles for the mermaid container, loading and error states Note: committed with --no-verify because the pre-commit lint-staged oxfmt step was SIGKILLed by the environment (tmpfs/inode pressure in /tmp), not because of a formatting failure — oxfmt --check passes on all changed files.
◈ PR Lens
Architecture 8 components touched across 2 lanes. Inside the changed components — 1 viewComponent view — Editor Diagram Extensions Components and helpers that power Mermaid diagram insertion and live rendering in the editor. Data flow
Drill down
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
…errors (PLANE-7) The error branch unmounted the canvas div, leaving containerRef null on the next render pass — the effect bailed out before it could clear the error, so a diagram that failed once could never re-render until the whole code block was recreated.
Description
Renders Mermaid diagrams in the editor: a code block with language
mermaidgets a live diagram preview below the (still editable) code — GitHub/Notion-style UX. Works in work item descriptions, comments, and pages; read-only surfaces (peek overview, space pages) render automatically via the same node view.Implementation:
language-mermaid), so Markdown round-trip, HTML export and yjs collaboration are untouched; server-side nh3 sanitization already allowslanguage-*classes.mermaidis loaded via dynamicimport()only when a mermaid block is visible (~350KB gzip stays out of the main bundle; SSR-safe since node views are client-only).data-themeattribute + MutationObserver; render errors show source + parser message; source changes (including remote collaboration edits) re-render debounced at 400ms.isMermaidLanguage/getMermaidTheme/formatMermaidError) live in@plane/utilswith 10 unit tests.Note: the slash-menu label is hardcoded English like every other label in
command-items-list.tsx(the editor package has zero i18n wiring and is imported by the Node live server); i18n keys are staged ineditor.jsonfor a future wiring PR.Type of Change
Test Scenarios
check:typesfor editor/utils/i18n/web; builds for editor/utils; new vitest suite 10/10; lint clean on touched files.import("mermaid")external (code-split chunk, loaded on demand).References