Skip to content

Commit 8787900

Browse files
authored
fix(feedback): Reduce force layout in screenshots (#11181)
Reduce force layout/reflow by reducing calls mentioned [here](https://gist.github.com/paulirish/5d52fb081b3570c81e3a)
1 parent a99f260 commit 8787900

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

packages/feedback/src/screenshot/components/ScreenshotEditor.tsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,17 @@ const constructRect = (box: Box): Rect => {
4646
};
4747

4848
const getContainedSize = (img: HTMLCanvasElement): Box => {
49+
const imgClientHeight = img.clientHeight;
50+
const imgClientWidth = img.clientWidth;
4951
const ratio = img.width / img.height;
50-
let width = img.clientHeight * ratio;
51-
let height = img.clientHeight;
52-
if (width > img.clientWidth) {
53-
width = img.clientWidth;
54-
height = img.clientWidth / ratio;
52+
let width = imgClientHeight * ratio;
53+
let height = imgClientHeight;
54+
if (width > imgClientWidth) {
55+
width = imgClientWidth;
56+
height = imgClientWidth / ratio;
5557
}
56-
const x = (img.clientWidth - width) / 2;
57-
const y = (img.clientHeight - height) / 2;
58+
const x = (imgClientWidth - width) / 2;
59+
const y = (imgClientHeight - height) / 2;
5860
return { startX: x, startY: y, endX: width + x, endY: height + y };
5961
};
6062

@@ -215,9 +217,11 @@ export function makeScreenshotEditorComponent({ h, imageBuffer, dialog }: Factor
215217
if (!context) {
216218
throw new Error('Could not get canvas context');
217219
}
218-
imageBuffer.width = imageSource.videoWidth;
219-
imageBuffer.height = imageSource.videoHeight;
220-
context.drawImage(imageSource, 0, 0, imageSource.videoWidth, imageSource.videoHeight);
220+
const sourceWidth = imageSource.videoWidth;
221+
const sourceHeight = imageSource.videoHeight;
222+
imageBuffer.width = sourceWidth;
223+
imageBuffer.height = sourceHeight;
224+
context.drawImage(imageSource, 0, 0, sourceWidth, sourceHeight);
221225
},
222226
[imageBuffer],
223227
),

0 commit comments

Comments
 (0)