Skip to content

fix(sidebar): 底部面板按钮与右侧栏共存(去掉 500ms 采样导致的闪烁) - #1019

Closed
eleven-lings wants to merge 1 commit into
omdsh-dev:mainfrom
eleven-lings:fix/bottom-toggle-coexist
Closed

eleven-lings wants to merge 1 commit into
omdsh-dev:mainfrom
eleven-lings:fix/bottom-toggle-coexist

Conversation

@eleven-lings

Copy link
Copy Markdown
Collaborator

Refs #290
Refs #989
Refs #992

现象

  1. 右侧栏展开后,底部工作台的入口直接消失 —— 于是只能「先开底部面板、再开右侧栏」,反过来做不了。
  2. 展开动画结束后按钮才突然消失 / 收起时先闪回来一拍 —— 不是跟动画走,是跟采样拍点走。

根因

  • src/client/Sidebar.tsx 的 BottomDockToggle 开头一句 if (useRightPanelOpen()) return null,右侧栏展开就整个不渲染;dock-fallback.tsx 的 rendered 里又额外挡了一道 !rightOpen。
  • src/client/sidebar/right-panel-open.ts 只有一条 POLL_MS = 500 的 setInterval 采样:readRightPanelOpen() 每次两趟全文档 querySelectorAll + 对命中的元素 getBoundingClientRect/getComputedStyle。动画中途采到的仍是旧值 → 按钮整段动画期间都在,动画结束后下一拍才消失;收起时某个拍点先读到「已收起」→ 按钮提前闪回来一拍再消失。

改动

  1. 事件驱动替代采样(right-panel-open.ts):0 → 1 个订阅者时建 MutationObserver,只盯 data-sidebar-right-expand / data-sidebar-right-toggle / style / class / hidden 这些真正决定可见性的属性(attributes + attributeFilter),外加 childList + subtree 覆盖宿主整块换控件;同时在 document 捕获阶段监听 transitionend / animationend,动画收尾再读一次。属性一变答案就落在当帧。
  2. 兜底采样保留但降频:POLL_MS 500 → 1500,只服务「观察者拿不到信号」(宿主改名/搬家)。推送式不变:答案没变时不写 open、不广播。
  3. 按钮与右侧栏共存(Sidebar.tsx):去掉 return null,改为带 data-right-open 标记;sidebar.module.css 里 .toggleButton[data-right-open='true'] 让出右侧间隔,不去压宿主那一簇 Split / Fullscreen / Collapse 控件。入口本身注册在 session header 的 utilities 列(sidebar/bottom-toggle.tsx),是流式排布,不会绝对定位去撞宿主。
  4. 备用入口同样放开(dock-fallback.tsx):rendered 里的 !rightOpen 去掉,位置继续由 measure() 的「向左逐步探空位」负责(slotFree 已按 5 点采样,避免只测中心点压住邻居)。

测试

  • tests/right-panel-open.spec.tsx:新增「宿主属性变化后不等兜底 tick 就更新」(断言 open 立刻为 true 且确实发生了一次文档读取)、「animation settle(transitionend)触发重读」(属性不动、仅事件也能把答案拉回 false)。
  • tests/dock-fallback.spec.tsx:原用例「renders no entry while the host right panel is expanded」改为「keeps the entry while the host right panel is expanded」,断言入口仍在、且带 data-right-open='true'。

未执行本地测试:本环境 pnpm install 反复超时,装不上依赖,因此没有拿到 vitest 的真实红灯/绿灯结果;上述测试是按仓库既有 spec 的风格(@vitest-environment jsdom + 账本式 interval mock + 手动触发事件)写的,请 CI 复核。这一点如实说明,不做任何通过性声明。

影响面 / 破坏性变更

  • 无破坏性变更:readRightPanelOpen 的判定语义、失败方向(宿主改属性名时读成 false=不隐藏)、引用计数与「页面隐藏时不建设备」这些既有契约全部保留。
  • 副作用是右侧栏展开时这个入口会出现(此前是隐藏),这正是本 PR 的目的;dock-fallback 的 blank 会话判定、会话头入口链路都不变。

@eleven-lings eleven-lings added area/sidebar Sidebar shell, panels, layout, tabs, workspace windows bug Something isn't working P2 中:一般功能/优化 labels Oct 20, 2026
@Menghuan1918

Copy link
Copy Markdown
Collaborator

同类的最小修法 #1053 已合入 dev(删掉 Sidebar.tsx 的 if (useRightPanelOpen()) return null 早退,保留 500ms 采样,带 tests/bottom-toggle.spec.tsx),所以 UX 部分不再需要这一笔。你把采样换成 MutationObserver 的方向和仓库稳态目标一致,但当前 CI 在 tests/steady-state.spec.tsx 红——入口现在只经宿主 slot(src/client/sidebar/bottom-toggle.tsx)挂载,500ms 表计数需要连测试夹具一起重锚;另外隐藏时拆观察者与「不停事件驱动刷新」冲突,observer 监听 body subtree + 全部 transition 未合帧,成本更高。建议拆成纯 perf PR:回退 dock-fallback / CSS 改动,只保留 right-panel-open.ts + spec,补上 steady-state 门禁重锚与 rAF 合帧。感谢!

Menghuan1918 added a commit that referenced this pull request Oct 26, 2026
- CHANGELOG: add the #992 dock-fallback entry
- docs/plans: scan inventory, per-batch merge/close evidence, deferred PR
  verdicts (#1040 #1019 #1048), gates and known local flakes
- issue-triage: #983/#992/#1059 are dev-fixed pending release
@Menghuan1918

Copy link
Copy Markdown
Collaborator

The UX half is superseded by #1053: BottomDockToggle no longer returns null while the right panel is open, so the entry coexists. The remaining event-driven right-panel polling is a perf follow-up and this branch is conflicting/CI red. Closing; a focused perf PR is welcome. Thanks @eleven-lings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/sidebar Sidebar shell, panels, layout, tabs, workspace windows bug Something isn't working P2 中:一般功能/优化

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants