fix(mermaid): suppress global error rendering

This commit is contained in:
zhangqianfeng committed 2026-08-23 01:50:07 +08:00
1 parent d9b8f15d9e
commit a75928daf1
2 files changed
+15 -1

No files matched your search

+4
View File
@@ -48,6 +48,10 @@ function configureMermaid(): void {
// forcing pure SVG text keeps labels visible and the HTML label channel // forcing pure SVG text keeps labels visible and the HTML label channel
// closed (strict already escapes label content). // closed (strict already escapes label content).
htmlLabels: false, htmlLabels: false,
// Mermaid 11 renders a large error SVG into document.body before rejecting
// invalid diagrams. The component already has its own error fallback, so
// suppress that global side effect to keep the DSH shell intact.
suppressErrorRendering: true,
theme: isDarkScheme() ? 'dark' : 'default', theme: isDarkScheme() ? 'dark' : 'default',
}) })
} }
+11 -1
View File
@@ -16,13 +16,14 @@ import { act } from 'react-dom/test-utils'
vi.mock('mermaid', () => ({ vi.mock('mermaid', () => ({
default: { default: {
initialize: () => {}, initialize: vi.fn(),
render: async () => ({ render: async () => ({
svg: '<svg xmlns="http://www.w3.org/2000/svg"><text>MOCK-DIAGRAM</text></svg>', svg: '<svg xmlns="http://www.w3.org/2000/svg"><text>MOCK-DIAGRAM</text></svg>',
}), }),
}, },
})) }))
import mermaid from 'mermaid'
import { MermaidMarkdown } from '../src/client/mermaid.tsx' import { MermaidMarkdown } from '../src/client/mermaid.tsx'
const codeLabels = { copyLabel: 'Copy', copiedLabel: 'Copied' } const codeLabels = { copyLabel: 'Copy', copiedLabel: 'Copied' }
@@ -56,6 +57,15 @@ describe('MermaidMarkdown', () => {
await unmount(root) await unmount(root)
}) })
it('suppresses Mermaid global error rendering', async () => {
vi.mocked(mermaid.initialize).mockClear()
const { root } = await renderMarkdown('```mermaid\ngraph TD\n A-->B\n```')
expect(mermaid.initialize).toHaveBeenCalledWith(expect.objectContaining({
suppressErrorRendering: true,
}))
await unmount(root)
})
it('resolves cross-fence reference-style links (single markdown parse)', async () => { it('resolves cross-fence reference-style links (single markdown parse)', async () => {
const text = [ const text = [
'[before][shared]', '[before][shared]',