与 665982eb9 的 tauri 事件注销竞态是两个独立原因,用户看到的是同一个症状:
① 切换版本时的重载被事件竞态报错打断(665982eb9,已并入 6618207b5);
② 版本菜单在选项收到 click 之前被「点外部」判定收掉,onSelectVersion 永远不被调用(本提交)。
- 现象:在运行模块点版本菜单里的选项没有任何反应(菜单直接消失、当前版本不切换)。
- 原因:菜单用 createPortal 挂到 document.body(运行画面会缩放,挂 body 才不跟着画布跑偏),DOM 上不在触发按钮 rootRef 的子树里;而「点外部关闭」判定只认 rootRef,落在选项上的那一次按下就被当成点外部,菜单在选项收到 click 之前被卸载,选项的 onClick 永远不会触发。
- 改法:删掉自建的 window mousedown 判定,复用共享 hook useImageCanvasFloatingOptionDismiss(AGC 的 view/project-development/index.tsx:1661 已在用同一份口径,不新造第二套判定),并把 portal 菜单登记成第二个边界:GameRunVersionPicker.tsx:35 新增 menuRef、:37-41 传 boundaryRefs: [rootRef, menuRef]、:69 把 menuRef 挂到菜单容器上。菜单的关闭时机随之从 mousedown 变为 click,与画布浮层口径一致。
- 回归用例(apps/ai-game-creator-shell/tests/resourceVersionSwitch.test.tsx,全部走真实指针序列 mousedown → mouseup → click,不再像旧用例那样只派发 click):
- does not dismiss the portal version menu when an option is pressed down:mousedown 后菜单必须还在,随后 mouseup+click 必须调用 onSelectVersion('version-root')。
- selects the version from the run module when the option is clicked after a real press:真实 launcher + 运行模块,走完真实序列后宿主必须收到 onActiveVersionChange('version-root')。
- keeps the portal menu mounted when the click lands on the menu itself:点 portal 菜单自身(非选项区)不算点外部。
- 变异验证(两条,都先红后绿):
- 还原旧实现(window mousedown + 只认 rootRef)→ 3 条新用例全红:2 条 AssertionError: expected null not to be null(菜单被关掉),1 条 expected "spy" to be called with arguments: [ 'version-root' ] / Number of calls: 0(onActiveVersionChange 没被调用,正是用户症状)。
- 只把边界收回 boundaryRefs: [rootRef](仍复用 hook,但不登记 portal 菜单)→ keeps the portal menu mounted when the click lands on the menu itself 变红(expected null not to be null)。注意另两条此时仍绿:共享 hook 的判定在 click 而非 mousedown,所以要复现用户现象必须连旧的 mousedown 判定一起还原,这也是本次把判定整体换成共享 hook 的直接理由。
- 验证:npx vitest run apps/ai-game-creator-shell/tests/resourceVersionSwitch.test.tsx 7 passed(原 4 条 + 新 3 条);npm --prefix apps/ai-game-creator-shell run typecheck exit 0。
- resourceVersionSwitch 新增用例:运行模块内切换版本必须既上报宿主又触发 onPlay 重载预览
- 覆盖验收用例 S16 的「并重载当前预览」条款(此前版本入口只测了记录层与高亮,重载没有守卫)
- 变异验证:摘掉 selectActiveVersion 里的 onPlay 调用后,该用例以 expected "spy" to be called at least once 失败
- 定向验证:resourceVersionSwitch 4 passed