Repository navigation
fix(sidebar): 底部面板按钮与右侧栏共存(去掉 500ms 采样导致的闪烁) - #1019
eleven-lings wants to merge 1 commit into
Conversation
|
同类的最小修法 #1053 已合入 dev(删掉 |
|
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. |
Refs #290
Refs #989
Refs #992
现象
根因
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。动画中途采到的仍是旧值 → 按钮整段动画期间都在,动画结束后下一拍才消失;收起时某个拍点先读到「已收起」→ 按钮提前闪回来一拍再消失。改动
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,动画收尾再读一次。属性一变答案就落在当帧。POLL_MS500 → 1500,只服务「观察者拿不到信号」(宿主改名/搬家)。推送式不变:答案没变时不写open、不广播。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),是流式排布,不会绝对定位去撞宿主。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=不隐藏)、引用计数与「页面隐藏时不建设备」这些既有契约全部保留。dock-fallback的 blank 会话判定、会话头入口链路都不变。