Open source CapCut alternative.
TypeScript
fix(site): paint a card's cached frame instead of waiting on the decoder
David Lea9c9d887dae5
diff --git a/site/src/cut/components/ProjectsHome.tsx b/site/src/cut/components/ProjectsHome.tsxindex a09ebaf8..befd3c03 100644--- a/site/src/cut/components/ProjectsHome.tsx+++ b/site/src/cut/components/ProjectsHome.tsx@@ -949,6 +949,11 @@ function CardPreview({ project: p, residency }: { project: ProjectSummary; resid// The frame this card drew last time, so coming back from a project shows the// picture at once instead of a grey rectangle while the media loads.const poster = useCardPoster(p.id, residency, videoRef, seen);+ // Whether the media itself has a frame up yet. Until it does the cached one+ // is what the tile shows — as its own layer, because the element's `poster`+ // attribute is read when the media starts loading and the cached frame comes+ // out of IndexedDB a moment after that.+ const [decoded, setDecoded] = useState(false);const backend = backendFor(residency);const fileUrl = (file: string) =>backend.url(`/api/cut/projects/${p.id}/media/${encodeURIComponent(file)}`);@@ -999,14 +1004,23 @@ function CardPreview({ project: p, residency }: { project: ProjectSummary; residcrossOrigin={MEDIA_CORS}ref={videoRef}src={`${src}#t=${posterT}`}- poster={poster ?? undefined}mutedloopplaysInlinepreload="metadata"+ onLoadedData={() => setDecoded(true)}className="size-full object-cover"/>)}+ {poster && !decoded && (+ // eslint-disable-next-line @next/next/no-img-element -- a cached data URL, not a Next asset+ <img+ src={poster}+ alt=""+ draggable={false}+ className="absolute inset-0 size-full object-cover"+ />+ )}</div>);}