Skip to content

fix(web): suppress Mermaid render error SVGs#813

Merged
tiann merged 2 commits into
tiann:mainfrom
swear01:fix/issue-785-mermaid-render-fallback
Jun 6, 2026
Merged

fix(web): suppress Mermaid render error SVGs#813
tiann merged 2 commits into
tiann:mainfrom
swear01:fix/issue-785-mermaid-render-fallback

Conversation

@swear01
Copy link
Copy Markdown
Contributor

@swear01 swear01 commented Jun 6, 2026

Closes #785

Summary

  • Suppress Mermaid's built-in error SVG rendering for invalid diagrams so failed Mermaid blocks do not inject the red "Syntax error in text" diagram into the page.
  • Pre-validate Mermaid source with mermaid.parse(..., { suppressErrors: true }); invalid syntax falls back to the source block without calling render.
  • Install a no-op Mermaid parse error handler to avoid global parse-error side effects.
  • Add tests for valid rendering, invalid syntax fallback, and render-failure fallback without Mermaid error SVG injection.

Notes

Test plan

  • bun typecheck
  • bun run test:cli — 93 files / 847 tests passed
  • bun run test:hub — 263 tests passed
  • bun run test:web — 89 files / 766 tests passed
  • bun run test:shared — 68 tests passed
  • bun run --cwd web test src/components/assistant-ui/mermaid-diagram.test.tsx — 3 tests passed
  • Manual verification: reproduced the original environment showing Mermaid error SVG while Markdown still rendered, then confirmed the fix prevents that error SVG path.

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Findings
No high-confidence issues found in the added or modified lines.

Summary
Review mode: initial
No correctness, security, regression, data-loss, performance, or maintainability issues found at >=80% confidence. Residual risk: this was a static review only; Mermaid behavior was checked against published Mermaid 11.14.0 declarations/source metadata, but browser rendering was not exercised.

Testing
Not run (automation)

HAPI Bot

@tiann tiann merged commit 66ba312 into tiann:main Jun 6, 2026
2 checks passed
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.

Mermaid 代码块图表渲染失败会导致页面崩溃

2 participants