From 10ca2341a18039ebf02dfd6effa2e4d094a9c349 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Tue, 6 Oct 2026 18:52:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E5=B8=83=E8=A1=A8=E5=8D=95=E5=9B=9E?= =?UTF-8?q?=E6=94=B6=E8=A2=AB=E6=9B=BF=E6=8D=A2=E6=88=96=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E7=9A=84=E5=B0=81=E9=9D=A2=E9=A2=84=E8=A7=88=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - useGameDistributionPublishForm 新增 previousCoverRef 与跟随 cover 的 effect,换封面 / 移除封面 / AI 生成覆盖时释放上一张的 blob 地址 --- .../useGameDistributionPublishForm.ts | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/apps/ai-game-creator-shell/src/components/game-distribution/useGameDistributionPublishForm.ts b/apps/ai-game-creator-shell/src/components/game-distribution/useGameDistributionPublishForm.ts index f890bb928..3584d74f1 100644 --- a/apps/ai-game-creator-shell/src/components/game-distribution/useGameDistributionPublishForm.ts +++ b/apps/ai-game-creator-shell/src/components/game-distribution/useGameDistributionPublishForm.ts @@ -215,6 +215,31 @@ export function useGameDistributionPublishForm({ // 文件签名 → 素材 ID:同一次打开面板重复提交不会重复上传同一张图。 const uploadedAssetCacheRef = useRef(new Map()); const objectUrlsRef = useRef(new Set()); + /** 上一张封面:替换 / 移除 / AI 生成覆盖时用来回收它的预览 blob 地址。 */ + const previousCoverRef = useRef(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;