Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Prevent duplicate image bitmap creation in editor

Richie McIlroy9c960b67bf68
diff --git a/apps/desktop/src/routes/screenshot-editor/context.tsx b/apps/desktop/src/routes/screenshot-editor/context.tsx
index da837aad5..e89104f0c 100644
--- a/apps/desktop/src/routes/screenshot-editor/context.tsx
+++ b/apps/desktop/src/routes/screenshot-editor/context.tsx
@@ -145,13 +145,22 @@ function createScreenshotEditorContext() {
}
}
+ let hasReceivedWebSocketFrame = false;
+
if (instance.path) {
const img = new Image();
img.crossOrigin = "anonymous";
img.src = convertFileSrc(instance.path);
img.onload = async () => {
+ if (hasReceivedWebSocketFrame) {
+ return;
+ }
try {
const bitmap = await createImageBitmap(img);
+ if (hasReceivedWebSocketFrame) {
+ bitmap.close();
+ return;
+ }
const existing = latestFrame();
if (existing?.bitmap) {
existing.bitmap.close();
@@ -188,6 +197,8 @@ function createScreenshotEditorContext() {
if (!width || !height) return;
+ hasReceivedWebSocketFrame = true;
+
const expectedRowBytes = width * 4;
const frameData = new Uint8ClampedArray(
buffer,