diff --git a/packages/cli/src/server/studioServer.previewAssets.test.ts b/packages/cli/src/server/studioServer.previewAssets.test.ts
new file mode 100644
index 0000000000..f280dd8923
--- /dev/null
+++ b/packages/cli/src/server/studioServer.previewAssets.test.ts
@@ -0,0 +1,49 @@
+import { afterEach, beforeEach, describe, expect, it } from "vitest";
+import * as fs from "node:fs";
+import * as path from "node:path";
+import { tmpdir } from "node:os";
+import { createStudioServer, type StudioServer } from "./studioServer.js";
+
+const COMPOSITION = `
+
+
+

+

+
`;
+
+let root: string;
+let server: StudioServer;
+
+beforeEach(() => {
+ root = fs.mkdtempSync(path.join(tmpdir(), "hf-preview-assets-"));
+ fs.mkdirSync(path.join(root, "assets"));
+ fs.writeFileSync(path.join(root, "index.html"), COMPOSITION);
+ fs.writeFileSync(path.join(root, "assets", "pic.png"), Buffer.alloc(4096, 7));
+ fs.writeFileSync(path.join(root, "assets", "brand.ttf"), Buffer.alloc(1024, 3));
+ server = createStudioServer({ projectDir: root, projectName: "film" });
+});
+
+afterEach(() => {
+ server.watcher.close();
+ fs.rmSync(root, { recursive: true, force: true });
+});
+
+describe("studio preview document", () => {
+ it("keeps image and font URLs instead of inlining them as base64", async () => {
+ const response = await server.app.request("/api/projects/film/preview");
+ const html = await response.text();
+
+ expect(response.status).toBe(200);
+ // Served by the bundler, not the raw-HTML fallback, so the assertions below mean something.
+ expect(html).toContain('data-hyperframes-preview-runtime="1" src="/api/runtime.js"');
+ expect(html).not.toContain("base64,");
+ expect(html.match(/src="assets\/pic\.png"/g)).toHaveLength(2);
+ expect(html).toContain("url(assets/brand.ttf)");
+ // The kept URL resolves against the preview's through the asset route.
+ expect(html).toContain('');
+ const asset = await server.app.request("/api/projects/film/preview/assets/pic.png");
+ expect(asset.status).toBe(200);
+ expect(asset.headers.get("Content-Type")).toBe("image/png");
+ expect(Buffer.from(await asset.arrayBuffer())).toEqual(Buffer.alloc(4096, 7));
+ });
+});
diff --git a/packages/cli/src/server/studioServer.ts b/packages/cli/src/server/studioServer.ts
index cdc6c5a313..5466515b36 100644
--- a/packages/cli/src/server/studioServer.ts
+++ b/packages/cli/src/server/studioServer.ts
@@ -40,6 +40,7 @@ import {
getMimeType,
affectsProjectSignature,
type PreviewApiAdapter,
+ PREVIEW_BUNDLE_OPTIONS,
thumbnailDeviceScaleFactor,
type ResolvedProject,
type RenderJobState,
@@ -427,10 +428,7 @@ export function createStudioServer(options: StudioServerOptions): StudioServer {
// we can point it at our hot-reloadable local runtime endpoint. Inlining
// ~150 KB of runtime body on every preview render would defeat browser
// caching across composition edits.
- let html = await bundleToSingleHtml(dir, {
- runtime: "placeholder",
- inlineColorGradingLuts: false,
- });
+ let html = await bundleToSingleHtml(dir, PREVIEW_BUNDLE_OPTIONS);
html = html.replace(
'data-hyperframes-preview-runtime="1" src=""',
'data-hyperframes-preview-runtime="1" src="/api/runtime.js"',
diff --git a/packages/studio-server/src/index.ts b/packages/studio-server/src/index.ts
index 4424cc191a..82e9ca37af 100644
--- a/packages/studio-server/src/index.ts
+++ b/packages/studio-server/src/index.ts
@@ -28,6 +28,7 @@ export {
type FileMutationInput,
} from "./helpers/applyFileMutations.js";
export type { PreviewApiAdapter } from "./helpers/mediaProxyPreview.js";
+export { PREVIEW_BUNDLE_OPTIONS } from "./routes/preview.js";
export { getMimeType, MIME_TYPES } from "./helpers/mime.js";
export {
consumeFileWriteReceipt,
diff --git a/packages/studio-server/src/routes/preview.ts b/packages/studio-server/src/routes/preview.ts
index 4ed13a4f59..055914ae97 100644
--- a/packages/studio-server/src/routes/preview.ts
+++ b/packages/studio-server/src/routes/preview.ts
@@ -3,7 +3,11 @@ import { createReadStream, existsSync, readFileSync, statSync } from "node:fs";
import { Readable } from "node:stream";
import { join, resolve } from "node:path";
import { createHash } from "node:crypto";
-import { injectScriptsIntoHtml, stripEmbeddedRuntimeScripts } from "@hyperframes/core/compiler";
+import {
+ injectScriptsIntoHtml,
+ stripEmbeddedRuntimeScripts,
+ type BundleOptions,
+} from "@hyperframes/core/compiler";
import { isWithinProjectRoot } from "@hyperframes/parsers/asset-resolution";
import type { StudioApiAdapter } from "../types.js";
import { resolveWithinProject } from "../helpers/safePath.js";
@@ -307,6 +311,13 @@ function resolveProjectMainHtml(
return null;
}
+/** The bundler options every adapter's `bundle()` uses. This route serves project files under a
+ * ``, so assets keep their URLs: inlined base64 multiplies the document per reference. */
+export const PREVIEW_BUNDLE_OPTIONS = {
+ runtime: "placeholder",
+ inlineAssets: false,
+} as const satisfies BundleOptions;
+
export function registerPreviewRoutes(api: Hono, adapter: PreviewApiAdapter): void {
const previewCacheHeaders = (etag: string) => ({
"Cache-Control": "private, no-cache",
diff --git a/packages/studio/vite.adapter.ts b/packages/studio/vite.adapter.ts
index 261573b42c..88a714080e 100644
--- a/packages/studio/vite.adapter.ts
+++ b/packages/studio/vite.adapter.ts
@@ -21,6 +21,7 @@ import {
createBackgroundRemovalJob,
createProjectSignature,
affectsProjectSignature,
+ PREVIEW_BUNDLE_OPTIONS,
} from "@hyperframes/studio-server";
import type { RegistryItem } from "@hyperframes/core/registry";
import { createRetryingModuleLoader, ensureProducerDist } from "./vite.producer";
@@ -238,7 +239,7 @@ export function createViteAdapter(
async bundle(dir: string) {
const bundler = await getBundler();
if (!bundler) return null;
- let html = await bundler(dir, { runtime: "placeholder", inlineColorGradingLuts: false });
+ let html = await bundler(dir, PREVIEW_BUNDLE_OPTIONS);
html = html.replace(
'data-hyperframes-preview-runtime="1" src=""',
`data-hyperframes-preview-runtime="1" src="${this.runtimeUrl}"`,