🐛 fix(sidebar): 修复 Windows 下拉菜单改名无响应 - #423
Merged
su-fen merged 2 commits intoAug 10, 2026
Merged
Conversation
会话与工作空间通过下拉菜单进入改名时,Base UI关闭菜单会归还焦点并触发输入框首次blur,导致原标题立即提交、编辑状态退出。 仅对菜单触发的改名忽略这次焦点交接,保留双击改名和正常失焦提交行为;补充源码回归测试。 验证:TypeScript类型检查通过;sidebar-selection测试8/8通过;目标UI文件Biome检查通过。Vite完整构建因执行工具30秒上限未完成。
StackCairn
marked this pull request as draft
August 10, 2026 13:23
Contributor
|
PR governance checks failed.
Fix the items above — pushing new commits or editing the PR body will re-run the checks. |
吞 blur 的 ignoreMenuCloseBlurRef 守卫没有时间边界:在 menu-close blur
不会发生的平台(macOS/WebUI)上标志位会悬留整个改名过程,把用户第一次
真实的外部点击吞掉(不提交、焦点被抢回并全选)。
改为 Base UI Menu.Popup 的声明式出口:菜单入口置位一次性标志,
finalFocus 回调在菜单关闭时(必然发生)消费它并返回 false,从源头不再
排队任何 return-focus;其余菜单关闭路径保持默认的 trigger 回焦。onBlur
恢复原始语义(skip 一次或提交),无悬留状态。
没有直接用 finalFocus={inputRef}:FloatingFocusManager 在卸载 cleanup
里同步解析返回元素(React mutation 阶段,先处理删除),此时新挂载输入
框的 ref 尚未附着(layout 阶段才附着),ref 会解析为 null 并静默回退到
默认行为,Windows 上 bug 依旧。函数形式返回 false 不需要元素,无此时序
问题。
su-fen
approved these changes
Aug 10, 2026
su-fen
marked this pull request as ready for review
August 10, 2026 14:08
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linked issue
Closes #415
Summary
Windows 桌面端从会话(和工作空间)的下拉菜单里点「修改标题」,输入框会瞬间闪现后立刻退回原标题,表现为「改名无响应」。
根因是焦点交接,不是菜单没触发。行在
isRenaming翻转时把整个 trigger 子树换成了重命名输入框,而 Base UI 的FloatingFocusManager在菜单卸载时会在一个 microtask 里把焦点还给 trigger;此时 trigger 已随子树卸载(domReference?.isConnected === false),焦点落到回退元素上,把刚聚焦的输入框 blur 掉,onBlur于是用未改动的原标题调用了onCommitRename()并退出编辑态。修复把「菜单入口改名」和「双击改名」拆成两个 handler,只有菜单入口会置位
ignoreMenuCloseBlurRef,让输入框吞掉这一次由菜单关闭引发的 blur 并重新聚焦;双击改名和正常失焦提交的行为不变。会话行和工作空间行走同一套下拉菜单,两处都改了;移动端长按/右键复用同一菜单,一并覆盖。Change scope
crates/agent-ui/src/components/chat/ChatHistorySidebar.tsx—HistoryRow与ProjectRow各新增ignoreMenuCloseBlurRef守卫和handleStartRenamingFromMenucrates/agent-gui/test/chat/sidebar-selection.test.mjs— 新增 1 条回归用例Screenshots / preview
暂缺。本次改动的验证是自动化检查(见下),未附运行时录屏——按模板规则这会使 PR 自动转为 draft,补录后再转正式。改动是纯焦点时序修复,无视觉变化,人工验证路径为三条:菜单改名、双击改名、点击输入框外提交。
Verification
全部在本机复跑通过:
pnpm --dir crates/agent-gui exec tscnode --test test/chat/sidebar-selection.test.mjspnpm test:guipnpm test:webuipnpm build:gui(tsc + vite)pnpm build:webuinode scripts/check-ui-boundaries.mjspnpm lint:guiChatHistorySidebar.tsxpnpm lint:ui报 2 个 error,位于WorkspaceResourceSettingsDrawer.tsx和ResourceActivationSwitch.tsx;git diff确认这两个文件本次未改动,属既有问题,不在本 PR 范围内。给 reviewer 的两点说明
ignoreMenuCloseBlurRef只在首次 blur 或isRenaming变 false 时清除。Base UI 的 return-focus 有前置条件(回退元素需已连接且可聚焦),若该条件不满足就不会产生那次 blur,标志位会一直保持到本次改名结束,从而吞掉用户真实的首次外部点击(不提交、焦点被抢回并全选)。Enter/Escape 不受影响,再点一次也能提交,属可恢复降级。更稳妥的做法是改用 Base UI 声明式出口Menu.Popup的finalFocus(DropdownMenuContent已透传 props,传finalFocus={inputRef}可从源头消除这次交接),如 reviewer 倾向该方案我可以改。test/settings/git-review-menu-position.test.mjs等约 30 处沿用同一约定,所以这是既有做法而非本 PR 引入;但它挡不住上面第 1 点的场景,也会被无害的格式改动碰红。Pre-submit checklist