From 118482b13660f1617a9b34b3208b4392c56322dd Mon Sep 17 00:00:00 2001 From: qiqi Date: Fri, 4 Dec 2026 15:55:02 +0800 Subject: [PATCH] =?UTF-8?q?fix(save):=20=E8=90=BD=E5=AE=9A=E7=AA=97?= =?UTF-8?q?=E5=8F=A3=E5=86=85=E7=9A=84=E7=BC=96=E8=BE=91=E4=B8=8D=E5=86=8D?= =?UTF-8?q?=E9=9D=99=E9=BB=98=E4=B8=A2=E5=A4=B1=EF=BC=88=E5=90=AF=E5=8A=A8?= =?UTF-8?q?/=E5=88=87=E7=94=BB=E5=B8=83/=E5=90=8C=E6=AD=A5=201.2s=20?= =?UTF-8?q?=E5=86=85=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 7 ++++ CONTRIBUTING.md | 4 +- app.js | 5 ++- docs/standards/architecture-current-state.md | 2 +- package.json | 2 +- tests/canvas-save-settle-test.js | 41 ++++++++++++++++++++ tests/source-text-ratchet-test.js | 2 +- 7 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 tests/canvas-save-settle-test.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 7653297..e413a39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,13 @@ - 改 URL 时一并清掉旧网络图的 localRef/ref,避免回车后仍显示上一张 - 守卫同步:网络图缓存后仍保留 URL 行 / 本地图不渲染 +### v3.26.248 补记(2026-12-05)启动落定窗口内的编辑不再丢失 + +- 现象:启动后(loaded=false)或切画布/同步后 1.2s(refs.syncing=true)内的第一次编辑被静默丢弃 —— 界面已改、文件 mtime 不变,落定后再改才正常 +- 根因:保存 effect 在这些状态下走 else 分支,且只在 refs.savePending 已为 true 时才补排;而 savePending 只在 saveDebounced 内被置位,第一次编辑前它是 false;skipInitialPersistence 又把载入后那一次保存跳过 +- 修法:commitCanvas 在未落定时打标 dirtyBeforeSettle;保存 effect 在 loaded && !syncing 时补一次 saveDebounced;切画布/同步的 1.2s 定时器结束时同样补一次(syncing 非响应式,不会重跑 effect) +- 守卫:tests/canvas-save-settle-test.js(旧实现必红);Workbench 行数棘轮 2,706 → 2,709(+3,时序逻辑依赖 loaded/syncing,抽不走) + ## v3.26.247(2026-12-04)修存储写盘通道被永久卡死(画布改动重启即丢) - 根因:244 的「内容未变不写盘」让启动那次 flush 变全同步,`writing = (async(){…finally{writing=null}})()` 在函数体没有 await 时先执行 finally、再被赋值成一个永不清理的已解决 promise ⇒ 之后每次 flush 都直接 return,整个会话不再写盘(画布/设置/图库索引全停写) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ad2ffcd..cf2a678 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -41,7 +41,7 @@ build esbuild 打包到 dist/(单 dist/app.js = src/ 模块按序 node --check app.js 与 dist/app.js 语法 check-dist.js 产物体检 lint ESLint(src/ + app.js,正确性规则) -test:unit 144 个单测文件(jsdom 契约测试;2026-11-07 新增 sync-facts-guard(事实一致性)/ _helpers/source(统一源文本);2026-11-12 新增 provider-ping(测速 no-cors 兜底)) +test:unit 145 个单测文件(jsdom 契约测试;2026-11-07 新增 sync-facts-guard(事实一致性)/ _helpers/source(统一源文本);2026-11-12 新增 provider-ping(测速 no-cors 兜底)) test relay-task-graph-fixture + iwb-v32-web-test test:facts 事实基线守门(见 §5) typecheck 渐进类型检查(tsc --noEmit;范围 = src/*.js,不含 app.js) @@ -106,7 +106,7 @@ IWB_WRITE_BOUNDARY_SNAPSHOT=1 node tests/architecture-boundary-guard-test.js # | 守卫 | 位置 | 现在的上限 | |---|---|---| | `app.js` 总行数 | `tests/source-text-ratchet-test.js` `MAX_APP_JS_LINES` | **9,529**(另守「占总源码 ≤ 40%」,见 `MAX_APP_JS_SHARE`) | -| `Workbench()` 行数 | 同上 `MAX_WORKBENCH_LINES` | **2,706** | +| `Workbench()` 行数 | 同上 `MAX_WORKBENCH_LINES` | **2,709** | | 单组件行数(不含 Workbench)| 同上 `MAX_APP_COMPONENT_LINES` | **423** | 三条都是**只减不增**。确需在 app.js 增长时,必须**同步上调上限并在 commit 里写理由**(等于显式记账,不会悄悄发生)。 diff --git a/app.js b/app.js index 0dc71a4..b15d6ae 100644 --- a/app.js +++ b/app.js @@ -6858,6 +6858,7 @@ const tbCenterSeed = (type, refs) => { runWorkspaces: new Map(), genScheduler: { active: 0, queue: [], external: null }, skipInitialPersistence: true, + dirtyBeforeSettle: false, // 2026-12-05:落定前的真实改动,落定后补存(见 tests/canvas-save-settle-test.js) // 跨渲染稳定的计时器句柄:用 per-render 的局部 let 会清不掉上一次渲染设下的定时器 toastTimer: null, saveTimer: null, typingTimer: null, // Ctrl+Shift+V 的按下时间窗:吞掉浏览器随后派发的 paste(Chrome 会以纯文本形式触发) @@ -7118,6 +7119,7 @@ const tbCenterSeed = (type, refs) => { }, } const commitCanvas = (nextNodes, nextEdges, nextGroups) => { + if (!(loaded && !refs.syncing)) refs.dirtyBeforeSettle = true iwbDebugCounter('commitCanvas', { nodes: nextNodes !== undefined ? nextNodes.length : refs.nodes.length, edges: nextEdges !== undefined ? nextEdges.length : refs.edges.length, @@ -7272,7 +7274,7 @@ const tbCenterSeed = (type, refs) => { else doFit(ns) } } - setTimeout(() => { refs.syncing = false }, 1200) + setTimeout(() => { refs.syncing = false; if (refs.dirtyBeforeSettle) { refs.dirtyBeforeSettle = false; saveDebounced() } }, 1200) } // 工作区列表写回族(persistWs / duplicateWs)已搬到 src/runtime-workbench-logic.js(2026-11-16 棘轮腾位)。 // 每渲染重建一次,语义与原 const 一致;activeWsId/wsRev 取当次渲染值,与原来闭包捕获的完全一样。 @@ -7594,6 +7596,7 @@ const tbCenterSeed = (type, refs) => { if (loaded && !(refs.syncing)) { if (refs.skipInitialPersistence) refs.skipInitialPersistence = false else saveDebounced() + if (refs.dirtyBeforeSettle) { refs.dirtyBeforeSettle = false; saveDebounced() } } else if (refs.savePending) { // 下面的 cleanup 会取消已排定的保存定时器,而此刻又不能落盘(尚未 loaded,或正在应用远端同步)。 // 必须把这次保存重新排上,否则用户的改动会被静默丢弃。 diff --git a/docs/standards/architecture-current-state.md b/docs/standards/architecture-current-state.md index ed02ace..81b9d82 100644 --- a/docs/standards/architecture-current-state.md +++ b/docs/standards/architecture-current-state.md @@ -22,7 +22,7 @@ - 图片**新写入主通道 = IndexedDB Blob `{__blob}` / key `imgblob__`** (A) `app.js:2143`;`{__cache}`(Cache Storage)为兜底;\`ref_\`(`app.js` 内定义的 `IDB_REF_PREFIX = 'ref_'`)为 legacy 形态 (A)。 - 大图判定:`isBigDataUrl` = `data:` 且 `length > 3000` (A) `app.js:2018`;**画布保存保留阈值** `< 16384` 才原样保留 (A) `app.js:2182`。**两处阈值并存,含义不同**。 - 单测是**源码契约测试**:`tests/` 目录共 **493** 处源码文本钉点(`source.includes` / `source.indexOf` / `/re/.test(source)`),分布在 **20** 个文件(其中 `iwb-v32-web-test.js` 一个就占 **407**)→ **结构性重构会先打红测试**。**该数字已由 `tests/source-text-ratchet-test.js` 的「只减不增」棘轮守门**(2026-10-20 起守卫范围从 1 个文件扩到全目录:新增任何一处源码文本钉点都会打红)。**2026-11-12 复算**(`npm run audit:pins`,v3.24.76):二分 STRUCT **417** / NAME **76**;形态 **POS 403 / NEG 87 / COUNT 3**;难度 **易 62 / 中 316 / 难 115**。钉点减法第一批(v3.24.72)把 **537 → 505**:8 条探针钉点改为「门禁内 spec 是否真的读该计数器」、5 条改为运行时断言(生产态 `window` 上无探针)、10 条改为 DOM 断言(质量档位禁用 / 传输页无三模式按钮 / 模型项 title)、4 条改为运行时对象断言(健康检查两域、策略对象冻结)、其余 9 条有同文件 DOM 等价断言或仅剩 NEG。第二批(v3.24.76)把 **505 → 493**:94-5~7 三条「多标签释放语义」(10 处正则)换成 `tests/iwb-tabs-release.spec.js` 的 3 条真 e2e,剩 1 条「消费方契约」(断言该 spec 在门禁内且 spec 源码真的读两个探针);另 2 条 `wPurgeIntent.add` 钉点改为读 `src/workspace-purge.js`。**这一批一换就查出 3 个真缺陷**(objectURL 从未释放 / 彻底删除留孤儿标签 · session / 刷新后误回收打开标签的图)—— 见 CHANGELOG v3.24.76。 -- `app.js` = 单 IIFE **9,515 行**(**双层预算**:绝对上限 9,529 / 占总源码 ≤ 40%,现 **26.4%**,2026-11-12 起;此前为单一上限 8,509、零余量);`Workbench()` = **2,706 行**(上限 **2,706**,余量 0;2026-11-16 把生成取消族 `cancelRunsFor`/`cancelRun`/`cancelTaskJobs` 与工作区列表写回族 `persistWs`/`duplicateWs` 搬进 `src/runtime-workbench-logic.js`(`createCancelActions` / `createWorkspaceListActions`),并删掉全仓零调用的 `runAll`,3090 → 2,998);大量逻辑已抽到 `src/*.js`(现 **129** 个模块 / 26,528 行,`sourceModules` 129 项;v3.24.68 新增 `clipboard-graph.js`,v3.24.74 新增 `image-admit.js`,v3.24.75 新增 `image-dedupe.js`,v3.24.76 新增 `workspace-purge.js`,v3.24.79 新增 `generation-provider-ping.js`,v3.24.80 删除无调用的 `createWBFlushViewport` 17 行)。 +- `app.js` = 单 IIFE **9,518 行**(**双层预算**:绝对上限 9,529 / 占总源码 ≤ 40%,现 **26.4%**,2026-11-12 起;此前为单一上限 8,509、零余量);`Workbench()` = **2,709 行**(上限 **2,709**,余量 0;2026-11-16 把生成取消族 `cancelRunsFor`/`cancelRun`/`cancelTaskJobs` 与工作区列表写回族 `persistWs`/`duplicateWs` 搬进 `src/runtime-workbench-logic.js`(`createCancelActions` / `createWorkspaceListActions`),并删掉全仓零调用的 `runAll`,3090 → 2,998);大量逻辑已抽到 `src/*.js`(现 **129** 个模块 / 26,528 行,`sourceModules` 129 项;v3.24.68 新增 `clipboard-graph.js`,v3.24.74 新增 `image-admit.js`,v3.24.75 新增 `image-dedupe.js`,v3.24.76 新增 `workspace-purge.js`,v3.24.79 新增 `generation-provider-ping.js`,v3.24.80 删除无调用的 `createWBFlushViewport` 17 行)。 - 门禁:`npm run verify` = `verify:ci`(`build` → `node --check app.js` → `node --check dist/app.js` → `check-dist.js` → `lint`(ESLint 正确性规则,`src/` + `app.js`,P4-16a)→ `test:unit` → `test` → `test:facts`)+ `test:e2e` (A) `package.json`。 ## 1.5 内存基线(2026-11-30,v3.26.115,Windows / WebView2 实测) diff --git a/package.json b/package.json index bb43724..67be2f1 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "app:build": "tauri build", "lint": "eslint src app.js", "test": "node tests/relay-task-graph-fixture-test.js && node tests/plugin-style-node-test.js && node tests/inherit-text-test.js", - "test:unit": "node tests/result-img-doubleclick-test.js && node tests/gallery-audit-test.js && node tests/plugin-files-policy-test.js && node tests/theme-plugin-tokens-test.js && node tests/design-tokens-component-doc-test.js && node tests/theme-static-snapshot-test.js && node tests/overlay-layer-test.js && node tests/settings-scope-test.js && node tests/node-scope-test.js && node tests/appearance-v2-test.js && node tests/image-prompt-cover-test.js && node tests/unit-test.js && node tests/canvas-actions-test.js && node tests/canvas-performance-test.js && node tests/canvas-drag-performance-test.js && node tests/resize-observer-performance-test.js && node tests/node-drag-jank-test.js && node tests/edge-graph-performance-test.js && node tests/persistence-export-images-test.js && node tests/settings-hotkeys-size-presets-test.js && node tests/custom-size-validation-test.js && node tests/image-node-performance-test.js && node tests/drag-frame-performance-test.js && node tests/canvas-edge-memo-test.js && node tests/canvas-node-transform-test.js && node tests/canvas-dot-zoom-test.js && node tests/duplicate-ws-fresh-source-test.js && node tests/single-canvas-shell-test.js && node tests/navigation-layout-test.js && node tests/home-canvas-library-test.js && node tests/left-resource-layout-test.js && node tests/interface-hierarchy-test.js && node tests/three-page-layout-test.js && node tests/page-chrome-regression-test.js && node tests/task-cache-test.js && node tests/album-task-graph-test.js && node tests/plugin-text-node-refs-test.js && node tests/generation-endpoint-test.js && node tests/storage-config-shape-test.js && node tests/generation-default-model-test.js && node tests/storage-zip-test.js && node tests/canvas-node-factory-test.js && node tests/runtime-error-test.js && node tests/runtime-lifecycle-test.js && node tests/runtime-fetch-test.js && node tests/runtime-channel-test.js && node tests/runtime-boundary-test.js && node tests/runtime-record-test.js && node tests/runtime-recovery-test.js && node tests/runtime-diagnostic-record-test.js && node tests/runtime-metrics-test.js && node tests/runtime-run-context-test.js && node tests/runtime-execution-context-test.js && node tests/storage-gc-canvas-refs-test.js && node tests/storage-health-test.js && node tests/generation-state-test.js && node tests/canvas-store-test.js && node tests/storage-result-test.js && node tests/storage-local-test.js && node tests/storage-domain-test.js && node tests/storage-runtime-test.js && node tests/storage-indexeddb-test.js && node tests/generation-scheduler-test.js && node tests/gallery-query-test.js && node tests/gallery-hydration-test.js && node tests/gallery-sync-test.js && node tests/image-blob-store-test.js && node tests/image-format-test.js && node tests/clipboard-graph-test.js && node tests/clipboard-graph-fallback-test.js && node tests/image-admit-test.js && node tests/image-dedupe-test.js && node tests/clipboard-kind-test.js && node tests/clipboard-paste-test.js && node tests/clipboard-copy-test.js && node tests/clipboard-native-test.js && node tests/paste-once-test.js && node tests/list-e2e-specs-test.js && node tests/desktop-csp-loopback-test.js && node tests/architecture-boundary-guard-test.js && node tests/plugin-host-test.js && node tests/plugin-data-test.js && node tests/plugin-loader-test.js && node tests/plugin-bundle-test.js && node tests/plugin-install-test.js && node tests/plugin-gallery-render-test.js && node tests/plugin-gallery-recovery-test.js && node tests/plugin-gallery-ux-test.js && node tests/plugin-grouplib-render-test.js && node tests/plugin-promptlib-render-test.js && node tests/image-compress-test.js && node tests/storage-fallback-indexeddb-test.js && node tests/canvas-normalize-test.js && node tests/canvas-geometry-test.js && node tests/canvas-history-test.js && node tests/canvas-ops-test.js && node tests/canvas-text-test.js && node tests/history-store-test.js && node tests/plugin-integrity-test.js && node tests/workspace-sessions-store-test.js && node tests/workspace-list-test.js && node tests/workspace-purge-test.js && node tests/provider-ping-test.js && node tests/runtime-diagnostics-hotpath-test.js && node tests/storage-log-failure-test.js && node tests/storage-convergence-test.js && node tests/swallow-wiring-test.js && node tests/image-writeback-test.js && node tests/image-ingest-test.js && node tests/workbench-logic-test.js && node tests/storage-autobackup-test.js && node tests/storage-outputs-mutate-test.js && node tests/sync-facts-guard-test.js && node tests/e2e-fixed-waits-ratchet-test.js && node tests/shell-render-behavior-test.js && node tests/canvas-meta-notice-behavior-test.js && node tests/source-text-ratchet-test.js && node tests/plugin-theme-contract-test.js && node tests/prompt-md-roundtrip-test.js && node tests/generation-results-store-test.js && node tests/out-groups-order-test.js && node tests/native-overlay-park-test.js && node tests/ui-dock-sanitize-test.js && node tests/ui-minimap-fit-test.js && node tests/ui-workbench-hooks-test.js && node tests/plugin-scale-contract-test.js && node tests/design-token-ratchet-test.js && node tests/theme-contrast-test.js && node tests/image-file-ref-preview-test.js && node tests/image-download-contract-test.js && node tests/icon-assets-test.js && node tests/strip-plugins-test.js && node tests/plugin-manifest-hashes-test.js && node tests/boot-progress-test.js && node tests/idb-gc-plugin-refs-test.js && node tests/canvas-v3-test.js && node tests/canvas-v3-hit-test.js && node tests/image-cache-migrate-test.js && node tests/storage-flush-persist-test.js", + "test:unit": "node tests/result-img-doubleclick-test.js && node tests/gallery-audit-test.js && node tests/plugin-files-policy-test.js && node tests/theme-plugin-tokens-test.js && node tests/design-tokens-component-doc-test.js && node tests/theme-static-snapshot-test.js && node tests/overlay-layer-test.js && node tests/settings-scope-test.js && node tests/node-scope-test.js && node tests/appearance-v2-test.js && node tests/image-prompt-cover-test.js && node tests/unit-test.js && node tests/canvas-actions-test.js && node tests/canvas-performance-test.js && node tests/canvas-drag-performance-test.js && node tests/resize-observer-performance-test.js && node tests/node-drag-jank-test.js && node tests/edge-graph-performance-test.js && node tests/persistence-export-images-test.js && node tests/settings-hotkeys-size-presets-test.js && node tests/custom-size-validation-test.js && node tests/image-node-performance-test.js && node tests/drag-frame-performance-test.js && node tests/canvas-edge-memo-test.js && node tests/canvas-node-transform-test.js && node tests/canvas-dot-zoom-test.js && node tests/duplicate-ws-fresh-source-test.js && node tests/single-canvas-shell-test.js && node tests/navigation-layout-test.js && node tests/home-canvas-library-test.js && node tests/left-resource-layout-test.js && node tests/interface-hierarchy-test.js && node tests/three-page-layout-test.js && node tests/page-chrome-regression-test.js && node tests/task-cache-test.js && node tests/album-task-graph-test.js && node tests/plugin-text-node-refs-test.js && node tests/generation-endpoint-test.js && node tests/storage-config-shape-test.js && node tests/generation-default-model-test.js && node tests/storage-zip-test.js && node tests/canvas-node-factory-test.js && node tests/runtime-error-test.js && node tests/runtime-lifecycle-test.js && node tests/runtime-fetch-test.js && node tests/runtime-channel-test.js && node tests/runtime-boundary-test.js && node tests/runtime-record-test.js && node tests/runtime-recovery-test.js && node tests/runtime-diagnostic-record-test.js && node tests/runtime-metrics-test.js && node tests/runtime-run-context-test.js && node tests/runtime-execution-context-test.js && node tests/storage-gc-canvas-refs-test.js && node tests/storage-health-test.js && node tests/generation-state-test.js && node tests/canvas-store-test.js && node tests/storage-result-test.js && node tests/storage-local-test.js && node tests/storage-domain-test.js && node tests/storage-runtime-test.js && node tests/storage-indexeddb-test.js && node tests/generation-scheduler-test.js && node tests/gallery-query-test.js && node tests/gallery-hydration-test.js && node tests/gallery-sync-test.js && node tests/image-blob-store-test.js && node tests/image-format-test.js && node tests/clipboard-graph-test.js && node tests/clipboard-graph-fallback-test.js && node tests/image-admit-test.js && node tests/image-dedupe-test.js && node tests/clipboard-kind-test.js && node tests/clipboard-paste-test.js && node tests/clipboard-copy-test.js && node tests/clipboard-native-test.js && node tests/paste-once-test.js && node tests/list-e2e-specs-test.js && node tests/desktop-csp-loopback-test.js && node tests/architecture-boundary-guard-test.js && node tests/plugin-host-test.js && node tests/plugin-data-test.js && node tests/plugin-loader-test.js && node tests/plugin-bundle-test.js && node tests/plugin-install-test.js && node tests/plugin-gallery-render-test.js && node tests/plugin-gallery-recovery-test.js && node tests/plugin-gallery-ux-test.js && node tests/plugin-grouplib-render-test.js && node tests/plugin-promptlib-render-test.js && node tests/image-compress-test.js && node tests/storage-fallback-indexeddb-test.js && node tests/canvas-normalize-test.js && node tests/canvas-geometry-test.js && node tests/canvas-history-test.js && node tests/canvas-ops-test.js && node tests/canvas-text-test.js && node tests/history-store-test.js && node tests/plugin-integrity-test.js && node tests/workspace-sessions-store-test.js && node tests/workspace-list-test.js && node tests/workspace-purge-test.js && node tests/provider-ping-test.js && node tests/runtime-diagnostics-hotpath-test.js && node tests/storage-log-failure-test.js && node tests/storage-convergence-test.js && node tests/swallow-wiring-test.js && node tests/image-writeback-test.js && node tests/image-ingest-test.js && node tests/workbench-logic-test.js && node tests/storage-autobackup-test.js && node tests/storage-outputs-mutate-test.js && node tests/sync-facts-guard-test.js && node tests/e2e-fixed-waits-ratchet-test.js && node tests/shell-render-behavior-test.js && node tests/canvas-meta-notice-behavior-test.js && node tests/source-text-ratchet-test.js && node tests/plugin-theme-contract-test.js && node tests/prompt-md-roundtrip-test.js && node tests/generation-results-store-test.js && node tests/out-groups-order-test.js && node tests/native-overlay-park-test.js && node tests/ui-dock-sanitize-test.js && node tests/ui-minimap-fit-test.js && node tests/ui-workbench-hooks-test.js && node tests/plugin-scale-contract-test.js && node tests/design-token-ratchet-test.js && node tests/theme-contrast-test.js && node tests/image-file-ref-preview-test.js && node tests/image-download-contract-test.js && node tests/icon-assets-test.js && node tests/strip-plugins-test.js && node tests/plugin-manifest-hashes-test.js && node tests/boot-progress-test.js && node tests/idb-gc-plugin-refs-test.js && node tests/canvas-v3-test.js && node tests/canvas-v3-hit-test.js && node tests/image-cache-migrate-test.js && node tests/storage-flush-persist-test.js && node tests/canvas-save-settle-test.js", "test:diagnostics": "node tests/runtime-diagnostics-hotpath-test.js", "test:facts": "node tests/architecture-facts-guard-test.js && node tests/release-records-test.js", "check:plugins": "node scripts/check-plugins-sync.js", diff --git a/tests/canvas-save-settle-test.js b/tests/canvas-save-settle-test.js new file mode 100644 index 0000000..1f688d0 --- /dev/null +++ b/tests/canvas-save-settle-test.js @@ -0,0 +1,41 @@ +/* canvas-save-settle-test.js —— 「落定窗口」内的编辑不得被静默丢弃(v3.26.249) + * + * 背景(2026-12-04,work 实机验收 247 时发现): + * 启动后(loaded=false)或切换画布/同步后的 1.2s 内(refs.syncing=true)做的第一次编辑, + * 保存 effect 走的是 else 分支,而 refs.savePending 只在 saveDebounced 内部置位 —— + * 第一次编辑前它是 false ⇒ 既不排保存、cleanup 还会清掉定时器;skipInitialPersistence + * 又把载入后那一次保存跳过 ⇒ 改动彻底丢失(界面已改、文件 mtime 不变)。 + * + * 修法三处(缺一不可): + * ① commitCanvas 在未落定时打标 refs.dirtyBeforeSettle; + * ② 保存 effect 在 loaded && !syncing 时把标记补成一次 saveDebounced; + * ③ 切画布/同步的 1.2s 定时器结束时同样补一次(syncing 非响应式,不会重跑 effect)。 + * + * 这是源码契约断言(时序行为需要完整宿主才能驱动,jsdom 下不稳定); + * 目录钉点总数远低于棘轮上限,不涉及上调。 + */ +'use strict' +const fs = require('fs') +const path = require('path') +const assert = require('assert') + +const app = fs.readFileSync(path.join(__dirname, '..', 'app.js'), 'utf8') +const read = (rel) => fs.readFileSync(path.join(__dirname, '..', rel), 'utf8') + +assert.ok(/dirtyBeforeSettle: false/.test(app), '① refs 必须有 dirtyBeforeSettle 初值') + +const commitBlock = app.slice(app.indexOf('const commitCanvas = '), app.indexOf('const saveDebounced = ')) +assert.ok(commitBlock.indexOf('if (!(loaded && !refs.syncing)) refs.dirtyBeforeSettle = true') >= 0, + '① commitCanvas(画布唯一变更入口)在未落定时必须打标') + +const gate = app.slice(app.indexOf('if (loaded && !(refs.syncing)) {'), app.indexOf('}, [nodes, edges, groups, loaded])')) +assert.ok(/if \(refs\.dirtyBeforeSettle\) \{ refs\.dirtyBeforeSettle = false; saveDebounced\(\) \}/.test(gate), + '② 保存 effect 落定后必须补一次保存并清标记') + +assert.ok(/setTimeout\(\(\) => \{[\s\S]{0,400}refs\.syncing = false[\s\S]{0,400}dirtyBeforeSettle[\s\S]{0,200}saveDebounced\(\)/.test(app), + '③ 切换画布/同步的 1.2s 定时器结束时也必须补存(syncing 非响应式)') + +assert.ok(/dirtyBeforeSettle = false; saveDebounced\(\)/.test(app), '补存时必须先清标记,避免每次渲染重复排保存') + +console.log('canvas-save-settle: 5 通过 / 0 失败') + diff --git a/tests/source-text-ratchet-test.js b/tests/source-text-ratchet-test.js index 5169eb5..a7f1b79 100644 --- a/tests/source-text-ratchet-test.js +++ b/tests/source-text-ratchet-test.js @@ -218,7 +218,7 @@ const MAX_APP_JS_SHARE = 0.40 // 需要实时读 .iwb-world 变换 + 按同类型实测高度校正视觉中心;属装配层的 DOM 读取, // 放 src 会引入新的全局读取与边界快照改动,权衡后留在 app.js // +10(2026-11-01):背景色「悬停预览」的 DOM 补丁助手(纯 DOM,不写数据/不进撤销栈); // 属装配层最小的 DOM 操作,放 src 会引入新的全局读取与边界快照改动,权衡后留在 app.js -const MAX_WORKBENCH_LINES = 2706 // +10(2,696→2,706)2026-12-04:ref 气泡上传按钮(调用 src/ref-upload)+ 移除气泡改名。之前 +5 文件版接线;+4 文件版;+6 缓存闭包;+3 网络栈/并发;+1 队列预览;+153 队列装配。之后只减不增。 +const MAX_WORKBENCH_LINES = 2709 // +3(2,706→2,709)2026-12-05:保存落定窗口补存(commitCanvas 打标 / 保存 effect 与 1.2s 同步定时器补一次 saveDebounced),时序逻辑依赖 Workbench 内的 loaded/syncing,抽不走。之前 +10 ref 气泡上传/去改名;+5 文件版接线;+4 文件版;+6 缓存闭包;+3 网络栈/并发;+1 队列预览;+153 队列装配。之后只减不增。 // 2026-11-18 v3.25.21:模态层指针守卫(2 行) // 实测 3090 → 2998(省 92):① 生成取消族 cancelRunsFor/cancelRun/cancelTaskJobs // → src/runtime-workbench-logic.js 的 createCancelActions(−53);② 工作区列表写回族