Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

perf(desktop): use font-display block for bundled fonts

Richie McIlroye6a890ba3b3c
diff --git a/apps/desktop/app.config.ts b/apps/desktop/app.config.ts
index b149bc913..cfa423e39 100644
--- a/apps/desktop/app.config.ts
+++ b/apps/desktop/app.config.ts
@@ -7,6 +7,28 @@ import tsconfigPaths from "vite-tsconfig-paths";
const enableSolidDevtools = !!process.env.VITE_SOLID_DEVTOOLS;
+// Bundled fonts load from local assets near-instantly, so `block` is safe and
+// avoids the fallback-font flash (FOUT) that `swap` causes on every window
+// open. Desktop-only: web keeps `swap` for slow networks.
+// No `enforce`: must run after vite:css has inlined the virtual module's
+// @import statements (a `pre` transform only sees the un-inlined imports).
+const fontDisplayBlock = {
+ name: "cap:font-display-block",
+ transform(code: string, id: string) {
+ // unplugin-fonts inlines the @fontsource CSS into its virtual
+ // "unfonts.css" module, so match that as well as direct imports.
+ const [file] = id.split("?");
+ const isFontCss =
+ file.endsWith("unfonts.css") ||
+ (file.includes("@fontsource") && file.endsWith(".css"));
+ if (!isFontCss) return;
+ return {
+ code: code.replace(/font-display:\s*swap;/g, "font-display: block;"),
+ map: null,
+ };
+ },
+};
+
export default defineConfig({
ssr: false,
server: { preset: "static" },
@@ -31,6 +53,7 @@ export default defineConfig({
assetsInclude: ["**/*.riv"],
plugins: [
...(enableSolidDevtools ? [devtools({ autoname: true })] : []),
+ fontDisplayBlock,
wasm(),
topLevelAwait(),
capUIPlugin,