// 停靠栏插件面板「串页」回归守护(2026-11-27 重写)。 // // 原缺陷(资源中心浮窗时代):插件面板与图库分支渲染在同一父容器的同一位置, // React 复用 DOM 节点 + 插件手动 appendChild 不在 fiber 记账里 ⇒ 切走后残留。 // // v3.25.82 起资源中心浮窗下线,面板搬进左右停靠栏(每个面板一个 .iwb-dock-body)。 // 同一类风险仍然存在:切面板时旧面板的 DOM 必须卸载,切回只能挂载一份。 // 这里用「宿主级」判据守护:任何时刻停靠栏里只应有一个插件容器(.iwb-dock-plugin)。 const { test, expect } = require('./_pw-coverage') const W = require('./_helpers/wait') const baseURL = process.env.IWB_BASE_URL || 'http://127.0.0.1:8787' test.use({ baseURL, viewport: { width: 1440, height: 1000 } }) const WS = { workspaces: [{ id: 'w1', name: 'W', nodes: [], edges: [], groups: [] }], activeId: 'w1', rev: 1 } test('停靠栏面板切换不残留:切走即卸载,切回只挂载一份', async ({ page }) => { await page.addInitScript((ws) => { localStorage.clear() localStorage.setItem('iwb_web_workspaces', JSON.stringify(ws)) localStorage.setItem('iwb_ws_active', ws.activeId) localStorage.setItem('iwb_ws_w1', JSON.stringify(ws.workspaces[0])) localStorage.setItem('iwb_web_outputs', JSON.stringify([])) }, WS) await page.goto('/', { waitUntil: 'domcontentloaded' }) await page.waitForFunction(() => Boolean(window.IWBPluginHost) && window.IWBPluginHost.snapshot().initialized === true) await page.locator('.iwb-home-card:not(.iwb-home-new)').first().dblclick() await expect(page.locator('.iwb-canvas:not(.iwb-canvas-hidden)')).toBeVisible() // 左右两栏各可有一个活动面板 ⇒ 不能按全局计数;按「本面板 body 内的插件容器」断言 const galleryBody = () => page.locator('.iwb-dock-body[data-panel="gallery"]') const galleryBoxes = () => page.locator('.iwb-dock-body[data-panel="gallery"] .iwb-dock-plugin').count() // 图库面板:挂载一份 await W.openDockPanel(page, 'gallery') await expect(galleryBody()).toHaveCount(1) await expect.poll(galleryBoxes).toBe(1) // 切到提示词库:图库的 DOM 必须卸载(旧面板不残留) await W.openDockPanel(page, 'prompts') await expect(galleryBody()).toHaveCount(0) // 切回图库:重新挂载,且只有一份(不是叠加两份) await W.openDockPanel(page, 'gallery') await expect(galleryBody()).toHaveCount(1) await expect.poll(galleryBoxes).toBe(1) await expect(page.locator('.iwb-dock-body[data-panel="gallery"] .iwb-history-embedded')).toHaveCount(1) // 再往返一次:仍然干净 await W.openDockPanel(page, 'prompts') await expect(galleryBody()).toHaveCount(0) await W.openDockPanel(page, 'gallery') await expect.poll(galleryBoxes).toBe(1) })