Files
mnote/bugs/05-editor-mainline/done/5-12-page-options-refresh-runtime-attrs-v1.md
T
lix-2026 f292c6710a feat: EditorRuntimeActor - 三层缓存/delta/事件架构
Phase A — EditorRuntimeActor 内存缓存层
- 新增 editor_actor.rs: EditorBlockDocument 内存态 + apply_command + load_or_init
- block.rs 四个写工具(replace/insert/delete/move)接入 actor 路径
- editor_actor feature flag(MNOTE_WEB_ENABLE_EDITOR_ACTOR=true 默认开启)
- bridge-runtime 三个核心函数公开化
- rust-toolchain: 1.89 → stable(修复 spike WASM 编译阻塞)

Phase B — 编辑器增量 delta channel
- BlockDelta/DeltaOperation 类型 + actor.build_block_delta()
- leptos-tiptap spike: mnote:editor:block-delta CustomEvent 监听 + JSON patch
- DocumentAiAgentPanel: 拦截 blockDelta → window dispatchEvent
- 工具响应含 blockDelta 字段供前端消费

Phase C — 事件 stream delta
- broadcast channel 在 AppState/actor/SSE 三层贯通
- tree_events SSE 端点发 block.delta 事件
- 旧客户端降级兼容

环境修复
- rustc recursion_limit = 1024(修复 Leptos SSR 类型深度溢出)
- run-convex-deploy.js(封装 Convex function 部署到本地后端 3210)

ref: design/07-ai/process/7-13-page-block-editor-runtime-actor-v1.md
2026-05-16 22:03:30 +08:00

69 lines
3.3 KiB
Markdown
Raw 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.
# 5-12 [done][bug] 页面设置刷新后 runtime 属性回退 v1
> 更新时间:2026-05-16
>
> 分类归属:
> - `05-editor-mainline/done`
> - 涉及边界:`Page Aggregate / Rust Web document shell / leptos-tiptap island runtime page options`
## 1. 问题定义
在 Page Aggregate 单一真源验收中,同一临时页写入标题、正文和页面设置后,`/api/page-aggregate/:id` 已能回读最新 `layout.pageOptions`,刷新后的 `.document-shell` 也保留 `wideLayout=true / smallText=true / layoutDensity=compact`
但首轮综合 smoke 发现,刷新后 `document.documentElement` 上的 `data-page-wide-layout / data-page-small-text / data-layout-density` 仍可能是默认值,island root 上也缺少对应 runtime 属性。该问题会让页面设置的部分 runtime DOM 层与 Page Aggregate / SSR 壳层不一致。
## 2. 复现步骤
1. 启动 `http://127.0.0.1:3000`
2. 新建临时页面。
3. 通过页面头写入唯一标题。
4. 通过主编辑器写入唯一正文。
5. 通过页面设置 UI 写入 `wideLayout=true``smallText=true``layoutDensity=compact`
6.`/api/page-aggregate/:id` 回读最新标题、正文和页面设置。
7. 刷新页面后检查 `documentElement``.document-shell`、island root 和 `.editor-surface` 的 runtime page option 属性。
## 3. 根因
`rust/crates/mnote-web/src/ssr/pages/layout.rs``initializePageUiSurfaces` 原先通过 `setTimeout(initializePageUiSurfaces, 0)` 调度。
在文档页加载时,这个调用可能早于嵌入的 `__MNOTE_PAGE_AGGREGATE__` JSON 脚本和 island DOM 完整可用,导致 `applyPageOptionsToShell()` 读取到默认 pageOptions,或只更新了部分 DOM 层。后续 SSR 壳层仍显示最新值,但 `documentElement` 和 island root 可能保持默认属性。
## 4. 修复
`rust/crates/mnote-web/src/ssr/pages/layout.rs` 新增 `scheduleInitializePageUiSurfaces()`
- 如果 `document.readyState === "loading"`,等 `DOMContentLoaded` 后再 `setTimeout(initializePageUiSurfaces, 0)`
- 如果文档已经可用,保持原有异步调度。
这样初始化会在 Page Aggregate JSON 与文档 DOM 解析完成后再应用 page options。
## 5. 验证
真实 3000 smoke
```bash
MNOTE_UI_BASE_URL=http://127.0.0.1:3000 node scripts/task-page-aggregate-refresh-persistence-smoke.js
```
证据:
- `tmp/page-aggregate-refresh-persistence-smoke/mp88fr6k.json`
- `tmp/page-aggregate-refresh-persistence-smoke/mp88fr6k.png`
- `tmp/page-aggregate-refresh-persistence-smoke/latest.stdout.json`
验证结果:
- 刷新前后 `head.title=Page Aggregate refresh mp88fr6k`
- 刷新前后 `body.revision=1``conflictDetectionKey=tree_1778929070007_1:1`
- 刷新前后 `blockDocument.blocks[0].text=Page Aggregate refresh body mp88fr6k`
- 刷新前后 `layout.pageOptions.wideLayout=true``smallText=true``layoutDensity=compact`
- 刷新后页头、`.ProseMirror` 正文、设置控件、`documentElement``.document-shell`、island root 和 `.editor-surface` 均保持最新值。
配套命令:
```bash
node --check scripts/task-page-aggregate-refresh-persistence-smoke.js
cargo test --manifest-path rust/Cargo.toml -p mnote-web page_aggregate
cargo test --manifest-path rust/Cargo.toml -p mnote-web documents_options_route_executes_page_layout_update_options
```