From 06f57f6e5ef4ae3508c6924d45e53bfaf4bfb420 Mon Sep 17 00:00:00 2001 From: qiqi Date: Sat, 5 Dec 2026 19:13:15 +0800 Subject: [PATCH] =?UTF-8?q?fix(canvas):=20=E5=8A=A0=E8=BD=BD=E5=8E=BB?= =?UTF-8?q?=E9=87=8D=E4=B8=8E=E6=8A=A4=E6=A0=8F=E5=8F=AA=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E7=9C=9F=20hydrate=EF=BC=9B=E4=BF=9D=E5=AD=98=E6=88=90?= =?UTF-8?q?=E5=8A=9F=E8=AE=B0=20selfSaveAt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 7 +++++++ CONTRIBUTING.md | 2 +- app.js | 12 +++++++----- docs/standards/architecture-current-state.md | 2 +- package.json | 2 +- src-tauri/Cargo.lock | 2 +- src-tauri/Cargo.toml | 2 +- src-tauri/tauri.conf.json | 2 +- src/runtime-workbench-logic.js | 7 ++++++- tests/source-text-ratchet-test.js | 2 +- 10 files changed, 27 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df12201..ecd2134 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,13 @@ - 历史条目补录:该 tag 当时未在 CHANGELOG 记录(release-records 守卫要求 tag 与条目双向一致),内容按当时提交补一句占位说明。 +## v3.26.254(2026-12-05)画板加载去重:护栏不再误报、少一轮无谓 hydrate + +- `board-load` 护栏只统计**真的 hydrate 了**的次数:已加载的板重复 touch 不再计数,快速点几个标签页不会误触发「同一画板 60 秒加载 7 次」 +- 同一块板在 3 秒内的重复请求(切画布后紧跟的同步读)直接跳过:不重复 touch、不重复 hydrate +- 保存成功后也记 `selfSaveAt`(原来只在冲突分支记):自己保存引起的 rev+1 不再被轮询当成「别人改了」而整块回读 +- breadcrumb 增加 `hydrated=0/1`,便于确认是真实装载还是空转 + ## v3.26.253(2026-12-05)诊断增强:画板反复加载可定位 - wLoadBoard 的 breadcrumb 始终带 via=(hydrate-ws / board-into / 其它),不再出现无来源的 board-load diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bda0935..250d2bb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -105,7 +105,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`) | +| `app.js` 总行数 | `tests/source-text-ratchet-test.js` `MAX_APP_JS_LINES` | **9,530**(另守「占总源码 ≤ 40%」,见 `MAX_APP_JS_SHARE`) | | `Workbench()` 行数 | 同上 `MAX_WORKBENCH_LINES` | **2,710** | | 单组件行数(不含 Workbench)| 同上 `MAX_APP_COMPONENT_LINES` | **423** | diff --git a/app.js b/app.js index e9b5928..07efd08 100644 --- a/app.js +++ b/app.js @@ -3050,24 +3050,26 @@ try { if (window.IWBMiniMapFit && typeof window.IWBMiniMapFit.install === 'funct if (!w || !w.id) return w // 目标画板尚未装载时要为它预留一个名额,否则会出现「先加载第 4 个、再判断超限」的越界 const known = wLoadedBoards.some((x) => x.id === w.id) + const need = wBoardNeedsHydrate(w), prevGuard = wLoadGuard.get(w.id) // 已加载的板 3 秒内重复请求直接跳过 + if (!need && prevGuard && (Date.now() - (Number(prevGuard.lastAt) || 0)) < 3000) return w await wEvictLoadedBoards(w.id, list, known ? W_MAX_LOADED_BOARDS : W_MAX_LOADED_BOARDS - 1) - if (wBoardNeedsHydrate(w)) { if (typeof window !== 'undefined' && window.__IWB_E2E__ === true) window.__IWB_E2E_HYDRATES__ = (window.__IWB_E2E_HYDRATES__ || 0) + 1; await wHydrateWorkspace(w) } + if (need) { if (typeof window !== 'undefined' && window.__IWB_E2E__ === true) window.__IWB_E2E_HYDRATES__ = (window.__IWB_E2E_HYDRATES__ || 0) + 1; await wHydrateWorkspace(w) } wTouchLoadedBoard(w.id, w) // v3.87.17 反复加载护栏:同一画板在 60 秒内被反复加载(实测出现过 5 秒 6 次)会反复 hydrate 大图, // 是"内存尖峰 + 卡顿"的来源之一。超阈值时记 sync-loop 并**暂停自动同步**(用户主动操作仍可继续)。 try { const now = Date.now() - const st = wLoadGuard.get(w.id) || { at: now, n: 0, reason: '' } + const st = wLoadGuard.get(w.id) || { at: now, n: 0, reason: '', lastAt: 0 } if (now - st.at > 60000) { st.at = now; st.n = 0 } - st.n++ - if (reason) st.reason = String(reason) + st.lastAt = now; if (reason) st.reason = String(reason) + if (need) st.n++ wLoadGuard.set(w.id, st) if (st.n === 7 && !wSyncPaused) { wSyncPaused = true if (CrashLog && typeof CrashLog.record === 'function') CrashLog.record('sync-loop', { scope: 'board-load', message: '同一画板 60 秒内被加载 ' + st.n + ' 次,已暂停自动同步', version: APP_VERSION, boardId: String(w.id), extra: { loads: st.n, reason: String(st.reason || '') } }) } } catch (e) { /* 护栏失败不影响加载 */ } - try { if (CrashLog && CrashLog.breadcrumb) CrashLog.breadcrumb('board-load', String(w.id) + ' nodes=' + ((w.nodes || []).length) + ' loaded=' + wLoadedBoards.length + ' via=' + String(reason || 'unknown')) } catch (e) { /* ignore */ } + try { if (CrashLog && CrashLog.breadcrumb) CrashLog.breadcrumb('board-load', String(w.id) + ' nodes=' + ((w.nodes || []).length) + ' loaded=' + wLoadedBoards.length + ' via=' + String(reason || 'unknown') + ' hydrated=' + (need ? 1 : 0)) } catch (e) { /* ignore */ } try { if (typeof window !== 'undefined' && window.IWBPerf) window.IWBPerf.tag('board') } catch (e) { /* ignore */ } try { const MG = (typeof window !== 'undefined') ? window.IWBImageCacheMigrate : null; if (MG && typeof MG.once === 'function') MG.once(w, { read: iwbCacheRead, write: wImgRefWrite, bump: wImgUrlBump }).then(function (r) { try { if (r && r.total) { const S = (typeof window !== 'undefined') ? window.IWBStorageFile : null; if (S && S.logLine) S.logLine('cache-migrate ' + String(w.id) + ' ok=' + r.ok + ' fail=' + r.fail + ' total=' + r.total) } } catch (e) { /* ignore */ } }).catch(function () { /* ignore */ }) } catch (e) { /* 迁移失败不影响装载 */ } return w diff --git a/docs/standards/architecture-current-state.md b/docs/standards/architecture-current-state.md index 193b0fe..6e50813 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,528 行**(**双层预算**:绝对上限 9,529 / 占总源码 ≤ 40%,现 **26.3%**,2026-11-12 起;此前为单一上限 8,509、零余量);`Workbench()` = **2,710 行**(上限 **2,710**,余量 0;2026-11-16 把生成取消族 `cancelRunsFor`/`cancelRun`/`cancelTaskJobs` 与工作区列表写回族 `persistWs`/`duplicateWs` 搬进 `src/runtime-workbench-logic.js`(`createCancelActions` / `createWorkspaceListActions`),并删掉全仓零调用的 `runAll`,3090 → 2,998);大量逻辑已抽到 `src/*.js`(现 **129** 个模块 / 26,689 行,`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,530 行**(**双层预算**:绝对上限 9,530 / 占总源码 ≤ 40%,现 **26.3%**,2026-11-12 起;此前为单一上限 8,509、零余量);`Workbench()` = **2,710 行**(上限 **2,710**,余量 0;2026-11-16 把生成取消族 `cancelRunsFor`/`cancelRun`/`cancelTaskJobs` 与工作区列表写回族 `persistWs`/`duplicateWs` 搬进 `src/runtime-workbench-logic.js`(`createCancelActions` / `createWorkspaceListActions`),并删掉全仓零调用的 `runAll`,3090 → 2,998);大量逻辑已抽到 `src/*.js`(现 **129** 个模块 / 26,694 行,`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 f29854b..8918715 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "image-workbench-web", "private": true, - "version": "3.26.253", + "version": "3.26.254", "description": "Browser-based node canvas image workbench", "scripts": { "build": "node scripts/build.js && node scripts/copy-plugins.js", diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index c8e6589..7f17275 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -2014,7 +2014,7 @@ dependencies = [ [[package]] name = "image-workbench" -version = "3.26.253" +version = "3.26.254" dependencies = [ "arboard", "base64 0.22.1", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 09fd4e1..af92f0f 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "image-workbench" -version = "3.26.253" +version = "3.26.254" description = "无限画布 · 生图工作台桌面版" authors = ["malongan"] license = "" diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 3996bd1..a41c938 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "$schema": "../node_modules/@tauri-apps/cli/config.schema.json", "productName": "image-workbench", - "version": "3.26.253", + "version": "3.26.254", "identifier": "com.malongan.imageworkbench", "build": { "frontendDist": "../dist", diff --git a/src/runtime-workbench-logic.js b/src/runtime-workbench-logic.js index ff21ee3..221384c 100644 --- a/src/runtime-workbench-logic.js +++ b/src/runtime-workbench-logic.js @@ -535,7 +535,12 @@ } return } - if (r && r.ok) { setWsRev(r.rev || wsRev); bcNotify(); sessionsStore.markAllClean() } // S6:保存成功 → 全部 session 清脏 + if (r && r.ok) { + setWsRev(r.rev || wsRev); bcNotify(); sessionsStore.markAllClean() // S6:保存成功 → 全部 session 清脏 + // 2026-12-05:成功保存也要记 selfSaveAt —— 原来只在冲突分支记,导致「自己保存 → rev+1 → 轮询 + // 当成别人改的 → 整块回读+装载」,切画布时就是一轮多余的 hydrate。 + try { selfSaveAt.set(Date.now()) } catch (e) { /* ignore */ } + } wLog('save', '画布已保存:节点 ' + (cur.nodes || []).length + ' 个' + (override && override.nodes ? '(显式快照)' : '(自动)')) // 存储空间不足等明确错误:直接提示,不回退 graph(浏览器模式 graph 恒 ok 会掩盖失败) if (r && r.error) { diff --git a/tests/source-text-ratchet-test.js b/tests/source-text-ratchet-test.js index 68ec8bc..11358ca 100644 --- a/tests/source-text-ratchet-test.js +++ b/tests/source-text-ratchet-test.js @@ -175,7 +175,7 @@ const MAX_SRC_GLOBALS = 125 // 2026-12-04 +1(124→125):新增 IWBRefUpl // · 图标解析统一(右键菜单 + 设置页走同一解析器,2 行) +2 // 通用件(pick/grant/stat/readDataUrl/readBlob/参数校验)全部在 src/image-file-ref.js // 与 src/plugin-api-images.js,app.js 只做装配。 -const MAX_APP_JS_LINES = 9529 // +76(9,453→9,529)2026-12-04:ref 气泡「上传到图库」(含守卫 Set)+ 移除气泡改名。之前 +49 文件版加固;+42 文件版;+36 文件版;+6 缓存闭包;+4 mime;+56 原生审计;+19 缩略图兜底;+11 预览;+3 并发;+9 命名;+199 队列装配。之后只减不增。 +const MAX_APP_JS_LINES = 9530 // +1(9,529→9,530)2026-12-05:画板加载去重(已加载板 3 秒内重复请求直接跳过)+ 护栏只统计真 hydrate —— 该逻辑必须读 wLoadBoard 内的 loaded/同步状态,抽不到 src。之前 +76(9,453→9,529)2026-12-04:ref 气泡「上传到图库」(含守卫 Set)+ 移除气泡改名。之前 +49 文件版加固;+42 文件版;+36 文件版;+6 缓存闭包;+4 mime;+56 原生审计;+19 缩略图兜底;+11 预览;+3 并发;+9 命名;+199 队列装配。之后只减不增。 const MAX_APP_JS_SHARE = 0.40 // ── 历史记账(供回溯,逐条保留)──────────────────────────────────────────────