From 6c540e067132feb8f07124f8ab7dc0ba1ed39311 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:54:51 +0800 Subject: [PATCH] =?UTF-8?q?=E9=99=B6=E6=B3=A5=E5=84=BF=E6=89=93=E5=8C=85?= =?UTF-8?q?=E5=9B=9E=E6=9D=A5=E5=90=8E=E5=AF=B9=E8=B4=A6=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - useTaonierTab 新增 projectPathRef 与 isCurrentProject 判据,ensurePackage 的 await 返回后只有仍是当前项目才写 progress / packageResult,失败路径同样对账 --- .../export/state/useTaonierTab.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/apps/ai-game-creator-shell/src/view/project-development/export/state/useTaonierTab.ts b/apps/ai-game-creator-shell/src/view/project-development/export/state/useTaonierTab.ts index e5b9b2a85..a8059685f 100644 --- a/apps/ai-game-creator-shell/src/view/project-development/export/state/useTaonierTab.ts +++ b/apps/ai-game-creator-shell/src/view/project-development/export/state/useTaonierTab.ts @@ -86,6 +86,12 @@ export function useTaonierTab({ useDirectProjectManifest(projectPath); const manifestRef = useRef(manifest); manifestRef.current = manifest; + /** + * 当前项目路径。`ensurePackage` 在 await 之后要对账「这次打包还是不是当前项目的」, + * 但它闭包里的 `projectPath` 可能已经过期(面板跨项目切换时不会卸载)。 + */ + const projectPathRef = useRef(projectPath); + projectPathRef.current = projectPath; const [allowed, setAllowed] = useState(false); const [availabilityPending, setAvailabilityPending] = useState(true); @@ -175,6 +181,13 @@ export function useTaonierTab({ const ensurePackage = useCallback(async (): Promise => { const currentProjectPath = projectPath?.trim() ?? ''; + /** + * 这次打包发起时的项目是不是还是当前项目:await 回来后 `setPackageResult` 只能写给 + * 发起的那个项目,否则旧项目的包会落进新项目的面板,被发布流程当成新项目的产物。 + */ + const isCurrentProject = () => + mountedRef.current && + (projectPathRef.current?.trim() ?? '') === currentProjectPath; if (!currentProjectPath) { setBlockedMessage('先打开一个项目再发布'); return null; @@ -204,13 +217,13 @@ export function useTaonierTab({ 'export_local_project_package', { projectPath: currentProjectPath }, ); - if (!mountedRef.current) return null; + if (!isCurrentProject()) return null; setProgress(null); setPackageResult(result); appendPublishPermissionLog(currentProjectPath); return result; } catch (error) { - if (!mountedRef.current) return null; + if (!isCurrentProject()) return null; setProgress({ phase: 'failed', message: '发布失败',