Skip to content

Commit 0780220

Browse files
authored
Fix ~1 second delay opening new document in Chrome by correctly setting willReadFrequently (#2962)
* Fix ~1 second delay opening new document in Chrome by correctly setting willReadFrequently * Use willReadFrequently in a couple more places
1 parent abab145 commit 0780220

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

frontend/src/components/panels/Document.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@
241241
`.trim();
242242
243243
if (!rasterizedCanvas) {
244-
rasterizedCanvas = await rasterizeSVGCanvas(svg, width * dpiFactor, height * dpiFactor, "image/png");
245-
rasterizedContext = rasterizedCanvas.getContext("2d") || undefined;
244+
rasterizedCanvas = await rasterizeSVGCanvas(svg, width * dpiFactor, height * dpiFactor);
245+
rasterizedContext = rasterizedCanvas.getContext("2d", { willReadFrequently: true }) || undefined;
246246
}
247247
if (!rasterizedContext) return undefined;
248248

frontend/src/messages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ export class Color {
516516
const canvas = document.createElement("canvas");
517517
canvas.width = 1;
518518
canvas.height = 1;
519-
const context = canvas.getContext("2d");
519+
const context = canvas.getContext("2d", { willReadFrequently: true });
520520
if (!context) return undefined;
521521

522522
context.clearRect(0, 0, 1, 1);

frontend/src/utility-functions/rasterization.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export async function imageToCanvasContext(imageData: ImageBitmapSource): Promis
9393
canvas.width = width;
9494
canvas.height = height;
9595

96-
const context = canvas.getContext("2d");
96+
const context = canvas.getContext("2d", { willReadFrequently: true });
9797
if (!context) throw new Error("Could not create canvas context");
9898
context.drawImage(image, 0, 0, image.width, image.height, 0, 0, width, height);
9999

0 commit comments

Comments
 (0)