Repository navigation
fix(tui): harden Mermaid rendering limits - #42123
Merged
Merged
Conversation
kitlangton
enabled auto-merge (squash)
August 12, 2026 19:05
jinhuang712
pushed a commit
to jinhuang712/opencode
that referenced
this pull request
Sep 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.tsbounds statement length before edge-operator matching.packages/merman/src/core/canvas.tslowers the eager canvas allocation budget and requires a full grapheme to fit before writing it.packages/merman/src/markdown.tspasses a configurablelayoutMaxWidthinto flowchart layout, capped by the renderer width.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(294passing)cd packages/merman && bun run typecheckgit diff --check