diff --git a/packages/core/src/studio-api/routes/thumbnail.test.ts b/packages/core/src/studio-api/routes/thumbnail.test.ts
index e225d4d066..0c2697aa8c 100644
--- a/packages/core/src/studio-api/routes/thumbnail.test.ts
+++ b/packages/core/src/studio-api/routes/thumbnail.test.ts
@@ -1,6 +1,6 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { Hono } from "hono";
-import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
+import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { registerThumbnailRoutes } from "./thumbnail";
@@ -151,22 +151,27 @@ describe("registerThumbnailRoutes", () => {
);
});
- it("preserves an explicit zero seek time", async () => {
+ it("keeps changed studio manual edits separated in the disk cache", async () => {
const adapter = createAdapter();
+ const project = await adapter.resolveProject("demo");
+ if (!project) throw new Error("missing project");
const app = new Hono();
registerThumbnailRoutes(app, adapter);
- const response = await app.request(
- "http://localhost/projects/demo/thumbnail/index.html?t=0&format=png",
- );
+ const indexPath = join(project.dir, "index.html");
+ writeFileSync(indexPath, `
`);
+ const manualEditsDir = join(project.dir, ".hyperframes");
+ mkdirSync(manualEditsDir, { recursive: true });
+ const manualEditsPath = join(manualEditsDir, "studio-manual-edits.json");
+ writeFileSync(manualEditsPath, `{"version":1,"edits":[]}`);
- expect(response.status).toBe(200);
- expect(adapter.generateThumbnail).toHaveBeenCalledWith(
- expect.objectContaining({
- compPath: "index.html",
- seekTime: 0,
- format: "png",
- }),
+ await app.request("http://localhost/projects/demo/thumbnail/index.html?t=2&v=test");
+ writeFileSync(
+ manualEditsPath,
+ `{"version":1,"edits":[{"kind":"rotation","target":{"sourceFile":"index.html","id":"card"},"angle":30}]}`,
);
+ await app.request("http://localhost/projects/demo/thumbnail/index.html?t=2&v=test");
+
+ expect(adapter.generateThumbnail).toHaveBeenCalledTimes(2);
});
});
diff --git a/packages/core/src/studio-api/routes/thumbnail.ts b/packages/core/src/studio-api/routes/thumbnail.ts
index 34c1187e25..5f9c746504 100644
--- a/packages/core/src/studio-api/routes/thumbnail.ts
+++ b/packages/core/src/studio-api/routes/thumbnail.ts
@@ -1,9 +1,11 @@
import type { Hono } from "hono";
import { existsSync, readFileSync, writeFileSync, mkdirSync, statSync } from "node:fs";
import { join } from "node:path";
+import { createHash } from "node:crypto";
import type { StudioApiAdapter } from "../types.js";
const THUMBNAIL_CACHE_VERSION = "v3";
+const STUDIO_MANUAL_EDITS_PATH = ".hyperframes/studio-manual-edits.json";
export function registerThumbnailRoutes(api: Hono, adapter: StudioApiAdapter): void {
api.get("/projects/:id/thumbnail/*", async (c) => {
@@ -47,6 +49,13 @@ export function registerThumbnailRoutes(api: Hono, adapter: StudioApiAdapter): v
if (hMatch?.[1]) compH = parseInt(hMatch[1]);
}
}
+ const manualEditsFile = join(project.dir, STUDIO_MANUAL_EDITS_PATH);
+ let manualEditsKey = "";
+ if (existsSync(manualEditsFile)) {
+ const manualEditsContent = readFileSync(manualEditsFile, "utf-8");
+ manualEditsKey = `_${createHash("sha1").update(manualEditsContent).digest("hex").slice(0, 16)}`;
+ sourceMtime = Math.max(sourceMtime, Math.round(statSync(manualEditsFile).mtimeMs));
+ }
const previewUrl =
compPath === "index.html"
@@ -61,7 +70,7 @@ export function registerThumbnailRoutes(api: Hono, adapter: StudioApiAdapter): v
const urlVersionKey = urlVersion
? `_${urlVersion.replace(/[^a-zA-Z0-9_-]+/g, "_").slice(0, 32)}`
: "";
- const cacheKey = `${THUMBNAIL_CACHE_VERSION}${urlVersionKey}_${format}_${compPath.replace(/\//g, "_")}_${compW}x${compH}_${sourceMtime}_${seekTime.toFixed(2)}${selectorKey}.${format === "png" ? "png" : "jpg"}`;
+ const cacheKey = `${THUMBNAIL_CACHE_VERSION}${urlVersionKey}${manualEditsKey}_${format}_${compPath.replace(/\//g, "_")}_${compW}x${compH}_${sourceMtime}_${seekTime.toFixed(2)}${selectorKey}.${format === "png" ? "png" : "jpg"}`;
const cachePath = join(cacheDir, cacheKey);
if (existsSync(cachePath)) {
return new Response(new Uint8Array(readFileSync(cachePath)), {
diff --git a/packages/producer/src/services/fileServer.test.ts b/packages/producer/src/services/fileServer.test.ts
index 426dfb31dc..643fc34dcf 100644
--- a/packages/producer/src/services/fileServer.test.ts
+++ b/packages/producer/src/services/fileServer.test.ts
@@ -153,6 +153,40 @@ describe("isPathInside", () => {
});
describe("createFileServer", () => {
+ it("appends additional body scripts after configured body scripts", async () => {
+ const projectDir = mkdtempSync(join(tmpdir(), "hf-file-server-extra-body-"));
+
+ try {
+ writeFileSync(
+ join(projectDir, "index.html"),
+ "",
+ );
+
+ const server = await createFileServer({
+ projectDir,
+ preHeadScripts: [],
+ headScripts: [],
+ bodyScripts: ["window.__bodyScript = true;"],
+ additionalBodyScripts: ["window.__additionalBodyScript = true;"],
+ });
+
+ try {
+ const response = await fetch(`${server.url}/index.html`);
+ const html = await response.text();
+
+ expect(response.status).toBe(200);
+ expect(html.indexOf("window.__bodyScript = true;")).toBeGreaterThanOrEqual(0);
+ expect(html.indexOf("window.__additionalBodyScript = true;")).toBeGreaterThan(
+ html.indexOf("window.__bodyScript = true;"),
+ );
+ } finally {
+ server.close();
+ }
+ } finally {
+ rmSync(projectDir, { recursive: true, force: true });
+ }
+ });
+
it("serves asset files through project-root symlinked directories", async () => {
const workspaceDir = mkdtempSync(join(tmpdir(), "hf-file-server-symlink-assets-"));
const adsDir = join(workspaceDir, "Ads");
diff --git a/packages/producer/src/services/fileServer.ts b/packages/producer/src/services/fileServer.ts
index 2f96c6e9a0..bc36072c36 100644
--- a/packages/producer/src/services/fileServer.ts
+++ b/packages/producer/src/services/fileServer.ts
@@ -420,6 +420,8 @@ export interface FileServerOptions {
headScripts?: string[];
/** Scripts injected before