diff --git a/packages/ui/src/components/Mermaid/Mermaid.tsx b/packages/ui/src/components/Mermaid/Mermaid.tsx
index 010281257c7..17806ed1f16 100644
--- a/packages/ui/src/components/Mermaid/Mermaid.tsx
+++ b/packages/ui/src/components/Mermaid/Mermaid.tsx
@@ -243,12 +243,36 @@ export function Mermaid({ chart, className, zoomable = true }: MermaidProps) {
)
if (zoomable) {
- // Convert SVG to data URL for react-medium-image-zoom compatibility
- const svgDataUrl = `data:image/svg+xml;base64,${btoa(unescape(encodeURIComponent(svg)))}`
+ // react-medium-image-zoom requires . To zoom the container WITH the diagram,
+ // we bake the container (background + border) into the SVG itself.
+ const tempDiv = document.createElement('div')
+ tempDiv.innerHTML = svg
+ const svgEl = tempDiv.querySelector('svg')
+ const svgWidth = parseInt(svgEl?.getAttribute('width') || '400')
+ const svgHeight = parseInt(svgEl?.getAttribute('height') || '300')
+
+ const padding = 24
+ const totalWidth = svgWidth + padding * 2
+ const totalHeight = svgHeight + padding * 2
+ const bgColor = isDark ? '#171717' : '#ffffff'
+ const borderColor = isDark ? '#333333' : '#e5e5e5'
+
+ // SVG with background rect (including border stroke) and mermaid diagram inside
+ const wrappedSvg = ``
+
+ const dataUrl = `data:image/svg+xml,${encodeURIComponent(wrappedSvg)}`
+
return (
-