Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

perf(desktop): prewarm font and emoji caches on app mount

Richie McIlroyf2447fb9abeb
diff --git a/apps/desktop/src/app.tsx b/apps/desktop/src/app.tsx
index 022501fa3..d55ade5dd 100644
--- a/apps/desktop/src/app.tsx
+++ b/apps/desktop/src/app.tsx
@@ -126,6 +126,7 @@ function Inner() {
onMount(() => {
initAnonymousUser();
+ prewarmFontCaches();
});
return (
@@ -253,6 +254,29 @@ function Inner() {
);
}
+// WebKit resolves the emoji fallback chain lazily on first glyph paint, which
+// can jank the first list/text render containing emoji (e.g. recording
+// titles). Drawing once to an offscreen canvas at idle warms the per-process
+// font caches instead.
+function prewarmFontCaches() {
+ const warm = () => {
+ try {
+ const canvas = document.createElement("canvas");
+ canvas.width = 32;
+ canvas.height = 32;
+ const ctx = canvas.getContext("2d");
+ if (!ctx) return;
+ ctx.font = "16px 'Geist Sans'";
+ ctx.fillText("Ag", 0, 24);
+ ctx.font = "16px system-ui";
+ ctx.fillText("😀", 0, 24);
+ } catch {}
+ };
+
+ if ("requestIdleCallback" in window) requestIdleCallback(warm);
+ else setTimeout(warm, 250);
+}
+
function createThemeListener(currentWindow: WebviewWindow) {
const [appTheme, setAppTheme] = createSignal<AppTheme | null | undefined>();
let disposed = false;