Files
mnote/bugs/05-editor-mainline/done/2026-05-27-starred-scoped-file-open-reloads-sidebar.md

2.9 KiB
Raw Permalink Blame History

星标 scoped 文件夹打开 Markdown 会重载并重建 FileTree

状态:done Owner05-editor-mainline / 03-rust-web 发现日期:2026-05-27 来源:用户反馈 / Sidex Explorer 行为对照

现象

从“星标置顶”点击本地文件夹 design 后,继续在 scoped FileTree 中打开任意 .md 文件,页面会明显卡顿,表现为侧栏重新构建、文件树重新加载。用户在 localhost 下也能感到卡顿,远程延迟时更明显。

根因

这次实际有三条慢链路叠在一起:

  1. navigateToDocument(...)fileTreeScope 存在时绕过 window.__mnoteDocumentPaneRuntime.openPrimaryDocument(...),直接走 window.location.assign(...)。因此 scoped 文件树中打开 Markdown 不是 pane 内导航,而是整页 SSR reload。
  2. scoped 模式收到 root live snapshot 时,renderLiveSidebarSnapshot(...) 会调用 refreshLocalFolderSidebarSnapshot(),兜底重拉 scope 根 projection。
  3. tree live disabled / fallback polling 模式下,coarse /api/tree/local-folder-watch revision 变化会整刷 scoped FileTree;普通 Markdown mount 时,旧 healLegacyOfficeAttachmentParagraphs() 也会为了 legacy office 附件兼容拉 workspace root projection。

Sidex / VSCode Explorer 的对齐原则是:打开文件只切换 editor/input 和 selection,不重建 Explorer 数据源;Explorer 的 scoped/root view state 与文件打开解耦。

修复

  • 允许 scoped FileTree 打开 Markdown 时继续走 openPrimaryDocument(...) pane 内导航。
  • URL 仍保留 fileTreeScope,因此刷新页面时仍能恢复 scoped Explorer。
  • scoped 模式收到非当前 scope 的 root snapshot 时只标记忽略,不再兜底重拉 scope 根。
  • fallback polling 发现 coarse root revision 变化时,对 scoped FileTree 只标记 scope_stale,不做即时 scope refresh。
  • legacy office 附件兼容逻辑先检查 DOM 中是否存在“单段 office 文件名”候选;普通 Markdown 不再触发 workspace root projection。
  • task494-filetree-lazy-loading-dedup-smoke.js 增加回归:点击 scoped 中已可见 Markdown 后,页面 JS marker 必须保留,且不应再次请求 scope 根 projectionroot snapshot / coarse watch revision 也不得重拉 scope 根。

验证

  • node scripts/task494-filetree-lazy-loading-dedup-smoke.js 先失败于 marker 被整页 reload 清空,修复后通过。
  • node scripts/task494-filetree-lazy-loading-dedup-smoke.js 继续失败于 scoped root snapshot 和 coarse watch revision 重拉 scope 根,修复后通过。
  • 真实 /mnt/Data1T/mnote/design/05-editor-mainline/process/5-32-filetree-lazy-loading-sidex-alignment-v1.md 链路验证通过:scopeRootRequests=0workspaceRootRequests=0childrenRequests=2,请求只剩 design/05-editor-mainlinedesign/05-editor-mainline/process 两个必要 children projection。