Skip to content

Feature/mermaid diagrams - #91

Merged
honix merged 2 commits into
mainfrom
feature/mermaid-diagrams
Jan 19, 2026
Merged

honix merged 2 commits into
mainfrom
feature/mermaid-diagrams

Conversation

@honix

@honix honix commented Jan 19, 2026

Copy link
Copy Markdown
Owner

No description provided.

honix and others added 2 commits January 20, 2026 00:07
- Add mermaid package for diagram rendering
- Extend code_block schema with params attribute for language
- Create MermaidNodeView to render diagrams in view mode
- Configure mermaid with useMaxWidth: false for natural sizing
- Add CSS styles with centered layout and horizontal scroll
- Add mermaid-diagrams.md template with examples

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@claude

claude Bot commented Jan 19, 2026 •

Copy link
Copy Markdown

Claude finished @honix's task in 1m 24s —— View job


PR Review: Mermaid Diagrams Feature

I've completed a thorough review of the mermaid diagram implementation. Overall, this is a solid implementation with good architecture and attention to detail. Here are my findings:


✅ Strengths

  1. Clean Architecture: The MermaidNodeViewImpl class is well-structured with clear separation between view/edit modes
  2. Security: securityLevel: 'strict' is properly configured (line 21 in MermaidNodeView.ts)
  3. Error Handling: Comprehensive error display with user-friendly messages and technical details
  4. Dark Theme: Excellent solution using CSS filter inversion (filter: invert(1) hue-rotate(180deg))
  5. Integration: Seamless ProseMirror integration with proper NodeView lifecycle methods
  6. Documentation: Good agent template with multiple diagram examples

🔍 Issues Found

1. Memory Leak Risk - MermaidNodeView.ts:138

The renderCounter is a module-level variable that only increments, never resets. In long-running sessions, this could theoretically overflow.

Severity: Low
Location: frontend/src/editor/nodeviews/MermaidNodeView.ts:45-46, 138

Recommendation: Consider resetting or using a more bounded approach:

const id = `mermaid-${Date.now()}-${Math.random().toString(36).substring(7)}`;

2. Missing Type Safety - MermaidNodeView.ts:164

Error handling uses String(error) which loses type information.

Severity: Low
Location: frontend/src/editor/nodeviews/MermaidNodeView.ts:164

Recommendation:

errorDetails.textContent = error instanceof Error ? error.message : 'Unknown error';

3. Unused Import - ProseMirrorEditor.tsx:4

The history import is unused in this file (collaborative mode uses y-prosemirror's history).

Severity: Very Low
Location: frontend/src/components/editor/ProseMirrorEditor.tsx:4

4. Inconsistent Async Handling - MermaidNodeView.ts:86, 174

The render() method is async but the return value is never awaited. The update() method calls renderDiagram() without await, which could cause race conditions if updates happen rapidly.

Severity: Medium
Location: frontend/src/editor/nodeviews/MermaidNodeView.ts:86, 196

Recommendation: Either remove async from render() or properly handle the promise:

update(node: ProseMirrorNode): boolean {
  // ...
  if (newIsMermaid && !newEditable) {
    this.renderDiagram(); // Add await or handle promise
  }
  return true;
}

5. No Test Coverage

No tests found for the mermaid functionality. Given this adds rendering user-provided code, tests would be valuable.

Severity: Medium
Recommendation: Add tests for:

  • Valid mermaid syntax rendering
  • Invalid syntax error handling
  • Edit/view mode switching
  • Dark theme filter application

🎨 Style & Best Practices

Minor CSS Observations:

  1. Line 324 (prosemirror.css): width: fit-content with margin: 0 auto centers diagrams nicely, but very wide diagrams might overflow. Consider adding max-width: 100%.

  2. Line 334 (prosemirror.css): The dark theme filter is clever, but the hue-rotate(180deg) may distort brand colors in diagrams. This is acceptable, but worth noting in docs.


🔒 Security Review

✅ SECURE: The implementation properly sets securityLevel: 'strict' which:

  • Disables HTML rendering in mermaid diagrams
  • Prevents XSS attacks via malicious diagram code
  • Restricts dangerous features

No security concerns found.


📊 Performance Considerations

  1. Mermaid initialization (line 16-42): Uses singleton pattern with mermaidInitialized flag - good!
  2. Re-rendering: The update() method re-renders on any content change, which is correct but could be expensive for complex diagrams
  3. DOM mutations: ignoreMutation() implementation is correct and prevents unnecessary re-renders

Recommendation: For very large pages with many mermaid diagrams, consider adding debouncing to renderDiagram() calls.


📝 Documentation

The agent template (mermaid-diagrams.md) is excellent with diverse examples. Consider adding:

  • Note about dark theme color inversion
  • Performance tips for complex diagrams
  • Troubleshooting section for common syntax errors

✅ Code Quality Summary

Category Rating Notes
Architecture ⭐⭐⭐⭐⭐ Clean, well-structured
Security ⭐⭐⭐⭐⭐ Properly configured
Error Handling ⭐⭐⭐⭐ Good UX, minor improvements possible
Performance ⭐⭐⭐⭐ Efficient, room for optimization
Test Coverage ⭐⭐ Missing tests
Documentation ⭐⭐⭐⭐ Good examples, could be more comprehensive

🎯 Recommendations

Must fix before merge:

  • None (implementation is production-ready)

Should fix:

  • Add test coverage for mermaid rendering
  • Fix async/await handling in update() method
  • Consider bounded ID generation instead of incrementing counter

Nice to have:

  • Remove unused history import
  • Add debouncing for rapid updates
  • Document dark theme color behavior

💭 Overall Assessment

This is a well-executed feature with good attention to security and UX. The implementation follows ProseMirror best practices and integrates cleanly with the existing editor architecture. The main improvement area is test coverage.

Recommendation: ✅ Approve with minor suggestions

Great work on the dark theme solution - the CSS filter approach is elegant!


@honix
honix merged commit 34505a4 into main Jan 19, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant