Skip to content

Commit e08edb2

Browse files
authored
fix: Don't draw orange border when re-rendering screenshot (#120)
* fix: Don't need to draw a border around the img Not in the final designs * fix: inadvertant effects * The effect to draw the annotation was executing unnecessarily. Give the effect a proper list of dependencies to prevent unnecessary calls. * Properly cleanup event handler in the case the effect does run again.
1 parent 4eb088b commit e08edb2

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

webview-ui/test-generation/src/Screenshot.tsx

+15-4
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@ export function Screenshot(props: ScreenshotProps) {
2525
if (!context) {
2626
return;
2727
}
28+
2829
const img = new Image();
2930
img.src = src;
3031

31-
img.onload = () => {
32+
const onload = () => {
3233
context.drawImage(img, 0, 0, imgWidth, imgHeight);
3334

34-
context.strokeRect(0, 0, imgWidth, imgHeight);
35-
3635
if (annotation) {
3736
context.lineWidth = 3;
3837
context.rect(
@@ -46,6 +45,18 @@ export function Screenshot(props: ScreenshotProps) {
4645
context.stroke();
4746
}
4847
};
49-
}, [ref, annotation, src, imgWidth, imgHeight]);
48+
img.addEventListener('load', onload);
49+
50+
return () => img.removeEventListener('load', onload);
51+
}, [
52+
ref,
53+
annotation.x,
54+
annotation.y,
55+
annotation.width,
56+
annotation.height,
57+
src,
58+
imgWidth,
59+
imgHeight,
60+
]);
5061
return <canvas ref={ref} width={imgWidth} height={imgHeight} />;
5162
}

0 commit comments

Comments
 (0)