@devries-cameron20 / composio Mirror · read-only / commits / 7a21d8433
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 22, 09:30 UTC

fix: re-render mermaid diagrams on theme toggle

Use MutationObserver to watch for dark/light mode changes and generate a unique ID per render to avoid mermaid's ID cache. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Sushmithamallesh committed Feb 11, 2026 at 17:47 UTC 7a21d84334eee1ba8f003326c4b5f1bfa18294f3
1 file changed +44 -26
docs/components/mermaid.tsx
+44 -26
@@ -8,38 +8,56 @@ function getCssVar(name: string): string {
8 }
9
10 export function Mermaid({ chart }: { chart: string }) {
11 - const id = useRef(`mermaid-${Math.random().toString(36).slice(2, 9)}`);
11 + const renderCount = useRef(0);
12 + const baseId = useRef(`mermaid-${Math.random().toString(36).slice(2, 9)}`);
13 const containerRef = useRef<HTMLDivElement>(null);
14 const [svg, setSvg] = useState('');
15
16 useEffect(() => {
16 - const isDark = document.documentElement.classList.contains('dark');
17 - const orange = getCssVar('--composio-orange');
18 - const bg = isDark ? getCssVar('--color-fd-muted') : getCssVar('--color-fd-card');
19 - const fg = getCssVar('--color-fd-foreground');
20 - const border = getCssVar('--color-fd-border');
21 -
22 - mermaid.initialize({
23 - startOnLoad: false,
24 - theme: 'base',
25 - themeVariables: {
26 - background: bg,
27 - primaryColor: bg,
28 - primaryBorderColor: orange,
29 - primaryTextColor: fg,
30 - lineColor: orange,
31 - secondaryColor: bg,
32 - tertiaryColor: bg,
33 - edgeLabelBackground: bg,
34 - clusterBkg: bg,
35 - clusterBorder: border,
36 - },
37 - fontFamily: 'inherit',
38 - });
17 + const renderDiagram = () => {
18 + const isDark = document.documentElement.classList.contains('dark');
19 + const orange = getCssVar('--composio-orange');
20 + const bg = isDark ? getCssVar('--color-fd-muted') : getCssVar('--color-fd-card');
21 + const fg = getCssVar('--color-fd-foreground');
22 + const border = getCssVar('--color-fd-border');
23 +
24 + mermaid.initialize({
25 + startOnLoad: false,
26 + theme: 'base',
27 + themeVariables: {
28 + background: bg,
29 + primaryColor: bg,
30 + primaryBorderColor: orange,
31 + primaryTextColor: fg,
32 + lineColor: orange,
33 + secondaryColor: bg,
34 + tertiaryColor: bg,
35 + edgeLabelBackground: bg,
36 + clusterBkg: bg,
37 + clusterBorder: border,
38 + },
39 + fontFamily: 'inherit',
40 + });
41 +
42 + const uniqueId = `${baseId.current}-${renderCount.current++}`;
43 + mermaid.render(uniqueId, chart).then((result) => {
44 + setSvg(result.svg);
45 + });
46 + };
47
40 - mermaid.render(id.current, chart).then((result) => {
41 - setSvg(result.svg);
48 + renderDiagram();
49 +
50 + const observer = new MutationObserver((mutations) => {
51 + for (const mutation of mutations) {
52 + if (mutation.attributeName === 'class') {
53 + renderDiagram();
54 + }
55 + }
56 });
57 +
58 + observer.observe(document.documentElement, { attributes: true });
59 +
60 + return () => observer.disconnect();
61 }, [chart]);
62
63 return (