From 5cd8054a8d24ccde22b9dfc6e03fca1b39d7ff73 Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Mon, 11 Mar 2024 17:19:02 -0500 Subject: [PATCH 1/2] Prevent undesired image blur captures --- src/components/CanvasBlurCapture.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/CanvasBlurCapture.tsx b/src/components/CanvasBlurCapture.tsx index a47d6a2a..ce66d3de 100644 --- a/src/components/CanvasBlurCapture.tsx +++ b/src/components/CanvasBlurCapture.tsx @@ -83,7 +83,10 @@ export default function CanvasBlurCapture({ // Store timeout ref to ensure it's closed over // in cleanup function (recommended by exhaustive-deps) const timeouts = refTimeouts.current; - return () => timeouts.forEach(clearTimeout); + return () => { + refShouldCapture.current = false; + timeouts.forEach(clearTimeout); + }; }, [ imageUrl, onCapture, From a998880c8ddceaed905435c69ff0037e01374af7 Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Mon, 11 Mar 2024 18:03:06 -0500 Subject: [PATCH 2/2] Refine blur capture logic --- src/components/CanvasBlurCapture.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/CanvasBlurCapture.tsx b/src/components/CanvasBlurCapture.tsx index ce66d3de..a4541e04 100644 --- a/src/components/CanvasBlurCapture.tsx +++ b/src/components/CanvasBlurCapture.tsx @@ -29,6 +29,8 @@ export default function CanvasBlurCapture({ const refShouldCapture = useRef(true); useEffect(() => { + refShouldCapture.current = true; + const capture = () => { if (refShouldCapture.current) { if ( @@ -44,7 +46,7 @@ export default function CanvasBlurCapture({ if (context) { context.scale(scale, scale); context.filter = - 'contrast(1.2) saturate(1.2)' + + 'contrast(1.2) saturate(1.2) ' + `blur(${scale * 10}px)`; context.drawImage( refImage.current,