Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(web): never blank the transcript during the live-to-canonical handoff

Richie McIlroy4027258dc233
diff --git a/apps/web/app/s/[videoId]/_components/tabs/Transcript.tsx b/apps/web/app/s/[videoId]/_components/tabs/Transcript.tsx
index da5d7c1fb..9851431a1 100644
--- a/apps/web/app/s/[videoId]/_components/tabs/Transcript.tsx
+++ b/apps/web/app/s/[videoId]/_components/tabs/Transcript.tsx
@@ -142,6 +142,13 @@ const parseVTT = (vttContent: string): TranscriptEntry[] => {
return sortedEntries;
};
+/** Module-level so the last live transcript survives component remounts and
+ * router refreshes during the live→canonical handoff. */
+const lastLiveTranscript = new Map<
+ string,
+ { content: string; active: boolean }
+>();
+
export const Transcript: React.FC<TranscriptProps> = ({ data, onSeek }) => {
const user = useCurrentUser();
const queryClient = useQueryClient();
@@ -245,15 +252,35 @@ export const Transcript: React.FC<TranscriptProps> = ({ data, onSeek }) => {
isLiveTranscriptEnabled,
);
+ // The promotion handoff deletes the live artifact moments before the
+ // canonical VTT becomes fetchable; the cache bridges that gap (and any
+ // refresh) so a partial transcript never blanks back to "generating".
+ if (liveTranscript?.kind === "ready") {
+ lastLiveTranscript.set(data.id, {
+ content: liveTranscript.content,
+ active: liveTranscript.state === "active",
+ });
+ }
const liveTranscriptContent =
- liveTranscript?.kind === "ready" ? liveTranscript.content : null;
+ liveTranscript?.kind === "ready"
+ ? liveTranscript.content
+ : (lastLiveTranscript.get(data.id)?.content ?? null);
+ const isLiveTranscriptActive =
+ liveTranscript?.kind === "ready" && liveTranscript.state === "active";
const liveTranscriptData = useMemo(
() => (liveTranscriptContent ? parseVTT(liveTranscriptContent) : []),
[liveTranscriptContent],
);
- const showLiveTranscript =
- isLiveTranscriptEnabled && liveTranscriptData.length > 0;
+ const showLiveTranscript = liveTranscriptData.length > 0;
+
+ const canonicalTranscriptReady =
+ data.transcriptionStatus === "COMPLETE" && transcriptData.length > 0;
+ useEffect(() => {
+ if (canonicalTranscriptReady) {
+ lastLiveTranscript.delete(data.id);
+ }
+ }, [canonicalTranscriptReady, data.id]);
const invalidateTranscript = useInvalidateTranscript();
@@ -504,59 +531,62 @@ export const Transcript: React.FC<TranscriptProps> = ({ data, onSeek }) => {
const canEdit = user?.id === data.owner.id && selectedLanguage === "original";
- if (isTranscriptionProcessing && !hasTimedOut) {
- if (showLiveTranscript) {
- const isLiveActive =
- liveTranscript?.kind === "ready" && liveTranscript.state === "active";
-
- return (
- <div className="flex flex-col h-full">
- <div className="flex flex-none items-center gap-2 border-b border-gray-3 px-4 py-3">
- {isLiveActive ? (
- <span className="relative flex size-2">
- <span className="absolute inline-flex h-full w-full animate-ping rounded-full bg-red-500 opacity-75" />
- <span className="relative inline-flex rounded-full size-2 bg-red-500" />
- </span>
- ) : (
- <LoaderCircle className="size-3 animate-spin text-gray-9" />
- )}
- <span className="text-[11px] font-medium text-gray-12">
- Live transcript
- </span>
- <span className="text-[11px] text-gray-9">
- {isLiveActive
- ? "updating as the recording uploads"
- : "processing final transcript…"}
- </span>
- </div>
+ const liveTranscriptView = showLiveTranscript ? (
+ <div className="flex flex-col h-full">
+ <div className="flex flex-none items-center gap-2 border-b border-gray-3 px-4 py-3">
+ {isLiveTranscriptActive ? (
+ <span className="relative flex size-2">
+ <span className="absolute inline-flex h-full w-full animate-ping rounded-full bg-red-500 opacity-75" />
+ <span className="relative inline-flex rounded-full size-2 bg-red-500" />
+ </span>
+ ) : (
+ <LoaderCircle className="size-3 animate-spin text-gray-9" />
+ )}
+ <span className="text-[11px] font-medium text-gray-12">
+ {isLiveTranscriptActive ? "Live transcript" : "Transcript"}
+ </span>
+ </div>
- <div className="overflow-y-auto flex-1">
- <div className="px-3 py-3">
- {liveTranscriptData.map((entry) => (
- <div
- key={entry.id}
- className={`flex items-start gap-1 rounded-lg px-2 transition-colors ${
- selectedEntry === entry.id ? "bg-gray-3" : "hover:bg-gray-2"
- }`}
- >
- <button
- className="flex min-w-0 flex-1 items-baseline gap-2.5 py-1.5 text-left"
- onClick={() => handleTranscriptClick(entry)}
- type="button"
- >
- <span className="w-9 shrink-0 font-mono text-[10px] leading-[22px] tabular-nums text-gray-8">
- {entry.timestamp}
- </span>
- <span className="min-w-0 flex-1 text-[13px] leading-[22px] text-gray-11">
- {entry.text}
- </span>
- </button>
- </div>
- ))}
+ <div className="overflow-y-auto flex-1">
+ <div className="px-3 py-3">
+ {liveTranscriptData.map((entry) => (
+ <div
+ key={entry.id}
+ className={`flex items-start gap-1 rounded-lg px-2 transition-colors ${
+ selectedEntry === entry.id ? "bg-gray-3" : "hover:bg-gray-2"
+ }`}
+ >
+ <button
+ className="flex min-w-0 flex-1 items-baseline gap-2.5 py-1.5 text-left"
+ onClick={() => handleTranscriptClick(entry)}
+ type="button"
+ >
+ <span className="w-9 shrink-0 font-mono text-[10px] leading-[22px] tabular-nums text-gray-8">
+ {entry.timestamp}
+ </span>
+ <span className="min-w-0 flex-1 text-[13px] leading-[22px] text-gray-11">
+ {entry.text}
+ </span>
+ </button>
</div>
+ ))}
+ {/* The rest of the recording is still transcribing (or the final
+ transcript is being swapped in) — say so under the words
+ instead of ever blanking the list. */}
+ <div className="flex items-center gap-2 px-2 pt-2 pb-1 text-[11px] text-gray-9">
+ <LoaderCircle className="size-3 animate-spin" />
+ {isLiveTranscriptActive
+ ? "Transcribing as the recording uploads…"
+ : "Finalizing transcript…"}
</div>
</div>
- );
+ </div>
+ </div>
+ ) : null;
+
+ if (isTranscriptionProcessing && !hasTimedOut) {
+ if (liveTranscriptView) {
+ return liveTranscriptView;
}
return (
@@ -575,6 +605,11 @@ export const Transcript: React.FC<TranscriptProps> = ({ data, onSeek }) => {
}
if (isQueryLoading) {
+ // COMPLETE but the canonical VTT is still being fetched: keep showing
+ // the live transcript through the swap instead of a bare spinner.
+ if (liveTranscriptView) {
+ return liveTranscriptView;
+ }
return (
<div className="flex h-full items-center justify-center">
<LoaderCircle className="size-5 animate-spin text-gray-9" />