Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
Refactor subtitle and chapters URL cleanup logic
Richie McIlroy5aa6caf85643
diff --git a/apps/web/app/embed/[videoId]/_components/EmbedVideo.tsx b/apps/web/app/embed/[videoId]/_components/EmbedVideo.tsxindex a34584618..59efc6461 100644--- a/apps/web/app/embed/[videoId]/_components/EmbedVideo.tsx+++ b/apps/web/app/embed/[videoId]/_components/EmbedVideo.tsx@@ -92,7 +92,6 @@ export const EmbedVideo = forwardRef<}}, [transcriptContent, transcriptError]);- // Handle subtitle URL creationuseEffect(() => {if (data.transcriptionStatus === "COMPLETE" &&@@ -102,51 +101,38 @@ export const EmbedVideo = forwardRef<const vttContent = formatTranscriptAsVTT(transcriptData);const blob = new Blob([vttContent], { type: "text/vtt" });const newUrl = URL.createObjectURL(blob);-- // Clean up previous URL- if (subtitleUrl) {- URL.revokeObjectURL(subtitleUrl);- }-- setSubtitleUrl(newUrl);-+ setSubtitleUrl((prev) => {+ if (prev) URL.revokeObjectURL(prev);+ return newUrl;+ });return () => {URL.revokeObjectURL(newUrl);};- } else {- // Clean up if no longer needed- if (subtitleUrl) {- URL.revokeObjectURL(subtitleUrl);- setSubtitleUrl(null);- }}- }, [data.transcriptionStatus, transcriptData, subtitleUrl]);+ setSubtitleUrl((prev) => {+ if (prev) URL.revokeObjectURL(prev);+ return null;+ });+ }, [data.transcriptionStatus, transcriptData]);- // Handle chapters URL creationuseEffect(() => {if (chapters?.length > 0) {const vttContent = formatChaptersAsVTT(chapters);const blob = new Blob([vttContent], { type: "text/vtt" });const newUrl = URL.createObjectURL(blob);-- // Clean up previous URL- if (chaptersUrl) {- URL.revokeObjectURL(chaptersUrl);- }-- setChaptersUrl(newUrl);-+ setChaptersUrl((prev) => {+ if (prev) URL.revokeObjectURL(prev);+ return newUrl;+ });return () => {URL.revokeObjectURL(newUrl);};- } else {- // Clean up if no longer needed- if (chaptersUrl) {- URL.revokeObjectURL(chaptersUrl);- setChaptersUrl(null);- }}- }, [chapters, chaptersUrl]);+ setChaptersUrl((prev) => {+ if (prev) URL.revokeObjectURL(prev);+ return null;+ });+ }, [chapters]);const isMp4Source =data.source.type === "desktopMP4" || data.source.type === "webMP4";