Skip to content

fix(tui): harden Mermaid rendering limits - #42123

Merged
kitlangton merged 1 commit into
v2from
merman-review-hardening
Aug 12, 2026
Merged

kitlangton merged 1 commit into
v2from
merman-review-hardening

Conversation

@kitlangton

Copy link
Copy Markdown
Contributor

What

Keep terminal Mermaid rendering responsive and readable for oversized or malformed diagrams, and fold wide horizontal Markdown flowcharts before they are silently clipped.

Before / After

Before: a long malformed flowchart statement could spend seconds backtracking in edge parsing; near-million-cell canvases could allocate hundreds of megabytes; malformed chained sequence/state transitions became phantom endpoint names; a wide grapheme could extend beyond the canvas; and the four-stage LR diagram from the OpenCode session rendered wider than the message viewport.

After: pathological statements and oversized canvases fail through existing typed syntax/size errors, ambiguous chains are rejected, clipped wide graphemes are omitted, and Markdown flowcharts wider than 120 columns fold vertically by default.

How

  • packages/merman/src/flowchart/parser.ts bounds statement length before edge-operator matching.
  • packages/merman/src/core/canvas.ts lowers the eager canvas allocation budget and requires a full grapheme to fit before writing it.
  • Sequence and state parsers reject extra arrow operators embedded in endpoints.
  • packages/merman/src/markdown.ts passes a configurable layoutMaxWidth into flowchart layout, capped by the renderer width.
  • Adds focused regressions for each case, including the exact clipped LR diagram.

Scope

This does not replace the eager canvas with a sparse representation or rewrite flowchart edge parsing as a scanner. The conservative limits protect the TUI without expanding this fix into a storage/layout redesign.

Testing

  • cd packages/merman && bun run test (294 passing)
  • cd packages/merman && bun run typecheck
  • git diff --check

@kitlangton
kitlangton enabled auto-merge (squash) August 12, 2026 19:05
@kitlangton
kitlangton merged commit c6a86ac into v2 Aug 12, 2026
9 of 11 checks passed
@kitlangton
kitlangton deleted the merman-review-hardening branch August 12, 2026 19:06
jinhuang712 pushed a commit to jinhuang712/opencode that referenced this pull request Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant