From 45996c35235746fdf4380e2501c8a6fd24e570d4 Mon Sep 17 00:00:00 2001 From: Vance Ingalls Date: Tue, 31 Mar 2026 22:25:29 -0700 Subject: [PATCH] fix(studio): serve runtime locally instead of from CDN The Vite dev server was loading the HyperFrames runtime IIFE from cdn.jsdelivr.net. This caused compositions using window.__hyperframes (e.g., fitTextFontSize) to fail when the CDN script didn't load in the iframe context. Add a /api/runtime.js endpoint to the Vite plugin that serves the local built runtime, matching what studioServer.ts already does for the CLI embedded server. Co-Authored-By: Claude Opus 4.6 (1M context) --- packages/studio/vite.config.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/studio/vite.config.ts b/packages/studio/vite.config.ts index f936e7da8..b0556a9c7 100644 --- a/packages/studio/vite.config.ts +++ b/packages/studio/vite.config.ts @@ -146,7 +146,7 @@ function createViteAdapter(dataDir: string, server: ViteDevServer): StudioApiAda return mod.lintHyperframeHtml(html, opts); }, - runtimeUrl: "https://cdn.jsdelivr.net/npm/@hyperframes/core/dist/hyperframe.runtime.iife.js", + runtimeUrl: "/api/runtime.js", rendersDir: () => resolve(dataDir, "../renders"), @@ -363,6 +363,22 @@ function devProjectApi(): Plugin { return _api; }; + // Serve the local runtime IIFE so compositions don't depend on CDN + const runtimePath = resolve(__dirname, "../core/dist/hyperframe.runtime.iife.js"); + server.middlewares.use((req, res, next) => { + if (req.url !== "/api/runtime.js") return next(); + if (!existsSync(runtimePath)) { + res.writeHead(404); + res.end("runtime not built — run pnpm build in packages/core"); + return; + } + res.writeHead(200, { + "Content-Type": "text/javascript", + "Cache-Control": "no-store", + }); + res.end(readFileSync(runtimePath, "utf-8")); + }); + server.middlewares.use(async (req, res, next) => { if (!req.url?.startsWith("/api/")) return next();