Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
TypeScript agentic-aiagentsaiai-agentsaiagentsdeveloper-toolsfunction-callinggpt-4javascriptjsllmllmopsmcppythonremote-mcp-serverssetypescript
fix: re-render mermaid diagrams on theme toggle
Sushmithamallesh7a21d84334ee
diff --git a/docs/components/mermaid.tsx b/docs/components/mermaid.tsxindex c0862ce20..6f0cd4fd0 100644--- a/docs/components/mermaid.tsx+++ b/docs/components/mermaid.tsx@@ -8,38 +8,56 @@ function getCssVar(name: string): string {}export function Mermaid({ chart }: { chart: string }) {- const id = useRef(`mermaid-${Math.random().toString(36).slice(2, 9)}`);+ const renderCount = useRef(0);+ const baseId = useRef(`mermaid-${Math.random().toString(36).slice(2, 9)}`);const containerRef = useRef<HTMLDivElement>(null);const [svg, setSvg] = useState('');useEffect(() => {- const isDark = document.documentElement.classList.contains('dark');- const orange = getCssVar('--composio-orange');- const bg = isDark ? getCssVar('--color-fd-muted') : getCssVar('--color-fd-card');- const fg = getCssVar('--color-fd-foreground');- const border = getCssVar('--color-fd-border');-- mermaid.initialize({- startOnLoad: false,- theme: 'base',- themeVariables: {- background: bg,- primaryColor: bg,- primaryBorderColor: orange,- primaryTextColor: fg,- lineColor: orange,- secondaryColor: bg,- tertiaryColor: bg,- edgeLabelBackground: bg,- clusterBkg: bg,- clusterBorder: border,- },- fontFamily: 'inherit',- });+ const renderDiagram = () => {+ const isDark = document.documentElement.classList.contains('dark');+ const orange = getCssVar('--composio-orange');+ const bg = isDark ? getCssVar('--color-fd-muted') : getCssVar('--color-fd-card');+ const fg = getCssVar('--color-fd-foreground');+ const border = getCssVar('--color-fd-border');++ mermaid.initialize({+ startOnLoad: false,+ theme: 'base',+ themeVariables: {+ background: bg,+ primaryColor: bg,+ primaryBorderColor: orange,+ primaryTextColor: fg,+ lineColor: orange,+ secondaryColor: bg,+ tertiaryColor: bg,+ edgeLabelBackground: bg,+ clusterBkg: bg,+ clusterBorder: border,+ },+ fontFamily: 'inherit',+ });++ const uniqueId = `${baseId.current}-${renderCount.current++}`;+ mermaid.render(uniqueId, chart).then((result) => {+ setSvg(result.svg);+ });+ };- mermaid.render(id.current, chart).then((result) => {- setSvg(result.svg);+ renderDiagram();++ const observer = new MutationObserver((mutations) => {+ for (const mutation of mutations) {+ if (mutation.attributeName === 'class') {+ renderDiagram();+ }+ }});++ observer.observe(document.documentElement, { attributes: true });++ return () => observer.disconnect();}, [chart]);return (