发布表单回收被替换或移除的封面预览地址

- useGameDistributionPublishForm 新增 previousCoverRef 与跟随 cover 的 effect,换封面 / 移除封面 / AI 生成覆盖时释放上一张的 blob 地址
This commit is contained in:
2026-10-06 18:52:39 +08:00
parent f4b1a6ad99
commit 10ca2341a1
@@ -215,6 +215,31 @@ export function useGameDistributionPublishForm({
// 文件签名 → 素材 ID:同一次打开面板重复提交不会重复上传同一张图。
const uploadedAssetCacheRef = useRef(new Map<string, string>());
const objectUrlsRef = useRef(new Set<string>());
/** 上一张封面:替换 / 移除 / AI 生成覆盖时用来回收它的预览 blob 地址。 */
const previousCoverRef = useRef<PanelImageAsset | null>(null);
/**
* 封面预览地址跟着封面走:换封面、移除封面、AI 生成覆盖都会丢掉上一张的 blob 地址,
* 不在这里统一回收就会一路泄漏到面板卸载(卸载清理只认 `objectUrlsRef`)。
*/
useEffect(() => {
const previous = previousCoverRef.current;
previousCoverRef.current = cover;
if (
!previous ||
previous === cover ||
!previous.previewUrl ||
!objectUrlsRef.current.has(previous.previewUrl)
) {
return;
}
try {
URL.revokeObjectURL(previous.previewUrl);
} catch {
// 预览地址释放失败不影响换封面 / 移除封面。
}
objectUrlsRef.current.delete(previous.previewUrl);
}, [cover]);
useEffect(() => {
if (!open) return;