revert(storage): 回滚启动阶段的存储改动(插件面板样式异常排查)
Verify (Gitea) / gate (build · unit · facts) (push) Canceled after 54s
Verify (Gitea) / gate (build · unit · facts) (push) Canceled after 54s
用户反馈升级到 81a30f2 后,风格库 / 浏览器 / 提示词库三个插件的面板样式全乱。
web 构建下同一份代码插件样式注入正常(promptlib 42KB 样式节点在 head 里),
所以问题出在桌面端独有的路径上。81a30f2 里改了存储装载:
ensureDirs 并发、一次性维护延后到首屏后、prepare 阶段上报。
先把这一半整体回滚到 e3c7a3f,保留静态启动屏与进度条,用二分法确认责任范围。
This commit is contained in:
1 parent
81a30f261a
commit
cef362cbc2
6 files changed
+131
-32
No files matched your search
+25
@@ -0,0 +1,25 @@
|
||||
const { chromium } = require('playwright');
|
||||
(async () => {
|
||||
const b = await chromium.launch();
|
||||
const p = await b.newPage({ viewport: { width: 1400, height: 900 } });
|
||||
const errs = [];
|
||||
p.on('pageerror', (e) => errs.push(e.message.slice(0, 120)));
|
||||
p.on('console', (m) => { if (m.type() === 'error') errs.push(m.text().slice(0, 120)) });
|
||||
await p.goto('http://127.0.0.1:8792/', { waitUntil: 'load' });
|
||||
await p.waitForTimeout(3000);
|
||||
await p.click('button:has-text("新建画布")').catch(() => {});
|
||||
await p.waitForTimeout(2500);
|
||||
const info = await p.evaluate(() => {
|
||||
const styles = Array.prototype.map.call(document.querySelectorAll('head style'), (s) => ({ id: s.id || s.getAttribute('data-plugin') || '(none)', len: s.textContent.length }));
|
||||
const pluginStyles = styles.filter((x) => x.id !== '(none)' || x.len > 0);
|
||||
return {
|
||||
styleCount: styles.length,
|
||||
nonEmpty: styles.filter((s) => s.len > 0).length,
|
||||
pluginStyles,
|
||||
dockButtons: Array.prototype.map.call(document.querySelectorAll('.iwb-dock-btn'), (b) => b.getAttribute('data-tip') || b.getAttribute('aria-label') || b.textContent.trim()).slice(0, 12),
|
||||
};
|
||||
});
|
||||
console.log(JSON.stringify(info, null, 1).slice(0, 1200));
|
||||
console.log('errors:', JSON.stringify(errs.slice(0, 5)));
|
||||
await b.close();
|
||||
})().catch((e) => { console.error('ERR', e.message); process.exit(1) });
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
const { chromium } = require('playwright');
|
||||
(async () => {
|
||||
const b = await chromium.launch();
|
||||
const p = await b.newPage({ viewport: { width: 1400, height: 900 } });
|
||||
await p.goto('http://127.0.0.1:8793/', { waitUntil: 'load' });
|
||||
await p.waitForTimeout(2500);
|
||||
await p.click('button:has-text("新建画布")').catch(() => {});
|
||||
await p.waitForTimeout(2000);
|
||||
// 打开左侧停靠栏里的「提示词库」面板
|
||||
await p.click('.iwb-dock-btn[data-tip="提示词库"], .iwb-dock-btn[data-tip="风格库"], .iwb-dock-btn[data-tip="浏览器"]').catch((e) => console.log('click err', e.message.slice(0, 60)));
|
||||
await p.waitForTimeout(2500);
|
||||
const info = await p.evaluate(() => {
|
||||
const styles = Array.prototype.map.call(document.querySelectorAll('head style'), (s) => ({ attr: s.getAttribute('data-plugin') || s.id || '', len: s.textContent.length }));
|
||||
const panel = document.querySelector('.iwb-plugin-panel, .iwb-dock.right .iwb-dock-body, .iwb-dock-body');
|
||||
const inner = document.querySelector('.iwb-promptlib, .iwb-plugin-panel-root, .iwb-dock-panel');
|
||||
return {
|
||||
pluginStyleNodes: styles.filter((s) => s.attr).slice(0, 6),
|
||||
totalStyles: styles.length,
|
||||
panelCls: panel ? String(panel.className) : null,
|
||||
panelW: panel ? Math.round(panel.getBoundingClientRect().width) : null,
|
||||
innerTag: inner ? inner.tagName + '.' + String(inner.className).slice(0, 40) : null,
|
||||
dockRightW: (() => { const d = document.querySelector('.iwb-dock.right'); return d ? Math.round(d.getBoundingClientRect().width) : null })(),
|
||||
bootStyleLeft: !!document.getElementById('iwb-boot-static'),
|
||||
};
|
||||
});
|
||||
console.log(JSON.stringify(info, null, 1));
|
||||
await p.screenshot({ path: '/tmp/plugin-panel.png' });
|
||||
await b.close();
|
||||
})().catch((e) => { console.error('ERR', e.message); process.exit(1) });
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
const { chromium } = require('playwright');
|
||||
(async () => {
|
||||
const b = await chromium.launch();
|
||||
const p = await b.newPage({ viewport: { width: 1400, height: 900 } });
|
||||
await p.goto('http://127.0.0.1:8794/', { waitUntil: 'load' });
|
||||
await p.waitForTimeout(2500);
|
||||
await p.click('button:has-text("新建画布")').catch(() => {});
|
||||
await p.waitForTimeout(2000);
|
||||
const buttons = await p.evaluate(() => Array.prototype.map.call(document.querySelectorAll('.iwb-dock-btn, .iwb-dock-head button'), (b) => ({ cls: b.className, tip: b.getAttribute('data-tip'), label: b.getAttribute('aria-label'), text: (b.textContent || '').trim().slice(0, 8) })));
|
||||
console.log('dock buttons:', JSON.stringify(buttons).slice(0, 600));
|
||||
const target = buttons.find((x) => (x.tip || x.label || x.text || '').indexOf('提示词') >= 0);
|
||||
console.log('target:', JSON.stringify(target));
|
||||
if (target) {
|
||||
await p.click('.iwb-dock-btn[data-tip="' + target.tip + '"]').catch((e) => console.log('click2 err', e.message.slice(0, 50)));
|
||||
await p.waitForTimeout(2500);
|
||||
}
|
||||
const info = await p.evaluate(() => {
|
||||
const styles = Array.prototype.map.call(document.querySelectorAll('head style'), (s) => ({ attr: s.getAttribute('data-plugin') || '', len: s.textContent.length }));
|
||||
const body = document.querySelector('.iwb-dock-body');
|
||||
const card = document.querySelector('.iwb-lib-card, .iwb-prompt-item, .iwb-plugin-panel *');
|
||||
return {
|
||||
pluginStyleNodes: styles.filter((s) => s.attr),
|
||||
bodyH: body ? Math.round(body.getBoundingClientRect().height) : null,
|
||||
bodyCls: body ? String(body.className) : null,
|
||||
firstChildCls: body && body.firstElementChild ? String(body.firstElementChild.className).slice(0, 60) : null,
|
||||
cardW: card ? Math.round(card.getBoundingClientRect().width) : null,
|
||||
};
|
||||
});
|
||||
console.log(JSON.stringify(info, null, 1));
|
||||
await p.screenshot({ path: '/tmp/panel2.png' });
|
||||
await b.close();
|
||||
})().catch((e) => { console.error('ERR', e.message); process.exit(1) });
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
const { chromium } = require('playwright');
|
||||
(async () => {
|
||||
const b = await chromium.launch();
|
||||
const p = await b.newPage({ viewport: { width: 1400, height: 900 } });
|
||||
const errs = [];
|
||||
p.on('console', (m) => { if (m.type() === 'error') errs.push(m.text().slice(0, 100)) });
|
||||
await p.goto('http://127.0.0.1:8796/', { waitUntil: 'load' });
|
||||
await p.waitForTimeout(2500);
|
||||
await p.click('button:has-text("新建画布")').catch(() => {});
|
||||
await p.waitForTimeout(2500);
|
||||
const dock = await p.evaluate(() => Array.prototype.map.call(document.querySelectorAll('.iwb-dock-btn'), (b) => ({ label: b.getAttribute('aria-label'), cls: b.className })));
|
||||
console.log('dock:', JSON.stringify(dock));
|
||||
const btn = await p.$('.iwb-dock-btn[aria-label="提示词库"]');
|
||||
if (btn) { await btn.click({ force: true }).catch((e) => console.log('click err', e.message.slice(0, 50))); }
|
||||
await p.waitForTimeout(2500);
|
||||
const info = await p.evaluate(() => {
|
||||
const styles = Array.prototype.map.call(document.querySelectorAll('head style'), (s) => ({ p: s.getAttribute('data-plugin') || '', len: s.textContent.length }));
|
||||
const body = document.querySelector('.iwb-dock.right .iwb-dock-body') || document.querySelector('.iwb-dock-body');
|
||||
return {
|
||||
pluginStyles: styles.filter((s) => s.p),
|
||||
bodyCls: body ? String(body.className) : null,
|
||||
bodyW: body ? Math.round(body.getBoundingClientRect().width) : null,
|
||||
firstChild: body && body.firstElementChild ? String(body.firstElementChild.className).slice(0, 50) : null,
|
||||
dockRightW: (() => { const d = document.querySelector('.iwb-dock.right'); return d ? Math.round(d.getBoundingClientRect().width) : null })(),
|
||||
};
|
||||
});
|
||||
console.log(JSON.stringify(info, null, 1));
|
||||
console.log('errs:', JSON.stringify(errs.slice(0, 4)));
|
||||
await p.screenshot({ path: '/tmp/panel-head.png' });
|
||||
await b.close();
|
||||
})().catch((e) => { console.error('ERR', e.message); process.exit(1) });
|
||||
@@ -22,7 +22,7 @@
|
||||
- 图片**新写入主通道 = IndexedDB Blob `{__blob}` / key `imgblob_<hash>_<len>`** (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 **8,323 行**(**双层预算**:绝对上限 8,329 / 占总源码 ≤ 40%,现 **26.2%**,2026-11-12 起;此前为单一上限 8,509、零余量);`Workbench()` = **2,174 行**(上限 **2,179**,余量 5;2026-11-16 把生成取消族 `cancelRunsFor`/`cancelRun`/`cancelTaskJobs` 与工作区列表写回族 `persistWs`/`duplicateWs` 搬进 `src/runtime-workbench-logic.js`(`createCancelActions` / `createWorkspaceListActions`),并删掉全仓零调用的 `runAll`,3090 → 2,998);大量逻辑已抽到 `src/*.js`(现 **117** 个模块 / 23,482 行,`sourceModules` 117 项;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 **8,323 行**(**双层预算**:绝对上限 8,329 / 占总源码 ≤ 40%,现 **26.2%**,2026-11-12 起;此前为单一上限 8,509、零余量);`Workbench()` = **2,174 行**(上限 **2,179**,余量 5;2026-11-16 把生成取消族 `cancelRunsFor`/`cancelRun`/`cancelTaskJobs` 与工作区列表写回族 `persistWs`/`duplicateWs` 搬进 `src/runtime-workbench-logic.js`(`createCancelActions` / `createWorkspaceListActions`),并删掉全仓零调用的 `runAll`,3090 → 2,998);大量逻辑已抽到 `src/*.js`(现 **117** 个模块 / 23,464 行,`sourceModules` 117 项;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`。
|
||||
|
||||
## 2. 门禁与环境现状
|
||||
|
||||
+13
-31
@@ -754,15 +754,6 @@
|
||||
return fromDataJson ? 'loaded' : 'migrated'
|
||||
}
|
||||
|
||||
// 首屏之后再做的一次性维护:延迟到当前渲染帧之后,别和启动抢 I/O
|
||||
const deferAfterPaint = (fn) => {
|
||||
const run = () => { try { Promise.resolve(fn()).catch(() => {}) } catch (e) { /* ignore */ } }
|
||||
try {
|
||||
if (typeof setTimeout === 'function') setTimeout(run, 1200)
|
||||
else run()
|
||||
} catch (e) { run() }
|
||||
}
|
||||
|
||||
// 一次性迁移:把老版本存在 IndexedDB 里的图片字节搬到 images/ 下(跑过一次就写标记文件)
|
||||
// 启动日志:超过 256KB 只保留最后 64KB(否则长年累月会一直长)
|
||||
const blog = async (m) => {
|
||||
@@ -895,9 +886,9 @@
|
||||
/* 建立工作必需目录:canvases/ library/ plugins/ trash/ 与 images/{canvas,gallery,thumbs,legacy} */
|
||||
async function ensureDirs() {
|
||||
const subs = [CANVAS_DIR, 'library', PLUG_DIR, 'trash', IMG_DIR, IMG_DIR + '/canvas', IMG_DIR + '/gallery', IMG_DIR + '/thumbs', IMG_DIR + '/legacy']
|
||||
// v3.26.109:串行建 9 个目录 = 9 次网络往返(局域网资料目录上就是十几秒白屏的主因之一),
|
||||
// 改成并发:一次往返的量级。mkdir recursive 本来幂等,并发安全。
|
||||
await Promise.all(subs.map((sub) => join(dir, sub).then((abs) => fs().mkdir(abs, { recursive: true })).catch(() => {})))
|
||||
for (const sub of subs) {
|
||||
try { await fs().mkdir(await join(dir, sub), { recursive: true }) } catch (e) { /* 已存在或不可写:继续下一个 */ }
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -922,39 +913,30 @@
|
||||
// 授权(fs scope 是运行时授权,重启后由这里补一次)
|
||||
try { await core().invoke('grant_dir', { dir: want }) } catch (e) { console.error('[iwb][file-store] 授权失败', e); return false }
|
||||
dir = want
|
||||
bpReport('prepare', 1, 4, '资料目录已授权')
|
||||
try { global.localStorage.setItem(PTR_KEY, dir) } catch (e) { /* ignore */ }
|
||||
try { await fs().mkdir(await join(dir, IMG_DIR), { recursive: true }) } catch (e) { /* 已存在 */ }
|
||||
// 兜底:把工作必需的子目录一次性补齐(幂等)。
|
||||
// 为什么需要:Windows 全新安装时 images/ 下只有 thumbs/,缺了 canvas/ 会导致
|
||||
// 图片写入失败(历史 bug:写进不持久的 Cache → 重启丢图);目录被手工删掉时也靠这里自愈,
|
||||
// 否则启动阶段读目录抛错会直接影响首屏渲染。
|
||||
bpReport('prepare', 2, 4, '补齐子目录')
|
||||
try { await ensureDirs() } catch (e) { /* 建目录失败不阻塞启动 */ }
|
||||
bpReport('prepare', 3, 4, '整理画布文件名')
|
||||
try { await repairCanvasFileNames() } catch (e) { /* 修复失败按原样装载 */ }
|
||||
bpReport('prepare', 4, 4)
|
||||
await loadInto()
|
||||
// 从 WebView 的 localStorage 捞回被截断/覆盖的画布(一次性)
|
||||
try { await recoverFromWebStorage() } catch (e) { /* 忽略 */ }
|
||||
loaded = true
|
||||
bpReport('finalize', 1, 1)
|
||||
// 首次迁移要立刻落盘,别等 debounce
|
||||
await flush()
|
||||
// v3.26.109:以下都是一次性维护(各自带标记文件,正常情况下只是 check 一下),
|
||||
// 但每次都要若干次网络往返。放到首屏渲染之后跑,局域网资料目录的启动时间能少好几秒。
|
||||
deferAfterPaint(async () => {
|
||||
// 老版本图片在 IndexedDB 里 ⇒ 搬到 images/(带标记,只跑一次)
|
||||
try { await migrateBlobs() } catch (e) { /* 迁移失败不阻塞启动 */ }
|
||||
// 图库清单补齐缩略图(一次性)
|
||||
try { await backfillGalleryThumbs() } catch (e) { /* 忽略 */ }
|
||||
// 图库清单去 base64(一次性):缩略图已在 images/thumbs/,清单只留 thumbHash
|
||||
try { await stripInlineGalleryThumbs() } catch (e) { /* 忽略 */ }
|
||||
// trash/ 轮转:gcImages 只是移进来,超过 30 天在这里真正删除
|
||||
try { await rotateTrash(30) } catch (e) { /* 忽略 */ }
|
||||
// 旧的 768px 显示缩略图一次性清理(缓存可再生)
|
||||
try { const dropped = await dropLegacyDisplayThumbs(); if (dropped) console.info('[iwb][file-store] 清理旧缩略图', dropped, '个') } catch (e) { /* 忽略 */ }
|
||||
})
|
||||
// 老版本图片在 IndexedDB 里 ⇒ 搬到 images/(带标记,只跑一次)
|
||||
try { await migrateBlobs() } catch (e) { /* 迁移失败不阻塞启动 */ }
|
||||
// 图库清单补齐缩略图(一次性)
|
||||
try { await backfillGalleryThumbs() } catch (e) { /* 忽略 */ }
|
||||
// 图库清单去 base64(一次性):缩略图已在 images/thumbs/,清单只留 thumbHash
|
||||
try { await stripInlineGalleryThumbs() } catch (e) { /* 忽略 */ }
|
||||
// trash/ 轮转:gcImages 只是移进来,超过 30 天在这里真正删除
|
||||
try { await rotateTrash(30) } catch (e) { /* 忽略 */ }
|
||||
// 旧的 768px 显示缩略图一次性清理(缓存可再生)
|
||||
try { const dropped = await dropLegacyDisplayThumbs(); if (dropped) console.info('[iwb][file-store] 清理旧缩略图', dropped, '个') } catch (e) { /* 忽略 */ }
|
||||
// 自愈:图库清单丢了但 assets 还有 out_ 键 ⇒ 按键重建(名称/时间/idb 可推,label/远程 url 无法恢复)
|
||||
try {
|
||||
if (mem['iwb_web_outputs'] === undefined) {
|
||||
|
||||
Reference in new issue
Block a user