You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
@streamdown/mermaid: a hook to transform the source before render #719
LLM-written Mermaid sometimes has a small syntax error we could fix without losing content, like an unquoted ( in a flowchart label or a quoted state name used as a transition endpoint. We want to fix the source only when Mermaid fails to parse it, then render again.
There's no seam for that today. createMermaidPlugin only takes { config } and hands the fence body straight to render, so the only way in is to wrap the plugin's render. That depends on the shape of MermaidInstance and changes every caller of render, export included. errorComponent only fires on failure, so a host also can't tell when a render succeeded.
Proposal:
interfaceMermaidPluginOptions{config?: MermaidConfig;/** Runs on the fence body before every render, including export. Throwing falls back to the original source. */transform?: (source: string,ctx: {isIncomplete: boolean})=>string|Promise<string>;}interfaceMermaidOptions{config?: MermaidConfig;errorComponent?: React.ComponentType<MermaidErrorComponentProps>;/** Fires once per closed fence when its final render settles. */onRenderSettled?: (result: {chart: string;renderedSource: string;ok: boolean;error?: Error})=>void;}
errorComponent would keep getting the original chart, so the error UI sees what the model wrote. With #668, onRenderSettled only fires after the fence closes, so it never reports a partial chart.
Related: #490 (host callbacks on MermaidOptions). I can put up a PR if this shape works.
Looked into this as a possible external contribution and I'm going to leave it alone. Findings:
This adds two public API surfaces: transform on createMermaidPlugin and onRenderSettled on MermaidOptions. No maintainer has weighed in yet, so the shape (async transform, ctx.isIncomplete, fall back to the original source on throw, once-per-closed-fence settle semantics) is unconfirmed.
The issue author has offered to send the PR, and they have the most context on the use case.
Suggestion: a maintainer should first agree on the API shape, ideally with transform and onRenderSettled split into separate changes. After that, @aryakapoor's PR offer seems like the best route.
Activity
sleitor commentedon Nov 13, 2026
Looked into this as a possible external contribution and I'm going to leave it alone. Findings:
transformoncreateMermaidPluginandonRenderSettledonMermaidOptions. No maintainer has weighed in yet, so the shape (async transform,ctx.isIncomplete, fall back to the original source on throw, once-per-closed-fence settle semantics) is unconfirmed.onRenderSettleddepends on fix(mermaid): stop showing errors for partial charts while streaming #668 and overlaps with Host-integrated Mermaid download and fullscreen hooks #490 (host callbacks onMermaidOptions), so it should probably be designed together with that.Suggestion: a maintainer should first agree on the API shape, ideally with
transformandonRenderSettledsplit into separate changes. After that, @aryakapoor's PR offer seems like the best route.