Skip to content

Conversation

@kookyleo
Copy link

@kookyleo kookyleo commented Oct 4, 2025

Summary

Refactors Mermaid integration for stability on pages with many diagrams and better debuggability.

Key changes

  • Centralize Mermaid script loading in layout; remove per-snippet init
  • Add mermaid-init.js to:
    • Compute theme (auto/light/dark) and init once (idempotent)
    • Render all .mermaid nodes sequentially to avoid race/global state issues
    • Use mermaid.render (v10) or mermaidAPI.render (v8/v9) with broad compatibility
    • Preserve original code (data-code) for safe re-rendering
    • Surface parse/render errors inline (.mermaid-error) and in console
  • Add github-mermaid.css for clear error styles (light/dark)

Why

Previously, multi-graph pages could randomly leave some diagrams blank with no console error due to concurrent rendering and version-specific API behavior. Centralizing init and sequential rendering makes behavior predictable and debuggable.

Notes

  • Init is idempotent; theme changes re-init gently
  • securityLevel: 'loose' for local use; logLevel: 'error'

Future (optional)

  • Lazy render with IntersectionObserver for large docs
  • Add debug switch to control console verbosity

…optimized layout

- Add global font support for Chinese, Japanese, Korean, Arabic, Hindi and other major languages
- Optimize print margins with binding-friendly layout (left 2cm, others 1.5cm)
- Improve print typography with proper page breaks and clean backgrounds
- Preserve text colors while removing background interference
- Update README with detailed print features documentation
- Add new --no-reload flag to disable WebSocket-based auto-refresh
- Provide clear user feedback about current refresh mode
- Maintain backward compatibility with auto-reload enabled by default
- Include WebSocket CORS fix when reload is enabled for development use
- Update README with usage example for stable editing workflow
… and robust error display

- Move Mermaid script loading to layout template; remove per-snippet init
- Add mermaid-init.js to compute theme, init once, and render all diagrams
- Render diagrams sequentially to avoid race conditions on multi-graph pages
- Use mermaid.render/mermaidAPI.render with broad version compatibility
- Surface parse/render errors both inline (.mermaid-error) and in console
- Preserve original code in data-code for safe re-rendering
- Add github-mermaid.css for clear error styles and dark mode support
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