Skip to content

fix: 修复固定标签触发 LRU 淘汰或分屏初始化后消息区空白问题 - #1830

Merged
qqqqqf-q merged 1 commit into
mainfrom
fix/memoh-335-keepalive-evicted-chat-view
Nov 22, 2026
Merged

qqqqqf-q merged 1 commit into
mainfrom
fix/memoh-335-keepalive-evicted-chat-view

Conversation

@qqqqqf-q

Copy link
Copy Markdown
Member

Author

  • Human
  • Agent

Type

  • bug
  • feat
  • test

Summary

问题

  1. 固定标签页触发 LRU 淘汰后切回黑屏:view-registry.ts 中存放会话视图的 views 使用了原生非响应式 Map。当某个已打开的聊天标签隐藏在后台由 <KeepAlive> 保活,用户在其他标签连续浏览超过 12 个会话(CHAT_SESSION_VIEW_CACHE_LIMIT = 12)触发 LRU 淘汰时,旧 ChatViewEntry 被清空并从 Map 删除;再次切回原标签时,由于 botId / sessionId / viewId 均未变化,ChatPane 的 paneView 计算属性不会重新求值,持续引用已被清空的旧对象,而新拉取的历史消息写入了新建的 ChatViewEntry,导致消息区一片空白(关闭标签页销毁组件重开后才恢复)。
  2. 分屏可见会话在初始化重连后悬空空白:冷启动或切换 Bot 执行 initialize() 时,stopStreams() 会中止所有已恢复分屏面板在途的初始历史加载,但 initialize() 结束时只为当前焦点所在的单个 sessionId 调用 startSessionRuntime,导致其余可见分屏会话停留在未初始化的空白态。

修复

  1. 将 view-registry.ts 中的 views 改为 shallowReactive(new Map<string, ChatViewEntry>()),按单个会话 key 建立浅层响应式依赖:被淘汰并重建的会话在标签重新激活时会自动重绑到新的 ChatViewEntry,同时既不递归代理条目内部属性,也不会触发其他未变动面板的多余重算。
  2. 在 view-registry.ts 提供 visibleSessionIds(botId),并在 bootstrap.ts 的 initialize() 完成 WebSocket 启动后,为当前 Bot 下所有处于可见状态的会话视图恢复 startSessionRuntime。

Related Issues

Validation

自动化检查

  • pnpm vitest run apps/web/src/store/chat/view-registry.test.ts apps/web/src/store/chat/bootstrap.test.ts apps/web/src/store/chat/cache-revisit.test.ts apps/web/src/store/chat-list.test.ts:167/167 全部通过(含新增的隐藏标签淘汰重建重绑与单 key 隔离测试、分屏可见会话初始化恢复测试)。
  • node scripts/check-ui-contract.mjs:通过。
  • pre-commit Web lint(eslint):通过。
  • 未执行:全仓 mise run lint 与后端测试未在本地全量运行(本次仅改动 apps/web),由 CI 覆盖。

Agent 本地运行与真实界面验证(非真人 QA)

  • 环境:本地 memoh-dev 后端(127.0.0.1:18080)+ 修复前前端(localhost:18082)与本分支前端(http://127.0.0.1:8084)。
  • 复现与验证步骤:在拥有 >15 个历史会话的 Bot 中,右键将一条有消息的会话打开为固定标签页(渲染消息数 2 条),随后在预览标签页依次点击另外 15 个不同会话以触发 12 条上限的 LRU 淘汰,最后切回原固定标签页。
    • 修复前:切回后消息区空白,[data-message-id] 数量从 2 变为 0。
    • 修复后:切回后自动重绑并完整渲染原对话,[data-message-id] 数量保持为 2。

Screenshots / Recordings

修复前(触发 12 会话 LRU 淘汰后切回固定标签,消息区空白)

修复前:LRU 淘汰后切回固定标签黑屏

修复后(相同操作路径切回固定标签,正常重绑并渲染对话)

修复后:切回固定标签正常渲染消息

Human QA

  • Human QA passed

@github-actions github-actions Bot added bug Fixes a bug or unexpected behavior change:web Changes web frontend or shared frontend packages size:S PR size uses the larger of added or deleted lines, excluding generated files labels Nov 22, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T10:50:30.682677Z 07589bd PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@qqqqqf-q
qqqqqf-q merged commit 837bdd9 into main Nov 22, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Fixes a bug or unexpected behavior change:web Changes web frontend or shared frontend packages size:S PR size uses the larger of added or deleted lines, excluding generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant