fix(mermaid): render flowchart sources missing the graph TD declaration - #39
Merged
taekchef merged 3 commits intoAug 21, 2026
Merged
Conversation
Model-generated mermaid (chat assistants) frequently omits the mandatory
diagram-type declaration line - 'A[高帧率摄像头 120-240fps] --> B[...]' with
no leading 'graph TD' - so the kind whitelist rejects the source before
renderMermaid runs and the mermaid node falls back to the raw-source error
display.
Add ensureFlowchartKind (mermaid-safe.ts, pure): when the first token is not
an already-declared graph/flowchart kind but the body contains flowchart
edges ('-->', '==>', '-.->'; negative lookahead keeps sequence '-->>'
messages from matching), prepend 'graph TD'. renderMermaid (mermaid-core.ts)
wires it into the kind gate; declared kinds, sequence/gantt/pie bodies and
plain text pass through untouched - the diagram type is never guessed.
Adds 8 tests (21 -> 29 in genui-mermaid-safe) and rebuilds the lib artifacts
(lib/assets/mermaid.js, lib/client.js, lib/types) with a minimal diff.
The previously committed bundles were built against a drifted local toolchain, so CI's 'Verify lib matches src' gate failed. Rebuilt with 'pnpm install --frozen-lockfile' + 'pnpm run build' so the committed artifacts are byte-identical to CI's rebuild.
Collaborator
|
@passionjj 感谢这个修复 🙏 方向和实现都很好: CI 红的唯一原因是
CI 转绿后我就合并,感谢贡献 ✨ |
taekchef
added a commit
to jordanking211/dsh-awesome-genui
that referenced
this pull request
Aug 22, 2026
…o feat/echarts-support; lib to be rebuilt
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.
Problem
Model-generated mermaid (e.g. from chat assistants) frequently omits the mandatory diagram-type declaration line -
A[高帧率摄像头 120-240fps] --> B[...]with no leadinggraph TD. The kind whitelist inrenderMermaidrejects such sources before rendering ever runs, so the mermaid node falls back to the raw-source error display even though the body is a perfectly valid flowchart.Fix
src/client/mermaid-safe.ts- new pure functionensureFlowchartKind(code): when the first token is not an already-declaredgraph/flowchartkind but the body contains flowchart edges (-->,==>,-.->; negative lookahead keeps sequence-->>messages from matching), prependgraph TD. Everything else - declared kinds, sequence/gantt/pie bodies, plain text - passes through untouched: the diagram type is never guessed.src/client/mermaid-core.ts-renderMermaidwires it into the kind gate: undeclared flowchart bodies now render instead of throwing straight to the fallback; genuinely unclassifiable input still fails as before.src/client/mermaid-lazy.ts- re-export so the shared client bundle carries it.genui-mermaid-safe.spec.ts(21 -> 29, all green).lib/assets/mermaid.js,lib/client.js, two.d.ts) so the published bundle carries the fix.Verification
node --checkpasses on both bundles.Notes
[Unreleased].