fix(file-viewer): revoke blob URL created by an aborted media load

If the file switches while the fetch/PDF-validation is awaiting, the effect
cleanup runs before objectUrl is assigned, so it revokes nothing and the
in-flight load then creates a blob URL that is never freed. Check
controller.signal.aborted right after createObjectURL and revoke + bail so
rapid switching can't leak object URLs (CodeRabbit: Stability, Major).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
CloudCLI UI Contributors
2026-06-29 02:25:51 +00:00
parent e39de299c3
commit de13eed72a

View File

@@ -103,6 +103,16 @@ export default function CodeEditorMediaPreview({
const typed = outType && outType !== blob.type ? new Blob([blob], { type: outType }) : blob; const typed = outType && outType !== blob.type ? new Blob([blob], { type: outType }) : blob;
objectUrl = URL.createObjectURL(typed); objectUrl = URL.createObjectURL(typed);
// The cleanup may have already run (deps changed during an await), in
// which case it revoked nothing because objectUrl was still null. Don't
// publish a URL the cleanup will never revoke — drop it ourselves.
if (controller.signal.aborted) {
URL.revokeObjectURL(objectUrl);
objectUrl = null;
return;
}
setUrl(objectUrl); setUrl(objectUrl);
setLoadedKey(sourceKey); setLoadedKey(sourceKey);
} catch (loadError: unknown) { } catch (loadError: unknown) {