[GH-ISSUE #5072] [GUI] 聊天回答里的外部链接点了没有任何反应:Markdown 的 preventDefault 之后 openLink 只接管预览链接,外部 URL 没人接 #2359

Open
opened 2026-11-04 01:58:42 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @xvcezrqpbxtpzblrt on GitHub (Nov 3, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/5072

English TL;DR: In 0.2.10 the chat link handler does route web addresses to the system browser (Chat.tsx:221-227 → openExternal), as designed for #4721. But the desktop shell's host spawn (apps/desktop/src-tauri/src/main.rs:463-475) never passes STRATA_UI_MODE, while the CLI supervisor does (supervisor.rs:361). So appUi.state() reports mode: null — documented in app-ui.mjs:12 as "not started by the app" — and open-external.ts:26 (if (mode.mode === 'window')) therefore skips the host leg and falls back to window.open(url,'_blank','noopener,noreferrer') (:22), which the codebase itself documents as a no-op inside the app window (artifacts.mjs:11: "the app window drops window.open: WebView2 has no new-window handler"). The click then does nothing, with no message. The same mode:null also sets appUpdate:'unavailable'.

Area

[GUI] 桌面应用(外壳 + host + Web UI)

现象

在聊天里点助手回答中的外部链接(GitHub issue 链接这类),没有任何反应:不开浏览器、不开预览、不提示。本机 0.2.10,2026-11-03 多次出现。

环境(本机实测)

  • Strata desktop 0.2.10(外壳 pid 9004),host http://127.0.0.1:47831,WebView2 156.0.4314.58,Windows 10.0.26300
  • 安装产物 host\dist\* 的 mtime 是 2026-11-03 06:37:26

现场实测(对着正在运行的 app 探的,2026-11-03 17:47)

  1. GET http://127.0.0.1:47831/api/app/mode → 200,响应体:
    {"mode":null,"reason":null,"canQuit":false,"appUpdate":"unavailable"}
    
    → mode 是 null,不是 'window';并且 appUpdate 被报成 unavailable
  2. GET http://127.0.0.1:47831/ → 200 / 2172 字节 index.html;GET /nope-does-not-exist → 200 + index.html(SPA 兜底)——说明 host 活着且正常,不是"服务没起来"
  3. POST /api/artifacts/open:我发的 JSON 被 PowerShell 的引号转义破坏,服务端回 500 {"error":"Body must be JSON"} → 这次探测无效,记 not run(真正走通 URL 腿会真的打开浏览器标签,没有做)

机制链(全部为 tag v0.2.10 = ffa80d73 的行号,与你安装的产物时间一致)

  1. 链接渲染:apps/host/src/components/Markdown.tsx:33-36 —— 只有 https?://、mailto:、# 会渲染成 <a … target="_blank" rel="noreferrer">,点击时 if (onOpenLink && /^https?:/i.test(link[2])) { e.preventDefault(); onOpenLink(link[2]); };图片当链接时同理(:19-23,plan.kind === 'link' → preventDefault + onOpenLink(plan.href))
  2. 交给页面:apps/host/src/screens/Chat.tsx:221-227
    function openLink(url: string) {
        const item = artifactFromUrl(url);
        if (!item)
            return;
        // A web address opens in the person's own browser; only a file (…) is shown in the side panel (#4721).
        if (item.kind === 'website') {
            void openExternal(url);
    
  3. apps/host/src/lib/open-external.ts:17-31(关键 3 行)
    • :25 const mode = d.known() ?? await d.load();(loadAppMode() 读 GET /api/app/mode,失败 .catch(() => NONE))
    • :26 if (mode.mode === 'window') { → 本机实测是 null,这个分支不进
    • :22 / :30 落到 d.open(url) = window.open(url, '_blank', 'noopener,noreferrer')
    • :27-28 即使在 window 分支,POST /api/artifacts/open 失败也是 catch { /* the host could not: the page tries as well */ } —— "再试一次"就是那个在 app 窗口里不可能成功的 window.open,两条失败路径都不出提示
  4. window.open 在 app 窗口里是空操作,代码自己写明了:apps/host/server/artifacts.mjs:11

    // #4721: a web address goes to the person's default browser (the app window drops window.open: WebView2 has no new-window handler).
    与本机对 strata-desktop.exe 的字符串计数一致:new_window 0、onNewWindow 0、opener: 0、shell:allow-open 0

  5. mode 从哪来:apps/host/server/app-ui.mjs:64
    let mode = MODES.has(env.STRATA_UI_MODE) ? env.STRATA_UI_MODE : null;
    
    注释 :12:mode null = not started by the app (the host run by hand, a test, a source checkout)
  6. 该设而没设的地方:
    • 桌面外壳起 host:apps/desktop/src-tauri/src/main.rs:463-475 传的是 STRATA_PORT、STRATA_DIST、NODE_ENV、STRATA_PACKAGED、STRATA_REAL_ENGINE、STRATA_EXIT_WITH_PARENT —— 没有 STRATA_UI_MODE
    • CLI 那条路径却有:apps/desktop/src-tauri/src/supervisor.rs:361 cmd.env("STRATA_UI_MODE", mode),紧接着 :363 .env("STRATA_UI_REASON","chosen")
      → 同一个 host 代码,终端启动时 mode 正确,桌面 app 启动时 mode 恒为 null

这一处 mode:null 的连带影响

  • 外部链接在 app 窗口里全灭(本报告现象)
  • app-ui.mjs:85 appUpdate: mode === 'browser' || mode === null ? 'unavailable' : … → 实测正是 "appUpdate":"unavailable":app 内自更新在桌面 app 里被报成不可用
  • canQuit:false(同一 state),依赖 mode 的通知/退出/更新提示路径都退回"没有窗口进程"的分支
  • 外壳日志里 [host] update · update-engine started 是引擎更新通道,与 app 自更新不是一回事,不要混淆

复现

  1. 从图标启动桌面 app(0.2.10),开一个聊天,让助手回答里带一个 https:// 链接
  2. 点它
  • 期望:默认浏览器打开该地址
  • 实际:什么都没有,也没有任何提示
  • 快速判定:curl http://127.0.0.1:<host端口>/api/app/mode → 若 mode 为 null 即命中本条
  • 复现状态:passed —— 对运行中的 app 探到 mode:null 与 appUpdate:"unavailable";行号在 tag v0.2.10(ffa80d73)逐条核对;exe 字符串计数已核。not run —— 端到端点击(无法程序化操作 UI)、POST /api/artifacts/open 的 URL 腿(探测因 body 转义失败,且真跑会打开浏览器标签)、url.dll 的导出表检查(我的 PE 解析报错,未得出结果)。failed —— 无

建议

  1. main.rs:463-475 起 host 时补 .env("STRATA_UI_MODE", "window")(与 supervisor.rs:361 一致;--browser 时传 browser),让桌面 app 与 CLI 走同一套语义
  2. open-external.ts 把 mode === null 当"未卜"而不是"非窗口":先试 POST /api/artifacts/open,失败再退 window.open;两条都失败时必须有用户可见的失败提示(toast:"打不开外部链接,地址已复制"),不要静默
  3. 外壳给 WebView2 装上新窗口处理(或明确拒绝并提示),让 target="_blank" 在 app 里有确定行为(与 #5072 的原始症状同源)
  4. 测试补两处:apps/host/tests/app-ui.test.mjs 现在只测 STRATA_UI_MODE:'window'/'browser' 的 host 侧,没有测"桌面外壳是否真的传了这个变量"——加一个断言外壳 spawn 参数含 STRATA_UI_MODE 的测试;再在桌面冒烟里断言 GET /api/app/mode 的 mode === "window"(这一条能立刻抓住本缺陷)

版本说明(必须交代)

本条最初是按 0.2.9 检出写的(克隆时间 2026-11-02 14:46,落后 origin/main 5,629 个提交),当时的结论是"openLink 只处理预览链接,外部 URL 没人接"。0.2.10 已经改成 openExternal + #4721 的设计,旧结论对 0.2.10 不成立;现在的检出已对齐 tag v0.2.10 = ffa80d73(2026-11-03 06:37:27),与安装产物 mtime 06:37:26 对得上,正文按 v0.2.10 重写。

相关已有讨论(先查过仓库)

  • #4721(0.2.10 代码里被引用为这条的设计来源:网页地址交给系统浏览器)
  • #5079 open—— 同为"外壳与 WebView2 能力/事件没接上"这一族
  • 搜索关键词:open link、external browser、app/mode、STRATA_UI_MODE、链接 打不开;未见覆盖"外壳未传 STRATA_UI_MODE 导致 mode:null"的开放 issue

本报告未包含

  • 未包含:macOS / Linux 外壳传参路径(main.rs 的 darwin/linux 分支未核);url.dll 是否导出 FileProtocolHandler(PE 解析失败,未得出);POST /api/artifacts/open 正常 URL 时的端到端结果(需真开浏览器标签);mode=null 对通知与退出按钮的具体影响面(只实测了 mode/appUpdate/canQuit 三个字段)
Originally created by @xvcezrqpbxtpzblrt on GitHub (Nov 3, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/5072 **English TL;DR**: In 0.2.10 the chat link handler *does* route web addresses to the system browser (`Chat.tsx:221-227` → `openExternal`), as designed for #4721. But the desktop shell's host spawn (`apps/desktop/src-tauri/src/main.rs:463-475`) never passes `STRATA_UI_MODE`, while the CLI supervisor does (`supervisor.rs:361`). So `appUi.state()` reports `mode: null` — documented in `app-ui.mjs:12` as "not started by the app" — and `open-external.ts:26` (`if (mode.mode === 'window')`) therefore skips the host leg and falls back to `window.open(url,'_blank','noopener,noreferrer')` (`:22`), which the codebase itself documents as a no-op inside the app window (`artifacts.mjs:11`: "the app window drops window.open: WebView2 has no new-window handler"). The click then does nothing, with no message. The same `mode:null` also sets `appUpdate:'unavailable'`. ## Area [GUI] 桌面应用(外壳 + host + Web UI) ## 现象 在聊天里点助手回答中的外部链接(GitHub issue 链接这类),**没有任何反应**:不开浏览器、不开预览、不提示。本机 0.2.10,2026-11-03 多次出现。 ## 环境(本机实测) - Strata desktop **0.2.10**(外壳 pid 9004),host `http://127.0.0.1:47831`,WebView2 156.0.4314.58,Windows 10.0.26300 - 安装产物 `host\dist\*` 的 mtime 是 **2026-11-03 06:37:26** ## 现场实测(对着正在运行的 app 探的,2026-11-03 17:47) 1. `GET http://127.0.0.1:47831/api/app/mode` → **200**,响应体: ```json {"mode":null,"reason":null,"canQuit":false,"appUpdate":"unavailable"} ``` → **`mode` 是 `null`**,不是 `'window'`;并且 `appUpdate` 被报成 `unavailable` 2. `GET http://127.0.0.1:47831/` → 200 / 2172 字节 index.html;`GET /nope-does-not-exist` → 200 + index.html(SPA 兜底)——说明 host 活着且正常,不是"服务没起来" 3. `POST /api/artifacts/open`:我发的 JSON 被 PowerShell 的引号转义破坏,服务端回 `500 {"error":"Body must be JSON"}` → **这次探测无效,记 not run**(真正走通 URL 腿会真的打开浏览器标签,没有做) ## 机制链(全部为 **tag v0.2.10 = ffa80d73** 的行号,与你安装的产物时间一致) 1. 链接渲染:`apps/host/src/components/Markdown.tsx:33-36` —— 只有 `https?://`、`mailto:`、`#` 会渲染成 `<a … target="_blank" rel="noreferrer">`,点击时 `if (onOpenLink && /^https?:/i.test(link[2])) { e.preventDefault(); onOpenLink(link[2]); }`;图片当链接时同理(`:19-23`,`plan.kind === 'link'` → `preventDefault` + `onOpenLink(plan.href)`) 2. 交给页面:`apps/host/src/screens/Chat.tsx:221-227` ```tsx function openLink(url: string) { const item = artifactFromUrl(url); if (!item) return; // A web address opens in the person's own browser; only a file (…) is shown in the side panel (#4721). if (item.kind === 'website') { void openExternal(url); ``` 3. `apps/host/src/lib/open-external.ts:17-31`(关键 3 行) - `:25` `const mode = d.known() ?? await d.load();`(`loadAppMode()` 读 `GET /api/app/mode`,失败 `.catch(() => NONE)`) - `:26` `if (mode.mode === 'window') {` → 本机实测是 `null`,**这个分支不进** - `:22` / `:30` 落到 `d.open(url)` = `window.open(url, '_blank', 'noopener,noreferrer')` - `:27-28` 即使在 `window` 分支,`POST /api/artifacts/open` 失败也是 `catch { /* the host could not: the page tries as well */ }` —— "再试一次"就是那个在 app 窗口里不可能成功的 `window.open`,**两条失败路径都不出提示** 4. `window.open` 在 app 窗口里是空操作,代码自己写明了:`apps/host/server/artifacts.mjs:11` > `// #4721: a web address goes to the person's default browser (the app window drops window.open: WebView2 has no new-window handler).` 与本机对 `strata-desktop.exe` 的字符串计数一致:`new_window` **0**、`onNewWindow` **0**、`opener:` **0**、`shell:allow-open` **0** 5. `mode` 从哪来:`apps/host/server/app-ui.mjs:64` ```js let mode = MODES.has(env.STRATA_UI_MODE) ? env.STRATA_UI_MODE : null; ``` 注释 `:12`:`mode null = not started by the app (the host run by hand, a test, a source checkout)` 6. **该设而没设的地方**: - 桌面外壳起 host:`apps/desktop/src-tauri/src/main.rs:463-475` 传的是 `STRATA_PORT`、`STRATA_DIST`、`NODE_ENV`、`STRATA_PACKAGED`、`STRATA_REAL_ENGINE`、`STRATA_EXIT_WITH_PARENT` —— **没有 `STRATA_UI_MODE`** - CLI 那条路径却有:`apps/desktop/src-tauri/src/supervisor.rs:361` `cmd.env("STRATA_UI_MODE", mode)`,紧接着 `:363` `.env("STRATA_UI_REASON","chosen")` → 同一个 host 代码,终端启动时 mode 正确,桌面 app 启动时 mode 恒为 `null` ## 这一处 mode:null 的连带影响 - 外部链接在 app 窗口里全灭(本报告现象) - `app-ui.mjs:85` `appUpdate: mode === 'browser' || mode === null ? 'unavailable' : …` → 实测正是 `"appUpdate":"unavailable"`:app 内自更新在桌面 app 里被报成不可用 - `canQuit:false`(同一 state),依赖 mode 的通知/退出/更新提示路径都退回"没有窗口进程"的分支 - 外壳日志里 `[host] update · update-engine started` 是**引擎**更新通道,与 app 自更新不是一回事,不要混淆 ## 复现 1. 从图标启动桌面 app(0.2.10),开一个聊天,让助手回答里带一个 `https://` 链接 2. 点它 - 期望:默认浏览器打开该地址 - 实际:什么都没有,也没有任何提示 - 快速判定:`curl http://127.0.0.1:<host端口>/api/app/mode` → 若 `mode` 为 `null` 即命中本条 - 复现状态:**passed** —— 对运行中的 app 探到 `mode:null` 与 `appUpdate:"unavailable"`;行号在 tag v0.2.10(ffa80d73)逐条核对;exe 字符串计数已核。**not run** —— 端到端点击(无法程序化操作 UI)、`POST /api/artifacts/open` 的 URL 腿(探测因 body 转义失败,且真跑会打开浏览器标签)、`url.dll` 的导出表检查(我的 PE 解析报错,未得出结果)。**failed** —— 无 ## 建议 1. `main.rs:463-475` 起 host 时补 `.env("STRATA_UI_MODE", "window")`(与 `supervisor.rs:361` 一致;`--browser` 时传 `browser`),让桌面 app 与 CLI 走同一套语义 2. `open-external.ts` 把 `mode === null` 当"未卜"而不是"非窗口":先试 `POST /api/artifacts/open`,失败再退 `window.open`;两条都失败时**必须有用户可见的失败提示**(toast:"打不开外部链接,地址已复制"),不要静默 3. 外壳给 WebView2 装上新窗口处理(或明确拒绝并提示),让 `target="_blank"` 在 app 里有确定行为(与 #5072 的原始症状同源) 4. 测试补两处:`apps/host/tests/app-ui.test.mjs` 现在只测 `STRATA_UI_MODE:'window'/'browser'` 的 host 侧,**没有**测"桌面外壳是否真的传了这个变量"——加一个断言外壳 spawn 参数含 `STRATA_UI_MODE` 的测试;再在桌面冒烟里断言 `GET /api/app/mode` 的 `mode === "window"`(这一条能立刻抓住本缺陷) ## 版本说明(必须交代) 本条最初是按 **0.2.9 检出**写的(克隆时间 2026-11-02 14:46,落后 `origin/main` **5,629** 个提交),当时的结论是"`openLink` 只处理预览链接,外部 URL 没人接"。0.2.10 已经改成 `openExternal` + #4721 的设计,**旧结论对 0.2.10 不成立**;现在的检出已对齐 **tag v0.2.10 = ffa80d73(2026-11-03 06:37:27)**,与安装产物 mtime 06:37:26 对得上,正文按 v0.2.10 重写。 ## 相关已有讨论(先查过仓库) - #4721(0.2.10 代码里被引用为这条的设计来源:网页地址交给系统浏览器) - #5079 [open](渲染进程崩掉后整窗变内置错误页)—— 同为"外壳与 WebView2 能力/事件没接上"这一族 - 搜索关键词:`open link`、`external browser`、`app/mode`、`STRATA_UI_MODE`、`链接 打不开`;未见覆盖"外壳未传 STRATA_UI_MODE 导致 mode:null"的开放 issue ## 本报告未包含 - 未包含:macOS / Linux 外壳传参路径(`main.rs` 的 darwin/linux 分支未核);`url.dll` 是否导出 `FileProtocolHandler`(PE 解析失败,未得出);`POST /api/artifacts/open` 正常 URL 时的端到端结果(需真开浏览器标签);mode=null 对通知与退出按钮的具体影响面(只实测了 `mode`/`appUpdate`/`canQuit` 三个字段)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#2359
No description provided.