Skip to content

armgit / fuobe

Public Imported from GitHub
0

The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.

Canvas list and Assist: no client catalog on /canvas, revoke attachment previews

Claude33545d4d4f9e
diff --git a/src/app/(studio)/canvas/page.tsx b/src/app/(studio)/canvas/page.tsx
index fa1b58fd..42b364ef 100644
--- a/src/app/(studio)/canvas/page.tsx
+++ b/src/app/(studio)/canvas/page.tsx
@@ -1,8 +1,30 @@
import type { Metadata } from "next";
-import { CanvasList } from "@/components/canvas/canvas-list";
+import { CanvasList, type TemplateCardData } from "@/components/canvas/canvas-list";
+import { getModel } from "@/lib/catalog";
+import { CANVAS_TEMPLATES, isGenerator, outline, type CanvasTemplate } from "@/lib/catalog/canvas";
+import type { Engine } from "@/lib/catalog/types";
export const metadata: Metadata = { title: "Canvas" };
+/** One template's board outline and model names on an engine. */
+function forEngine(t: CanvasTemplate, engine: Engine): TemplateCardData["byEngine"][Engine] {
+ const graph = t.build(engine);
+ const names = graph.nodes.filter(isGenerator).map((n) => getModel(n.data.modelId ?? "")?.name);
+ return { outline: outline(graph), models: [...new Set(names.filter((m): m is string => !!m))] };
+}
+
+/** Template cards built here, so the browser never loads the model catalog for /canvas (nor for the pages that prefetch it). */
+function templateCards(): TemplateCardData[] {
+ return CANVAS_TEMPLATES.map((t) => ({
+ id: t.id,
+ name: t.name,
+ description: t.description,
+ icon: t.icon,
+ hue: t.hue,
+ byEngine: { cloud: forEngine(t, "cloud"), open: forEngine(t, "open") },
+ }));
+}
+
export default function Page() {
- return <CanvasList />;
+ return <CanvasList templates={templateCards()} />;
}
diff --git a/src/components/assist-view.tsx b/src/components/assist-view.tsx
index 37b66ce6..212d2ba6 100644
--- a/src/components/assist-view.tsx
+++ b/src/components/assist-view.tsx
@@ -66,19 +66,43 @@ function Composer({
const uploading = files.some((f) => !f.url);
const ready = text.trim().length > 0 && !uploading && !sending && !disabled;
+ // Local previews (object URLs) are released once the upload settles, when removed, and on unmount.
+ const blobs = useRef(new Set<string>());
+ const release = (url: string) => {
+ if (blobs.current.delete(url)) URL.revokeObjectURL(url);
+ };
+ useEffect(() => {
+ const live = blobs.current;
+ return () => {
+ live.forEach((u) => URL.revokeObjectURL(u));
+ live.clear();
+ };
+ }, []);
+
const add = (list: FileList | null) => {
for (const f of Array.from(list ?? []).slice(0, 8 - files.length)) {
const id = nanoid(6);
const kind: MediaKind = f.type.startsWith("video") ? "video" : f.type.startsWith("audio") ? "audio" : "image";
- setFiles((xs) => [...xs, { id, kind, preview: URL.createObjectURL(f) }]);
+ const blob = URL.createObjectURL(f);
+ blobs.current.add(blob);
+ setFiles((xs) => [...xs, { id, kind, preview: blob }]);
uploadFile(f)
- .then((a) => setFiles((xs) => xs.map((x) => (x.id === id ? { ...x, url: a.url } : x))))
+ // Show the uploaded file, then let the blob go (after the element has switched over).
+ .then((a) => {
+ setFiles((xs) => xs.map((x) => (x.id === id ? { ...x, url: a.url, preview: a.url } : x)));
+ setTimeout(() => release(blob), 1500);
+ })
.catch((e) => {
toast.error((e as Error).message);
setFiles((xs) => xs.filter((x) => x.id !== id));
+ release(blob);
});
}
};
+ const remove = (f: Attachment) => {
+ setFiles((xs) => xs.filter((x) => x.id !== f.id));
+ if (f.preview.startsWith("blob:")) release(f.preview);
+ };
const send = async () => {
if (!ready) return;
@@ -117,7 +141,7 @@ function Composer({
)}
{!f.url && <Loader2 className="absolute inset-0 m-auto size-4 animate-spin text-foreground" />}
<button
- onClick={() => setFiles((xs) => xs.filter((x) => x.id !== f.id))}
+ onClick={() => remove(f)}
className="absolute top-0.5 right-0.5 grid size-4 place-items-center rounded-full bg-foreground/80 text-background"
aria-label="Remove attachment"
>
diff --git a/src/components/canvas/canvas-list.tsx b/src/components/canvas/canvas-list.tsx
index f6f27319..2a3fed92 100644
--- a/src/components/canvas/canvas-list.tsx
+++ b/src/components/canvas/canvas-list.tsx
@@ -3,7 +3,7 @@
import { Cloud, Copy, Cpu, Loader2, MoreHorizontal, Pencil, Plus, Search, Trash2, Workflow } from "lucide-react";
import Link from "next/link";
import { useRouter, useSearchParams } from "next/navigation";
-import { Suspense, useMemo, useState } from "react";
+import { Suspense, useState } from "react";
import { toast } from "sonner";
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from "@/components/ui/alert-dialog";
import { Button } from "@/components/ui/button";
@@ -15,8 +15,8 @@ import { Skeleton } from "@/components/ui/skeleton";
import { EngineSwitch } from "@/components/studio/engine-switch";
import { PageShell } from "@/components/page-shell";
import { useEngine } from "@/lib/api";
-import { getModel } from "@/lib/catalog";
-import { CANVAS_TEMPLATES, isGenerator, outline, type CanvasNodeType, type CanvasSummary, type CanvasTemplate, type Outline } from "@/lib/catalog/canvas";
+// Types only: the catalog (models, templates) stays on the server; the page passes slim template cards.
+import type { CanvasNodeType, CanvasSummary, Outline } from "@/lib/catalog/canvas";
import type { Engine } from "@/lib/catalog/types";
import { timeAgo } from "@/lib/format";
import { cn } from "@/lib/utils";
@@ -130,13 +130,22 @@ function CanvasCard({ c, onRename, onDelete }: { c: CanvasSummary; onRename: ()
);
}
-function TemplateCard({ t, engine, onUse, busy }: { t: CanvasTemplate; engine: Engine; onUse: () => void; busy: boolean }) {
- const graph = useMemo(() => t.build(engine), [t, engine]);
- const models = [...new Set(graph.nodes.filter(isGenerator).map((n) => getModel(n.data.modelId ?? "")?.name).filter(Boolean))];
+/** A template as the list shows it, built on the server (app/(studio)/canvas/page.tsx): its board outline and model names per engine. */
+export interface TemplateCardData {
+ id: string;
+ name: string;
+ description: string;
+ icon: string;
+ hue: number;
+ byEngine: Record<Engine, { outline: Outline; models: string[] }>;
+}
+
+function TemplateCard({ t, engine, onUse, busy }: { t: TemplateCardData; engine: Engine; onUse: () => void; busy: boolean }) {
+ const { outline, models } = t.byEngine[engine];
return (
<article className="flex min-w-0 flex-col overflow-hidden rounded-xl border bg-card">
<div className="relative aspect-[16/9] bg-muted/50" style={{ background: `linear-gradient(135deg, oklch(0.62 0.12 ${t.hue} / 0.14), transparent 70%)` }}>
- <Schematic outline={outline(graph)} className="p-4" />
+ <Schematic outline={outline} className="p-4" />
<span className="absolute top-3 left-3 grid size-8 place-items-center rounded-lg bg-background/90 text-foreground shadow-soft">
<NodeIcon name={t.icon} className="size-4" />
</span>
@@ -158,7 +167,7 @@ function TemplateCard({ t, engine, onUse, busy }: { t: CanvasTemplate; engine: E
);
}
-function ListInner() {
+function ListInner({ templates }: { templates: TemplateCardData[] }) {
const router = useRouter();
const params = useSearchParams();
const tab = params.get("tab") === "templates" ? "templates" : "mine";
@@ -270,7 +279,7 @@ function ListInner() {
)
) : (
<div className="mt-6 grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3">
- {CANVAS_TEMPLATES.map((t) => (
+ {templates.map((t) => (
<TemplateCard key={t.id} t={t} engine={engine} busy={creating === t.id} onUse={() => void start(t.id, { templateId: t.id, engine })} />
))}
</div>
@@ -329,10 +338,10 @@ function ListInner() {
);
}
-export function CanvasList() {
+export function CanvasList({ templates }: { templates: TemplateCardData[] }) {
return (
<Suspense fallback={null}>
- <ListInner />
+ <ListInner templates={templates} />
</Suspense>
);
}