@devries-cameron20 / composio-1 / commits / a72dc9fb3
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.

docs: disable mermaid zoom on mobile, fix initial render race

- Skip Zoom wrapper below 768px (pinch-to-zoom works natively) - Defer Zoom mount until SVG is ready to fix first-load detection Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Sushmitha Mallesh committed Mar 3, 2026 at 22:49 UTC a72dc9fb3792125adc43bde5dfe0b9eb1214555b
1 file changed +28 -15
docs/components/mermaid.tsx
+28 -15
@@ -1,21 +1,32 @@
1 'use client';
2
3 -import { useEffect, useRef, useState } from 'react';
3 +import { useEffect, useRef, useState, useSyncExternalStore } from 'react';
4 import mermaid from 'mermaid';
5 import Zoom from 'react-medium-image-zoom';
6 import 'react-medium-image-zoom/dist/styles.css';
7
8 -function getCssVar(name: string): string {
9 - return getComputedStyle(document.documentElement).getPropertyValue(name).trim();
8 +const MOBILE_BREAKPOINT = 768;
9 +
10 +function useIsMobile() {
11 + return useSyncExternalStore(
12 + (cb) => {
13 + const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
14 + mql.addEventListener('change', cb);
15 + return () => mql.removeEventListener('change', cb);
16 + },
17 + () => window.innerWidth < MOBILE_BREAKPOINT,
18 + () => false,
19 + );
20 }
21
12 -function svgToDataUrl(svg: string): string {
13 - return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg)}`;
22 +function getCssVar(name: string): string {
23 + return getComputedStyle(document.documentElement).getPropertyValue(name).trim();
24 }
25
26 export function Mermaid({ chart }: { chart: string }) {
27 const renderCount = useRef(0);
28 const baseId = useRef(`mermaid-${Math.random().toString(36).slice(2, 9)}`);
29 + const containerRef = useRef<HTMLDivElement>(null);
30 const [svg, setSvg] = useState('');
31
32 useEffect(() => {
@@ -65,17 +76,19 @@ export function Mermaid({ chart }: { chart: string }) {
76 return () => observer.disconnect();
77 }, [chart]);
78
79 + const isMobile = useIsMobile();
80 +
81 if (!svg) return null;
82
70 - return (
71 - <div className="my-4 max-w-full mx-auto">
72 - <Zoom>
73 - <img
74 - src={svgToDataUrl(svg)}
75 - alt="Mermaid diagram"
76 - className="mx-auto"
77 - />
78 - </Zoom>
79 - </div>
83 + const diagram = (
84 + <div
85 + ref={containerRef}
86 + className="my-4 overflow-x-auto max-w-full mx-auto [&>svg]:mx-auto"
87 + dangerouslySetInnerHTML={{ __html: svg }}
88 + />
89 );
90 +
91 + if (isMobile) return diagram;
92 +
93 + return <Zoom wrapElement="div">{diagram}</Zoom>;
94 }