fix: clean up mermaid diagram rendering — separate dangerouslySetInnerHTML from children

This commit is contained in:
Vectry
2026-02-09 18:55:15 +00:00
parent dd03d86642
commit a49f05e8df

View File

@@ -9,7 +9,6 @@ interface MermaidDiagramProps {
} }
export function MermaidDiagram({ chart }: MermaidDiagramProps) { export function MermaidDiagram({ chart }: MermaidDiagramProps) {
const containerRef = useRef<HTMLDivElement>(null);
const [error, setError] = useState<string | null>(null); const [error, setError] = useState<string | null>(null);
const [isReady, setIsReady] = useState(false); const [isReady, setIsReady] = useState(false);
const [svgHtml, setSvgHtml] = useState<string>(""); const [svgHtml, setSvgHtml] = useState<string>("");
@@ -184,6 +183,7 @@ export function MermaidDiagram({ chart }: MermaidDiagramProps) {
onMouseLeave={handleMouseUp} onMouseLeave={handleMouseUp}
style={fullHeight ? { height: "100%" } : { minHeight: "100px" }} style={fullHeight ? { height: "100%" } : { minHeight: "100px" }}
> >
{svgHtml ? (
<div <div
className="mermaid-diagram flex items-center justify-center" className="mermaid-diagram flex items-center justify-center"
style={{ style={{
@@ -192,14 +192,20 @@ export function MermaidDiagram({ chart }: MermaidDiagramProps) {
transition: isPanning ? "none" : "transform 0.15s ease-out", transition: isPanning ? "none" : "transform 0.15s ease-out",
minHeight: fullHeight ? "100%" : "100px", minHeight: fullHeight ? "100%" : "100px",
}} }}
dangerouslySetInnerHTML={svgHtml ? { __html: svgHtml } : undefined} dangerouslySetInnerHTML={{ __html: svgHtml }}
/>
) : (
<div
className="mermaid-diagram flex items-center justify-center"
style={{ minHeight: fullHeight ? "100%" : "100px" }}
> >
{!svgHtml && !isReady && ( {!isReady && (
<div className="flex items-center justify-center py-8"> <div className="flex items-center justify-center py-8">
<div className="w-6 h-6 border-2 border-blue-500/30 border-t-blue-500 rounded-full animate-spin" /> <div className="w-6 h-6 border-2 border-blue-500/30 border-t-blue-500 rounded-full animate-spin" />
</div> </div>
)} )}
</div> </div>
)}
</div> </div>
); );