Write HTML. Render video. Built for agents.
JavaScript aiai-agentsanimationclaude-codeffmpegframeworkgsaphtmlhtml-to-videomcpmotion-graphicspuppeteerrenderingtypescriptvideo-editor
fix(studio): the dev server leaves catalog installs to hyperframes preview (#4574)
Miguel Ángelc83e958576f4
diff --git a/packages/studio-server/src/routes/registry.ts b/packages/studio-server/src/routes/registry.tsindex c41a2f50b4..5fdb915656 100644--- a/packages/studio-server/src/routes/registry.ts+++ b/packages/studio-server/src/routes/registry.ts@@ -13,7 +13,7 @@ export function registerRegistryRoutes(api: Hono, adapter: StudioApiAdapter): vo// fallow-ignore-next-line complexityapi.post("/projects/:id/registry/install", async (c) => {if (!adapter.installRegistryBlock) {- return c.json({ error: "Registry install not available" }, 501);+ return c.json({ error: "Installing catalog items needs hyperframes preview" }, 501);}const project = await adapter.resolveProject(c.req.param("id"));if (!project) return c.json({ error: "Project not found" }, 404);diff --git a/packages/studio/src/App.tsx b/packages/studio/src/App.tsxindex a70645f463..76e36c5ecd 100644--- a/packages/studio/src/App.tsx+++ b/packages/studio/src/App.tsx@@ -209,6 +209,7 @@ export function StudioApp({ readOnlyPreview = false, readOnlyPreviewReason }: StrefreshFileTree: fileManager.refreshFileTree,reloadPreview,showToast,+ dismissToast,},previewIframeRef,setRightCollapsed: panelLayout.setRightCollapsed,diff --git a/packages/studio/src/hooks/useBlockHandlers.test.tsx b/packages/studio/src/hooks/useBlockHandlers.test.tsxnew file mode 100644index 0000000000..ca40648266--- /dev/null+++ b/packages/studio/src/hooks/useBlockHandlers.test.tsx@@ -0,0 +1,65 @@+// @vitest-environment happy-dom++import React, { act } from "react";+import { afterEach, describe, expect, it, vi } from "vitest";+import { mountReactHarness } from "./domSelectionTestHarness";+import { useBlockHandlers, type UseBlockHandlersResult } from "./useBlockHandlers";++(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;++vi.mock("../utils/blockInstaller", () => ({+ addBlockToProject: async (opts: { showToast: (message: string) => void }) => {+ opts.showToast("Installing catalog items needs hyperframes preview");+ return null;+ },+}));++afterEach(() => {+ document.body.innerHTML = "";+});++describe("useBlockHandlers", () => {+ it("leaves only the error toast when an install fails", async () => {+ const events: string[] = [];+ let nextId = 0;+ const showToast = (message: string) => {+ events.push(`show ${message}`);+ return ++nextId;+ };+ const dismissToast = (id: number) => events.push(`dismiss ${id}`);+ let handlers: UseBlockHandlersResult | undefined;+ function Harness() {+ handlers = useBlockHandlers({+ projectId: "demo",+ blockCtxDeps: {+ activeCompPath: null,+ timelineElements: [],+ readProjectFile: async () => "",+ writeProjectFile: async () => {},+ recordEdit: async () => {},+ refreshFileTree: async () => {},+ reloadPreview: () => {},+ showToast,+ dismissToast,+ },+ previewIframeRef: { current: null },+ setRightCollapsed: () => {},+ setRightPanelTab: () => {},+ });+ return null;+ }+ const root = mountReactHarness(<Harness />);++ await act(async () => {+ handlers!.handleAddBlock("x-post");+ await new Promise((resolve) => setTimeout(resolve, 0));+ });++ expect(events).toEqual([+ "show Adding x-post…",+ "show Installing catalog items needs hyperframes preview",+ "dismiss 1",+ ]);+ act(() => root.unmount());+ });+});diff --git a/packages/studio/src/hooks/useBlockHandlers.ts b/packages/studio/src/hooks/useBlockHandlers.tsindex 08d17f0d26..f55ab934ac 100644--- a/packages/studio/src/hooks/useBlockHandlers.ts+++ b/packages/studio/src/hooks/useBlockHandlers.ts@@ -23,7 +23,8 @@ interface BlockCtxDeps {}) => Promise<void>;refreshFileTree: () => Promise<void>;reloadPreview: () => void;- showToast: (message: string, tone?: "error" | "info") => void;+ showToast: (message: string, tone?: "error" | "info") => number;+ dismissToast: (id: number) => void;}interface UseBlockHandlersParams {@@ -87,21 +88,23 @@ export function useBlockHandlers({// Block installs hit the server and end in a full preview reload; without a// guard, repeat drops while one is in flight stack duplicate installs.const installingBlockRef = useRef(false);+ const { showToast, dismissToast } = blockCtxDeps;const runBlockInstall = useCallback(async <T>(blockName: string, install: () => Promise<T>): Promise<T | null> => {if (installingBlockRef.current) {- blockCtx.showToast("A block is already installing — one moment…", "info");+ showToast("A block is already installing — one moment…", "info");return null;}installingBlockRef.current = true;- blockCtx.showToast(`Adding ${blockName}…`, "info");+ const progress = showToast(`Adding ${blockName}…`, "info");try {return await install();} finally {installingBlockRef.current = false;+ dismissToast(progress);}},- [blockCtx],+ [showToast, dismissToast],);const handleAddBlock = useCallback(diff --git a/packages/studio/src/hooks/useToast.ts b/packages/studio/src/hooks/useToast.tsindex ea7f5add16..209bfc7e21 100644--- a/packages/studio/src/hooks/useToast.ts+++ b/packages/studio/src/hooks/useToast.ts@@ -50,7 +50,7 @@ export function useToast() {);const showToast = useCallback(- (message: string, tone: AppToast["tone"] = "error") => {+ (message: string, tone: AppToast["tone"] = "error"): number => {const id = nextToastId++;setToasts((prev) => {const next = [...prev, { id, message, tone }];@@ -65,6 +65,7 @@ export function useToast() {const timer = setTimeout(() => dismissToast(id), AUTO_DISMISS_MS);timersRef.current.set(id, timer);}+ return id;},[clearTimer, dismissToast],);diff --git a/packages/studio/vite.adapter.projects.test.ts b/packages/studio/vite.adapter.projects.test.tsindex ed2a74c59e..88d3d1cf99 100644--- a/packages/studio/vite.adapter.projects.test.ts+++ b/packages/studio/vite.adapter.projects.test.ts@@ -209,3 +209,21 @@ describe("dynamic preview ownership", () => {expect(previewChangeOwner(owners, join(realpathSync(dir), "index.html.tmp"))).toBeNull();});});++describe("Studio's dev server and the catalog", () => {+ it("answers every install with a 501 that points to hyperframes preview", async () => {+ const { data, app } = fixture();+ mkdirSync(join(data, "demo"));+ writeFileSync(join(data, "demo", "index.html"), "A");++ const response = await app.request("http://localhost/projects/demo/registry/install", {+ method: "POST",+ body: JSON.stringify({ blockName: "ai-chat-reveal" }),+ });++ expect(response.status).toBe(501);+ expect(await response.json()).toEqual({+ error: "Installing catalog items needs hyperframes preview",+ });+ });+});diff --git a/packages/studio/vite.adapter.ts b/packages/studio/vite.adapter.tsindex 29dd29a784..87ea594d8b 100644--- a/packages/studio/vite.adapter.ts+++ b/packages/studio/vite.adapter.ts@@ -7,11 +7,9 @@ import {existsSync,writeFileSync,realpathSync,- mkdirSync,- copyFileSync,unlinkSync,} from "node:fs";-import { basename, join, relative, resolve, isAbsolute, dirname, sep } from "node:path";+import { basename, join, relative, resolve, isAbsolute, sep } from "node:path";import type { ViteDevServer } from "vite";import {type ResolvedProject,@@ -435,48 +433,5 @@ export function createViteAdapter(}return items;},-- // fallow-ignore-next-line complexity- async installRegistryBlock(opts: {- project: ResolvedProject;- blockName: string;- }): Promise<{ written: string[]; block: RegistryItem }> {- const registryRoot = resolve(__dirname, "../../registry");- let itemDir = join(registryRoot, "blocks", opts.blockName);- if (!existsSync(join(itemDir, "registry-item.json"))) {- itemDir = join(registryRoot, "components", opts.blockName);- }- const manifestPath = join(itemDir, "registry-item.json");-- if (!existsSync(manifestPath)) {- throw new Error(`Item "${opts.blockName}" not found in registry`);- }-- const block = JSON.parse(readFileSync(manifestPath, "utf-8")) as RegistryItem;- const written: string[] = [];-- for (const file of block.files) {- const sourcePath = join(itemDir, file.path);- const targetPath = resolve(opts.project.dir, file.target);-- if (!isPathWithin(opts.project.dir, targetPath)) {- throw new Error(`Target path escapes project directory: ${file.target}`);- }-- mkdirSync(dirname(targetPath), { recursive: true });-- if (file.type === "hyperframes:composition") {- let content = readFileSync(sourcePath, "utf-8");- content = `<!-- hyperframes-registry-item: ${block.name} -->\n${content}`;- writeFileSync(targetPath, content, "utf-8");- } else {- copyFileSync(sourcePath, targetPath);- }-- written.push(file.target);- }-- return { written, block };- },};}