Merge pull request #19 from outis1one/claude/automate-sam-download-mzpRs

Fix onZoomChange reference error - use ref to avoid closure issues
This commit is contained in:
outis1one
2026-01-26 00:19:36 -05:00
committed by GitHub
+10 -5
View File
@@ -16,9 +16,12 @@ const ImageCanvas = forwardRef(({
const [currentSelection, setCurrentSelection] = useState(null); const [currentSelection, setCurrentSelection] = useState(null);
const currentSelectionRef = useRef(null); const currentSelectionRef = useRef(null);
const lassoPoints = useRef([]); const lassoPoints = useRef([]);
const isDrawingRef = useRef(false); const onZoomChangeRef = useRef(onZoomChange);
const imageRef = useRef(null);
const baseScaleRef = useRef(1); // Keep ref updated
useEffect(() => {
onZoomChangeRef.current = onZoomChange;
}, [onZoomChange]);
// Expose methods to parent // Expose methods to parent
useImperativeHandle(ref, () => ({ useImperativeHandle(ref, () => ({
@@ -83,7 +86,9 @@ const ImageCanvas = forwardRef(({
canvas.zoomToPoint({ x: pointer.x, y: pointer.y }, newZoom); canvas.zoomToPoint({ x: pointer.x, y: pointer.y }, newZoom);
setCurrentZoom(newZoom); setCurrentZoom(newZoom);
onZoomChange?.(newZoom); if (onZoomChangeRef.current) {
onZoomChangeRef.current(newZoom);
}
}; };
canvas.on('mouse:wheel', handleWheel); canvas.on('mouse:wheel', handleWheel);
@@ -93,7 +98,7 @@ const ImageCanvas = forwardRef(({
canvas.off('mouse:wheel', handleWheel); canvas.off('mouse:wheel', handleWheel);
canvas.dispose(); canvas.dispose();
}; };
}, [onZoomChange]); }, []); // Empty dependency array - only run once on mount
// Center and scale image // Center and scale image
const centerImage = (canvas, img, zoomFactor) => { const centerImage = (canvas, img, zoomFactor) => {