Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(work-panel): cover plugin view reload cleanup

vastsa68dd8ffef72d
diff --git a/apps/desktop/electron/main/bootstrap/window.ts b/apps/desktop/electron/main/bootstrap/window.ts
index 4a4f15365..558720b45 100644
--- a/apps/desktop/electron/main/bootstrap/window.ts
+++ b/apps/desktop/electron/main/bootstrap/window.ts
@@ -14,6 +14,7 @@ import type { BrowserHost } from "../browser-host";
import type { HostProcess } from "../host-process";
import type { Logger } from "../logger";
import type { PluginViewHost } from "../plugin-view-host";
+import { detachPluginViewOnRendererReload } from "../plugin-view-navigation";
import {
baseWindowBounds,
clampBoundsOriginToWorkArea,
@@ -760,16 +761,9 @@ export async function createWindow({
browserHost.setWindow(window);
pluginViews.setWindow(window);
- // A renderer reload (⌘R) drops the React tree that drives plugin-view
- // visibility, leaving the native view compositing above the fresh renderer
- // as an orphan overlay no surviving control can hide. Detach it here so a
- // reload always starts from "no plugin view shown"; the reloaded renderer
- // re-attaches on demand. Same-document navigations keep the tree alive.
- window.webContents.on(
- "did-start-navigation",
- (_event, _url, isInPlace, isMainFrame) => {
- if (isMainFrame && !isInPlace) pluginViews.hideVisibleView();
- },
+ detachPluginViewOnRendererReload(
+ window.webContents,
+ () => pluginViews.hideVisibleView(),
);
window.on("closed", () => {
screen.removeListener("display-metrics-changed", reconcileDisplayTopology);
diff --git a/apps/desktop/electron/main/plugin-view-navigation.ts b/apps/desktop/electron/main/plugin-view-navigation.ts
new file mode 100644
index 000000000..349a996b4
--- /dev/null
+++ b/apps/desktop/electron/main/plugin-view-navigation.ts
@@ -0,0 +1,18 @@
+import type { WebContents } from "electron";
+
+/**
+ * A full main-frame navigation replaces the React tree that owns native-view
+ * visibility. Detach the visible plugin page before that tree disappears;
+ * same-document and child-frame navigations leave its owner intact.
+ */
+export function detachPluginViewOnRendererReload(
+ webContents: WebContents,
+ hideVisibleView: () => void,
+): void {
+ webContents.on(
+ "did-start-navigation",
+ (_event, _url, isInPlace, isMainFrame) => {
+ if (isMainFrame && !isInPlace) hideVisibleView();
+ },
+ );
+}
diff --git a/apps/desktop/test/plugin-view-navigation.test.mjs b/apps/desktop/test/plugin-view-navigation.test.mjs
new file mode 100644
index 000000000..c1283b971
--- /dev/null
+++ b/apps/desktop/test/plugin-view-navigation.test.mjs
@@ -0,0 +1,60 @@
+import assert from "node:assert/strict";
+import { register } from "node:module";
+import { readFileSync } from "node:fs";
+import test from "node:test";
+
+register(new URL("./helpers/ts-import-hooks.mjs", import.meta.url));
+
+const { detachPluginViewOnRendererReload } = await import(
+ "../electron/main/plugin-view-navigation.ts"
+);
+const windowSource = readFileSync(
+ new URL("../electron/main/bootstrap/window.ts", import.meta.url),
+ "utf8",
+);
+const viewHostSource = readFileSync(
+ new URL("../electron/main/plugin-view-host.ts", import.meta.url),
+ "utf8",
+);
+
+test("only full main-frame navigation detaches the visible plugin view", () => {
+ let listener;
+ const webContents = {
+ on(event, callback) {
+ assert.equal(event, "did-start-navigation");
+ listener = callback;
+ return this;
+ },
+ };
+ let detachCount = 0;
+
+ detachPluginViewOnRendererReload(webContents, () => {
+ detachCount += 1;
+ });
+
+ listener({}, "file:///index.html#section", true, true);
+ listener({}, "https://plugin.invalid/frame", false, false);
+ assert.equal(detachCount, 0);
+
+ listener({}, "file:///index.html", false, true);
+ assert.equal(detachCount, 1);
+});
+
+test("window reload wiring detaches the cached view without closing its page", () => {
+ assert.match(
+ windowSource,
+ /detachPluginViewOnRendererReload\(\s*window\.webContents,\s*\(\) => pluginViews\.hideVisibleView\(\),?\s*\)/,
+ );
+
+ const hideMethod = viewHostSource.match(
+ /hideVisibleView\(\): void \{([\s\S]*?)\n \}/,
+ )?.[1];
+ assert.match(hideMethod ?? "", /this\.detachVisible\(\)/);
+ assert.doesNotMatch(hideMethod ?? "", /\.close\(/);
+
+ const detachMethod = viewHostSource.match(
+ /private detachVisible\(\): void \{([\s\S]*?)\n \}/,
+ )?.[1];
+ assert.match(detachMethod ?? "", /removeChildView\(entry\.view\)/);
+ assert.doesNotMatch(detachMethod ?? "", /webContents\.close\(/);
+});
diff --git a/docs/spec/04-ux/08-component-spec.md b/docs/spec/04-ux/08-component-spec.md
index 87a2a0794..2699f7ff4 100644
--- a/docs/spec/04-ux/08-component-spec.md
+++ b/docs/spec/04-ux/08-component-spec.md
@@ -1243,7 +1243,7 @@ entirely inside the plugin's isolated page:
| Open with no resource | `Cmd/Ctrl + J` reveals the panel without creating a tab, so the body renders the New launcher. Clicking `+` creates an explicit, closable New tab with the same launcher rows. Activating a row from that tab replaces it with or selects the singleton view. Closing the final tab leaves the panel open in the no-resource state. |
| Constrained work area | The panel is capped by the shared three-column budget inside the existing client area; MainChat never drops below its 450px floor and the expanded sidebar yields at the threshold |
| New launcher active | The body hosts concise Review and plugin-view buttons. Each row replaces the launcher tab with its destination or activates the existing singleton; the page is independently closeable. |
-| Plugin view active | The body hosts the plugin's own isolated page as a native `WebContentsView`, positioned from the measured surface rect. It remains visible at its full rect while the divider is being resized or a New launcher tab is created; creating a page never pushes the plugin body down or changes its bounds. Embedded plugin documents start with zero root/body margin and border and a transparent background, so the host panel and plugin theme own the visible surface edge. It is hidden whenever the tab is inactive, the panel is animating, or a panel-wide blocking overlay is open. When the active plugin tab's context menu opens, Main shows a native popup above the `WebContentsView`, keeping the page visible at unchanged bounds. A view whose plugin is disabled, uninstalled, reloaded, or crashed is destroyed; the tab stays and re-opens the page on the next lifecycle event (ADR 0104) |
+| Plugin view active | The body hosts the plugin's own isolated page as a native `WebContentsView`, positioned from the measured surface rect. It remains visible at its full rect while the divider is being resized or a New launcher tab is created; creating a page never pushes the plugin body down or changes its bounds. Embedded plugin documents start with zero root/body margin and border and a transparent background, so the host panel and plugin theme own the visible surface edge. It is hidden whenever the tab is inactive, the panel is animating, or a panel-wide blocking overlay is open. When the active plugin tab's context menu opens, Main shows a native popup above the `WebContentsView`, keeping the page visible at unchanged bounds. A full main-frame navigation of the host renderer, including reload, detaches the visible native view without closing its cached page; opening the tab again reattaches the same page. Same-document and child-frame navigations keep it attached. A view whose plugin is disabled, uninstalled, reloaded, or crashed is destroyed; the tab stays and re-opens the page on the next lifecycle event (ADR 0104) |
| Plugin out of scope | A view contributed by a plugin that is not active in the current project disappears from the New launcher when the project changes. Unlike contributed themes, which are one global setting and stay unfiltered, a view is scoped work |
### 5.4 Interactions
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index bad1b238f..0fda0bb47 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -4832,7 +4832,11 @@ window; opening a normal panel afterward must still work.
Move the normal window between displays and change the active display's
work-area geometry. 12) Send valid and malformed reservation payloads,
including positive values, and confirm the compatibility seam never changes
- native bounds. 13) Relaunch.
+ native bounds. 13) Relaunch. 14) Open a contributed plugin view and reload
+ the main renderer with Cmd/Ctrl+R. Confirm the native view detaches before the
+ new renderer appears, then reopen its tab and verify the cached plugin page
+ returns. Repeat with a same-document navigation and a child-frame navigation;
+ neither may detach the active view.
- **Expected**: Startup shows no panel, welcome chooser, or fixed tool buttons.
A viewport-fixed toggle in the window's top-right corner is the pointer
equivalent of Cmd/Ctrl+J; there is still no application-menu launcher.
@@ -4882,8 +4886,11 @@ window; opening a normal panel afterward must still work.
that preferred panel width. The compatibility reservation seam returns
`{requested: 0, reserved: 0}` for every valid request, including positive
legacy values, and never changes native bounds. Malformed payloads fail with
- `INVALID_ARGUMENT` and never coerce. The former context-panel overlay no
- longer exists.
+ `INVALID_ARGUMENT` and never coerce. A full main-frame renderer reload
+ detaches the visible plugin view without closing its page, so no orphan
+ overlay covers the fresh renderer; reopening the tab reattaches that same
+ page. Same-document and child-frame navigation leave the view attached. The
+ former context-panel overlay no longer exists.
- **Specs linked**: `03-runtime/01-ipc-protocol.md`, `04-ux/01-ui-ia.md`,
`04-ux/07-ui-design-system.md`, `04-ux/08-component-spec.md`,
`04-ux/09-interaction-patterns.md`, ADR 0068, ADR 0151, ADR 0195, D207, D292,
@@ -4893,7 +4900,8 @@ window; opening a normal panel afterward must still work.
- **Status**: Unit-covered (`work-panel-resize.test.mjs`,
`work-panel-window.test.mjs`, `work-panel-presentation.test.mjs`,
`work-panel-tabs.test.mjs`, `browser-tab-restore.test.mjs`,
- `work-panel.test.mjs`, `plugin-work-panel-views.test.mjs`); isolated Electron
+ `work-panel.test.mjs`, `plugin-work-panel-views.test.mjs`,
+ `plugin-view-navigation.test.mjs`); isolated Electron
tab-menu, Browser native-menu page visibility, and close geometry in
`scripts/e2e-work-panel-tab-close.mjs`; full UI scenario Draft
diff --git a/docs/zh-CN/spec/04-ux/08-component-spec.md b/docs/zh-CN/spec/04-ux/08-component-spec.md
index 7a4a45ade..e91da8794 100644
--- a/docs/zh-CN/spec/04-ux/08-component-spec.md
+++ b/docs/zh-CN/spec/04-ux/08-component-spec.md
@@ -821,7 +821,7 @@ vendor 进来的 `pi.file-manager` 视图在插件自己的隔离页面内完成
| 打开但无资源 | `Cmd/Ctrl + J` 揭示面板而不创建选项卡,因此主体渲染 New 启动器。点击行会创建或选中单例标签;关闭最后一个标签后仍回到这里。这里的主体不是 `role="tabpanel"`,因为没有选项卡为它命名。 |
| 受限工作区域 | 面板受三栏共享预算限制;MainChat 永不跌破 450px 硬下限,展开的左栏在阈值处让位 |
| New 启动器激活 | 主体承载简洁的 Review 与插件视图按钮;每行会用其目标替换启动器标签页,或激活已存在的单例视图;该页面可独立关闭 |
-| 插件视图处于活动状态 | 主体以原生 `WebContentsView` 承载插件自己的隔离页面,按测量到的表面矩形定位。分隔线拖动调整或 `+` 新建菜单打开时视图保持可见;占位符观察器跟随逐帧合并的面板宽度,菜单打开时只把原生边界裁剪到不透明菜单底边以下,让内容不会闪成面板底色。当该选项卡非活动、面板正在动画或面板级阻塞性浮层打开时,视图隐藏 —— 与浏览器预览同一条规则,因为两者都合成在渲染层之上。插件被禁用、卸载、重新加载或崩溃时其视图会被销毁;选项卡保留,并在下一次生命周期事件时重新打开页面(ADR 0104) |
+| 插件视图处于活动状态 | 主体以原生 `WebContentsView` 承载插件自己的隔离页面,按测量到的表面矩形定位。分隔线拖动调整或 `+` 新建菜单打开时视图保持可见;占位符观察器跟随逐帧合并的面板宽度,菜单打开时只把原生边界裁剪到不透明菜单底边以下,让内容不会闪成面板底色。当该选项卡非活动、面板正在动画或面板级阻塞性浮层打开时,视图隐藏 —— 与浏览器预览同一条规则,因为两者都合成在渲染层之上。宿主渲染器发生完整主框架导航(包括重新加载)时,会分离可见的原生视图但保留缓存页面;重新打开选项卡会重新挂载同一页面。同文档和子框架导航不会分离视图。插件被禁用、卸载、重新加载或崩溃时其视图会被销毁;选项卡保留,并在下一次生命周期事件时重新打开页面(ADR 0104) |
| 插件不在当前范围内 | 由未在当前项目激活的插件贡献的视图,会在切换项目时从菜单中消失。与全局唯一设置的贡献主题不同,视图属于项目内的工作,因此按范围过滤 |
### 5.4 互动
diff --git a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
index 8c2fee41d..4f1103434 100644
--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
@@ -2391,7 +2391,10 @@ hover/focus 不带移位标签,项目标题 hover/focus 路径显示
窗口管理器压缩并重新定位外部窗口之前的位置
显示更改回调。 13) 在打开时注入一项被拒绝的预订
以及折叠时的一个,然后重试每个操作。 14) 发送字符串、布尔值、
- 空、小数和超出范围的预留有效负载。 15) 重新启动。
+ 空、小数和超出范围的预留有效负载。 15) 重新启动。 16) 打开一个插件视图,
+ 使用 Cmd/Ctrl+R 重新加载主渲染器。确认原生视图在新渲染器出现前分离,
+ 然后重新打开对应选项卡,确认缓存的插件页面恢复。再测试同文档导航和
+ 子框架导航;两者都不应分离活动视图。
- **预期**:启动时不显示面板、欢迎选择器、固定工具按钮或
titlebar/menu 启动器。 Cmd/Ctrl+J 打开活动会话的面板
无需创建资源选项卡即可提交宽度;重复它是幂等的,
@@ -2460,15 +2463,18 @@ MainChat 弥补了缺口。 Maximized/fullscreen 调用保留最新的
(`--ds-window-lead-inset`,即灯簇右缘 76px 加 12px 间隙,共 88px)作为自身的左内边距渲染出来,
左侧第一个预览操作从该渲染值起或之后开始;检查读取的是解析后的内边距,而不是重述这个数字。
打开真实工作面板标签后,其第一个标签从预览操作组右侧至少 8px 处开始;全屏时使用 8px 原生内缩但保留该操作带。
+ 主渲染器完整主框架重新加载时,可见插件视图会分离但不会关闭缓存页面,因此新渲染器不会被孤儿原生层覆盖;重新打开选项卡会重新挂载同一页面。同文档和子框架导航保持视图附着。
以前的上下文面板覆盖不再存在。
- **链接规格**:`03-runtime/01-ipc-protocol.md`、`04-ux/01-ui-ia.md`、
`04-ux/07-ui-design-system.md`、`04-ux/08-component-spec.md`、
`04-ux/09-interaction-patterns.md`、ADR 0032、ADR 0068、D163、D207
- **接受**:F(坚持),质量
- **里程碑**:M5
-- **状态**:单位覆盖(`work-panel-resize.test.mjs`,
+- **状态**:单位覆盖(`work-panel-resize.test.mjs`、
`work-panel-window.test.mjs`、`work-panel-presentation.test.mjs`、
- `work-panel.test.mjs`);完整的 UI 场景草稿
+ `work-panel.test.mjs`、`plugin-work-panel-views.test.mjs`、
+ `plugin-view-navigation.test.mjs`);隔离 Electron 菜单和关闭路径已覆盖;
+ 完整渲染器重新加载 UI 场景仍为草稿
#### E2E-057:消息拥有的审阅历史记录可以安全提交并回滚