fix(mermaid): one more case of "Matrix is not inversible"

This commit is contained in:
Elian Doran 2025-11-25 08:55:17 +02:00
parent c16f9af6a9
commit 219753039d
No known key found for this signature in database

View File

@ -136,12 +136,16 @@ function useResizer(containerRef: RefObject<HTMLDivElement>, noteId: string, svg
const lastPanZoom = useRef<{ pan: SvgPanZoom.Point, zoom: number }>(); const lastPanZoom = useRef<{ pan: SvgPanZoom.Point, zoom: number }>();
const lastNoteId = useRef<string>(); const lastNoteId = useRef<string>();
const zoomRef = useRef<SvgPanZoom.Instance>(); const zoomRef = useRef<SvgPanZoom.Instance>();
const width = useElementSize(containerRef);
// Set up pan & zoom. // Set up pan & zoom.
useEffect(() => { useEffect(() => {
if (zoomRef.current || width?.width === 0) return;
const shouldPreservePanZoom = (lastNoteId.current === noteId); const shouldPreservePanZoom = (lastNoteId.current === noteId);
const svgEl = containerRef.current?.querySelector("svg"); const svgEl = containerRef.current?.querySelector("svg");
if (!svgEl) return; if (!svgEl) return;
const zoomInstance = svgPanZoom(svgEl, { const zoomInstance = svgPanZoom(svgEl, {
zoomEnabled: true, zoomEnabled: true,
controlIconsEnabled: false controlIconsEnabled: false
@ -163,14 +167,14 @@ function useResizer(containerRef: RefObject<HTMLDivElement>, noteId: string, svg
pan: zoomInstance.getPan(), pan: zoomInstance.getPan(),
zoom: zoomInstance.getZoom() zoom: zoomInstance.getZoom()
} }
zoomRef.current = undefined;
zoomInstance.destroy(); zoomInstance.destroy();
}; };
}, [ svg ]); }, [ svg, width ]);
// React to container changes. // React to container changes.
const width = useElementSize(containerRef);
useEffect(() => { useEffect(() => {
if (!zoomRef.current || (width?.width ?? 0) === 0) return; if (!zoomRef.current || (width?.width ?? 0) < 1) return;
zoomRef.current.resize().fit().center(); zoomRef.current.resize().fit().center();
}, [ width ]); }, [ width ]);