Skip to content

Mermaid: comment on parts of the rendered diagram #862

Open

Description

@tomasz-tomczyk

Context

User request: comment on parts of a rendered Mermaid diagram (not only the fence as a whole).

Today:

  • A Mermaid fence is one line-block covering the entire fence (crit-line-blocks.js / document-renderer.js: cssClass: "mermaid-block").
  • Reviewers can already leave a line-range comment on that block (or on source if they switch mental model), but there is no way to click a node/edge in the SVG and attach feedback to that part.
  • Product copy already positions “comment on Mermaid source” as the intended loop — agents need source lines, not pixel coordinates.

Ask

From the rendered diagram, click a meaningful part (node, participant, edge/label where practical) and open a normal Crit comment that points the agent at the right Mermaid source.

Ideal UX:

  1. Hover highlights the target element in the SVG.
  2. Click opens the standard comment form.
  3. Comment stores a durable pointer back to source (line range + quote of the Mermaid token).
  4. Optional: small marker on diagram elements that already have comments.

Feasibility

Yes, with a scoped approach — do not invent freeform diagram pins.

Approach Verdict
A. Map SVG element → source lines (recommended) Feasible. Mermaid SVG nodes carry ids/labels derived from source (flowchart-Foo-…, edge labels, etc.). Resolve clicked element → node/edge id or label text → search within the fence’s data-mermaid-src / source lines → set start_line/end_line + quote like a normal comment. Agent sees actionable Mermaid syntax.
B. Freeform x/y pin on the SVG Fragile. Re-layout on theme, zoom, viewport, or Mermaid version breaks anchors. Avoid as primary model.
C. New DOMAnchor-like diagram schema Possible later, but overkill for v1 and weaker for agents than source lines.

Live-mode DOMAnchor is a precedent for non-line pins, but Mermaid review comments should stay source-anchored so crit comment / agent fix loops keep working.

Hard parts (call out in design)

  • Diagram-type coverage differs: flowcharts / state / class are easiest; sequence (participants + messages), ER, Gantt need per-type mapping.
  • Mermaid’s generated SVG ids are not a stable public API — prefer matching on node id / label text from source, with SVG id as a hint.
  • Whole-block click vs part-click: don’t break “comment on entire diagram”; use element hit-testing and fall back to whole-block when click is on background.
  • Re-render / live reload: remount markers from comments whose quote/anchor still match source.

Proposed v1

  1. Flowcharts first (highest traffic for architecture reviews).
  2. Click node → find source line(s) containing that node id → open comment with quote = that line (or node declaration).
  3. Show hover outline on commentable SVG elements; cursor affordance.
  4. If mapping fails → fall back to whole-fence comment (current behavior) rather than failing silently.
  5. Parity in crit/web and crit-web.

Stretch / later

  • Edges and edge labels
  • Sequence diagram messages / participants
  • Markers on diagram for existing threads
  • Combine with fullscreen zoom overlay (see sibling issue) so part-comment works while zoomed

Acceptance

  • Clicking a flowchart node opens a comment anchored to the corresponding Mermaid source line(s), with quote set
  • Agent-facing output includes those line numbers / quote (same as normal comments)
  • Background / unmapped click still allows whole-block comment
  • Theme change / re-render does not orphan comments that still match source
  • Local + hosted parity

Related

  • Sibling: Mermaid fullscreen pan/zoom (GitHub-style)
  • Existing: whole-block Mermaid commenting + feature page copy under /features/mermaid-diagrams

Activity

  1. tomasz-tomczyk commented on Aug 26, 2026

    @tomasz-tomczyk
    OwnerAuthor

    Sibling (fullscreen pan/zoom): #861

  2. bewa1t commented on Sep 5, 2026

    @bewa1t
    Contributor

    I beilive it's worth adding comments over selected text rather than by line also falls in the same bucket, can these 2 review improvements go together as one MR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions