{
- if (container) {
- bindFunctions?.(container);
+ mermaid.initialize({
+ startOnLoad: false,
+ securityLevel: 'loose',
+ fontFamily: 'inherit',
+ themeCSS: 'margin: 1.5rem auto 0;',
+ theme: resolvedTheme === 'dark' ? 'dark' : 'default',
+ });
+
+ const { svg: rendered, bindFunctions } = await mermaid.render(
+ id.replaceAll(':', ''),
+ chart.replaceAll('\\n', '\n'),
+ );
+
+ if (!cancelled) {
+ setSvg(rendered);
+
+ if (containerRef.current) {
+ bindFunctions?.(containerRef.current);
}
- }}
- dangerouslySetInnerHTML={{ __html: svg }}
- />
- );
+ }
+ };
+
+ void render();
+
+ return () => {
+ cancelled = true;
+ };
+ }, [chart, id, resolvedTheme]);
+
+ if (!svg) {
+ return null;
+ }
+
+ return
;
};