fix: 回应 Codex 审查的 4 条意见(2×P1 + 2×P2)

- P1 state.ts reduceFor:恢复共享 uid 计数器到调用前水平(目标 session 的
  max 可能低于激活 session 已用 id,否则下次 mint 撞 id 损坏布局);
  回归测试实证:无修复时 split 产生重复 pane id
- P1 service.ts 生命周期分类:dedupe 聚焦判定改为基于输入态的存在性
  (dedupeKey 匹配或 id 匹配都算聚焦)——按 path 去重 + 新 id 打开时
  不再对从未插入的幽灵 tab 触发 onOpen(资源泄漏源)
- P2 SideCardSection:乐观 prefs ref(optimisticRef)驱动嵌套 map 合并
  (tabsEnabled/viewersEnabled/pluginSettings),同 tick 多次写入不再
  互相丢弃;mergePluginSetting 抽纯函数 + 单测
- P2 state.ts schedulePersist:每 session 独立防抖定时器(persistTimers
  Map),定向打开不再取消其他 session 的待写;单测验证双写都落盘
This commit is contained in:
Menghuan1918
2026-08-14 21:13:53 +08:00
parent ced3a1eade
commit 319d34ed09
6 changed files with 190 additions and 19 deletions
+16 -5
View File
@@ -543,13 +543,24 @@ export function createBetterSidebarService(store: SidebarStore): BetterSidebarSe
landed = next
}
// Lifecycle capture (before the auto-expand block, which early-returns).
if (!tabOpenIn(state, tab.id)) {
// Classify the landing against the INPUT state: a FOCUS fires
// onActivate with the tab that is active NOW; a real creation fires
// onOpen with the minted tab. Both the dedupeKey match AND the id
// match count as a focus — a descriptor deduping by key (e.g. editor
// by path) can focus an existing tab for a NEW requested id, and
// classifying that as a creation would fire onOpen with a phantom
// tab that never closes.
const dedupeKey = descriptor.dedupeKey ?? (descriptor.single === true ? () => descriptor.id : undefined)
const key = dedupeKey?.(tab)
const inputTabs = allLeaves(state.splits).concat(allLeaves(state.bottomSplits)).flatMap(leaf => leaf.tabs)
const existedByKey = key !== undefined
&& inputTabs.some(candidate => candidate.type === tab.type && dedupeKey!(candidate) === key)
const existedById = tabOpenIn(state, tab.id)
if (!existedByKey && !existedById) {
created = tab
} else {
// A focus happened (dedupeKey or the id safety net): resolve the
// tab that is actually active now and report THAT to onActivate.
const dedupeKey = descriptor.dedupeKey ?? (descriptor.single === true ? () => descriptor.id : undefined)
const key = dedupeKey?.(tab)
// A focus happened: resolve the tab that is actually active now and
// report THAT to onActivate (never the caller's un-inserted seed).
const candidates = allLeaves(landed.splits).concat(allLeaves(landed.bottomSplits)).flatMap(leaf => leaf.tabs)
activated = key !== undefined
? candidates.find(candidate => candidate.type === tab.type && dedupeKey!(candidate) === key)