Files
mnote/bugs/03-rust-web/done/3-26-sidebar-dev-hot-reload-setinterval-v1.md
lix-2026 1882db7681 收口 MNote P0 P1 P2 审查尾项
- 归档 OnlyOffice live bridge、Page AI、mindmap、design governance 与相关 bug 条目
- 补齐 MinerU OCR 后端 runtime 合同与 smoke/test 基线
- 收口 ChatOnly/Doubao、ObjectIdentity、Page Aggregate compat 与 runtime owner 文档口径

验证:
- cargo test --manifest-path rust/Cargo.toml -p mnote-web local_ocr -- --test-threads=1
- cargo test --manifest-path rust/Cargo.toml -p mnote-web onlyoffice_bridge -- --test-threads=1
- git diff --check
- git diff --cached --check
- codegraph index . --force && codegraph status .
- codegraph sync . && codegraph status .
2026-06-01 09:29:12 +08:00

47 lines
2.6 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 3-26 Sidebar dev hot reload 在主 runtime 中使用 setInterval
## 状态
- 状态:done
- Owner03-rust-web / browser runtime
- 发现时间:2026-05-31
## 现象
`sidebar-tree-runtime.js` 在主 Sidebar runtime 中安装 dev hot reload,并无前置环境 guard 地执行 `window.setInterval(tick, 1000)`。项目架构约束要求浏览器主链默认禁止新增基于 `setInterval`、周期 `setTimeout` 或轮询 fallback 的数据刷新和状态同步;即使这是 dev hot reload,也应该显式限制在 debug/dev 边界。
## 证据
- `rust/crates/mnote-web/browser/sidebar-tree-runtime.js``installMnoteDevHotReload()` 执行:
- 先调用 `tick()`
- 再执行 `timer = window.setInterval(tick, 1000)`
- 末尾无条件调用 `installMnoteDevHotReload()`
- `tick()` 每次请求 `/api/dev/hot-reload`,服务端返回 `enabled !== true` 时才清理 timer;这仍意味着页面启动后先进入轮询逻辑。
## 影响
- 主 Sidebar runtime 默认携带 dev 轮询逻辑,和“主链不叠加轮询 fallback”的架构约束冲突。
-`/api/dev/hot-reload` 异常或返回形态变化,可能引入重复请求、console 噪音或性能误判。
- 后续 worker 可能把这种模式复制到其他可见路径。
## 修复建议
- 在 Rust SSR bootstrap 中显式注入 dev/hot 模式标记,只有 dev hot 模式启用时才安装该逻辑。
- 或将 hot reload 逻辑迁到 debug/internal runtime,不放在默认 Sidebar runtime。
- 如果仍保留定时器,必须在设计/注释中说明退出条件和边界,并保证生产/普通 desktop 模式不可达。
## 本轮进展
- 2026-05-31
- `sidebar-tree-runtime.js` 已改为通过 `import.meta.url` 检查当前模块 URL 是否携带 `devHot` cache buster;只有 dev hot 模式才安装 hot reload 轮询。
- 已补 `layout.rs` 静态断言,禁止无条件 `installMnoteDevHotReload()` 回流。
- 已通过 `node --check rust/crates/mnote-web/browser/sidebar-tree-runtime.js` 和 Rust 定点测试。
- 已补 `scripts/task514-sidebar-dev-hot-reload-gating-smoke.js` 固化真实浏览器验证。
- 验证通过:`node scripts/task514-sidebar-dev-hot-reload-gating-smoke.js`。结果显示普通入口 `hotReloadRequestCount=0``scriptHasDevHot=false`hot 模式 `scriptHasDevHot=true``hotReloadRequestCount=2``data-mnote-dev-hot-reload=enabled`,且无 console/network 错误。
## 验收
- [x] 普通 `desktop` / 非 hot 入口打开后,浏览器不会请求 `/api/dev/hot-reload`
- [x] `npm run desktop:hot` 或等价 hot 模式下仍能刷新。
- [x] `setInterval(tick, 1000)` 仅在 `mnoteDevHotReloadEnabled()` guard 后可达。