From db2ecf32c43acb99aff48aee4ed6dcdba932e005 Mon Sep 17 00:00:00 2001 From: Ryan Malloy Date: Sat, 14 Feb 2026 13:25:43 -0700 Subject: [PATCH] Fix font buffer slice and env var access for production SSR MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Node.js Buffer pool shares an ArrayBuffer — slice to give Satori's OpenType parser a standalone copy starting at byte 0. Use process.env instead of import.meta.env for BACKEND_INTERNAL_URL since Vite only exposes PUBLIC_* prefixed vars via import.meta.env. --- frontend/src/lib/og-renderer.tsx | 5 ++++- frontend/src/lib/server-api.ts | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/frontend/src/lib/og-renderer.tsx b/frontend/src/lib/og-renderer.tsx index a6e8e40..cb205ad 100644 --- a/frontend/src/lib/og-renderer.tsx +++ b/frontend/src/lib/og-renderer.tsx @@ -17,7 +17,10 @@ function loadFont(): ArrayBuffer { ]; for (const path of candidates) { try { - return readFileSync(path).buffer as ArrayBuffer; + const buf = readFileSync(path); + // Node.js Buffers share a pooled ArrayBuffer — slice to get a + // standalone copy so Satori's OpenType parser starts at byte 0. + return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength); } catch { // try next } diff --git a/frontend/src/lib/server-api.ts b/frontend/src/lib/server-api.ts index e5b4793..a15b198 100644 --- a/frontend/src/lib/server-api.ts +++ b/frontend/src/lib/server-api.ts @@ -1,5 +1,7 @@ +// process.env is required here — Vite's import.meta.env only exposes +// PUBLIC_* prefixed vars. This module runs server-side only (SSR). export const INTERNAL_API_BASE = - import.meta.env.BACKEND_INTERNAL_URL || 'http://localhost:8099'; + process.env.BACKEND_INTERNAL_URL || 'http://localhost:8099'; export async function fetchNotebookMeta(id: string) { const url = `${INTERNAL_API_BASE}/api/notebooks/${encodeURIComponent(id)}`;