Skip to content

fix: embed face follows the dsh host theme; frame breathing room (#2559 #2560) - #2564

Merged
ranxianglei merged 3 commits into
masterfrom
2026-10-09_embed-dark-follow
Oct 10, 2026
Merged

ranxianglei merged 3 commits into
masterfrom
2026-10-09_embed-dark-follow

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #2559
Closes #2560

深色跟随(#2559)

嵌入面板在 iframe 里,prefers-color-scheme 只跟操作系统走,跟宿主应用主题无关——dsh 面板切深色但系统偏好仍是浅色时,浅色调色板直接铺到宿主的深色底上,文字不可读(fcab54cd/#2475 的 color-scheme 绑定解决不了:它只把画布颜色交给浏览器,OS 信号本身没变)。

修复链:

  1. src/agent/dsh-native-client.ts — panel 挂载时同步采样宿主页面底色(documentElement/body/main/[role=main]/#root/#app 不透明背景做亮度投票,luma≤0.4 → dark;全失败/无信号 → 不 pin,退回 OS 信号),结果通过 iframe URL &theme=light|dark 下发。运行时切换寄生在既有 origin probe tick 上(≤10s 延迟,iframe reload 保持 hash),零新增 timer、无 postMessage 通道(Windows/dsh 宿主重启:代理就绪超出 SPAWN_WAIT_MS(20s) 导致 bootstrap 失败,本进程内无重试 → /bili/origin 恒为 null、设置面板永久"未绑定"、整场会话直连(压缩失效) #2187 的 delay-pinning 测试原样通过即证明)。
  2. src/server/admin.ts /__bili/ — theme 参数白名单校验后透传。
  3. src/web/page.ts + styles.ts — pin 落在 <html data-theme>:新增 :root[data-theme="dark"] 块逐字携带既有深色变量集 + color-scheme: dark;OS 信号的 media 块收窄为 :root:not([data-theme]),两个调色板永不互搏(显式 pin 恒胜)。data-theme="light" 只钉 color-scheme: light(浅色是基础值)。

frame 呼吸空隙(#2560)

.embed main padding 由 4px 0 12px 改为 8px 10px 16px,内容不再贴框边(左/右原来为 0)。

验证

  • typecheck ✔;build ✔;tests/web-i18n.test.ts 10/0、tests/dsh-settings-ui.test.ts(含新增 【ui】dsh 嵌入面板不跟随宿主深色主题——深色底上文字不可读 #2559 CSS-pin 与首帧 pin 场景)、tests/web-sessions.test.ts + launcher.test.ts 310/310 ✔。
  • 像素 A/B(headless chrome ×2,暗色模拟宿主包 iframe,master worktree vs 本分支):
    • master @ v0.1.189,暗宿主 + OS 亮:标题/数字近乎不可见(复现)
    • 本分支 + &theme=dark:全深色调板,清晰可读
    • 本分支 + OS dark 无 pin:旧 media 路径不受收窄影响
    • 本分支 + 亮宿主 + OS dark + &theme=light:显式 pin 压过 OS 信号
  • 测试面:vm 沙箱新增场景钉住「首帧即带 &theme=」与三种底色判定;DOM-less 宿主(无 document/getComputedStyle)保持不 pin,既有精确 src 断言全部原样通过——行为对无 DOM 环境零变化。

config surface:无变更(?theme= 仅为 bili 自家 client↔server 管理路由的内部参数,非用户配置/环境变量)。

#2560)

Closes #2559
Closes #2560

Dark readability (#2559): the embed face sits in an iframe whose
prefers-color-scheme tracks the OS, not the host app — so a dark dsh
panel with an OS-level light preference rendered the light palette onto
the host's dark ground and the text went unreadable. The client now
samples its own page ground at panel mount (opaque background luminance
vote over documentElement/body/main/#root/#app, matchMedia fallback,
all failure paths → unpinned) and pins the result on the iframe URL as
&theme=light|dark. /__bili/ whitelists the param onto <html
data-theme>, which carries the existing dark palette verbatim plus a
matching color-scheme declaration; the OS-signal media block narrows to
:not([data-theme]) so the two palettes never fight (explicit pin always
wins). Live theme toggles piggyback the existing origin probe tick
(<=10s lag) — no new timer, no postMessage channel.

Frame padding (#2560): .embed main gains 8px/10px/16px padding instead
of hugging the frame edge on all four sides.
@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-09_embed-dark-follow (e8affd1)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2744-pr.2564.baf9f66

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr2564.tgz
npm install -g package

Install instructions are refreshed on each push.

…n palette sync (#2564 review)

Review finding: the :root[data-theme="dark"] block repeated the OS-driven dark list with --red-soft green channel drifted 73 -> 46 (rgba(248,81,46,.12) vs the #f85149-consistent rgba(248,81,73,.12)), contradicting the verbatim-carry intent. Restore 73 and add a bidirectional set-equality guard between the two lists (color-scheme aside) so future drift fails CI.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 PR #2564 审查结论(#2559 + #2560)

① 原 issue 方向:两个 issue 都属实、机制分析成立——iframe 是独立文档,prefers-color-scheme 只能读 OS/浏览器信号,dsh 应用级主题跨不过文档边界;.embed main 横向 padding 自 #2321 起为 0,被 max-width: none 裸露成贴边。修法方向正确(宿主侧采样 → URL 参数 → 显式 pin),是修根因不是堵症状。

② 回归清点(diff 触碰路径的既有行为逐项过):

③ 代码审查:detectHostTheme() 全链 try/catch 防御、无 DOM/无信号降级不 pin、luma(Rec.709) 加权 + alpha>0.5 投票 + 平票回退 OS,逻辑合理;admin.ts 严格白名单(只有 light/dark 两个字面量能进 HTML),无注入面;无 as any/@ts-ignore。

④ review 中发现一处真实缺陷,已直接修掉(独立 commit 5cbdc5502 推到本分支):styles.ts 新增的 :root[data-theme="dark"] 块没有逐字携带既有深色变量集——--red-soft 写成 rgba(248, 81, 46, 0.12),而 media 块既有值(master 亦同)是 rgba(248, 81, 73, 0.12)(= #f85149 带透明度),绿通道误写 46。影响:显式 pin 深色的错误 banner/toast 红色底比 OS-driven 深色略偏橙(视觉漂移,轻微)。修复:还原为 73,并在 #2559 测试里补了双向集合相等断言(两列表除 color-scheme 外必须逐条一致)——已验证该守卫对旧错误值会红且点名漂移的具体 declaration,杜绝未来静默漂移。

⑤ 测试有效性:vm 挂载首帧 src 断言(含高 alpha rgba 底色三例)有牙(去掉同步采样或改分类阈值都会红);renderPage data-theme 断言有牙;CSS pin 与仓库惯例一致。非阻塞 gap:mid-session toggle(probe tick 上 onTheme 重分类)无直接测试覆盖——路径简单且 timer 面已被 #2187 钉住,风险低。

⑥ diff 整洁度:7 个文件全部服务于两个 issue,无跑题改动、无格式噪音,单一线性提交。

验证:typecheck ✔;定向套件(dsh-settings-ui + web-i18n + web-sessions + launcher)330 pass / 0 fail / 1 skip ✔,且在 rebase 到最新 master 后重跑仍绿(rebase 零冲突——merge-base 以来 master 没有提交触碰这 7 个文件)。CI:新 head 5cbdc5502 已触发全量重跑,进行中,绿了我再跟一条。

结构化八问

  1. 是什么问题:dsh web 嵌入面板(iframe ?embed=1)不跟随 dsh 应用级深色主题(深色底上文字不可读)+ 面板内容贴死 frame 边缘。
  2. 什么原因导致的:iframe 是独立文档,只能看到 OS/浏览器 color-scheme,宿主应用级主题传不进文档边界;embed 面沿用独立页面的 main 横向 padding=0,max-width: none 后裸露。
  3. 影响范围与严重程度:「dsh 主题 ≠ OS 偏好」组合下嵌入面板可读性——暗宿主+亮 OS 组合下近乎不可用(完全不可读级);padding 项纯视觉瑕疵。
  4. 怎么修复的:宿主侧同源采样真实地面亮度(luma 投票;无信号降级 OS 信号)→ iframe URL &theme=light|dark → 服务端白名单校验 → <html data-theme> 显式变量表;media 块收窄到 :not([data-theme]),显式 pin 恒胜 OS 信号。运行时切换寄生在既有 origin probe tick(≤10s,零新增 timer、无 postMessage 通道)。
  5. 是否有回归问题:无。逐项:无参请求不变 / OS 路径不变 / DOM-less 宿主不变 / Windows/dsh 宿主重启:代理就绪超出 SPAWN_WAIT_MS(20s) 导致 bootstrap 失败,本进程内无重试 → /bili/origin 恒为 null、设置面板永久"未绑定"、整场会话直连(压缩失效) #2187 timer pin 不变 / embed 块其余规则不动。review 另发现并修复 --red-soft 绿通道漂移(见 ④)。
  6. 是否破坏缓存:不涉及——纯静态 HTML/CSS 渲染,不触碰会话状态、prefix、增量游标或去重键。
  7. 是否改了设计方向:不涉及——沿用既有 embed 面架构(dsh设置位置提供真的设置面板 #2321/【bug】dsh 嵌入面板窄宽度下会话表格挤压重叠、面板行拥挤(#2342 嵌入面未做窄容器适配) #2448),只增加一个内部 client↔server 参数。
  8. 是否引入了新的配置:不涉及——无 env/config/默认值变更。

判定:可合(等 CI 绿);合并权在你:#2564

相关条目:PR #2561(仅修 #2560 padding)的内容已被本 PR 完全包含(同一行 styles.ts),二者合并顺序会产生冲突——建议本 PR 合并后关闭 #2561(superseded),我没有擅自关闭,由你拍板。

…2564 review)

Git-for-Windows checks .ts out with \r\n (autocrlf default; .gitattributes
pins only tests/golden/** to LF), so the mid-string "\n" literal in the
OS-driven-palette assertion fails on every windows-latest CI run. Verified:
reproduced locally by converting src/web/styles.ts to CRLF (test red on the
exact assertion), green after normalization under both CRLF and LF.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 CI 跟进:windows-latest 全红,根因已定位并修掉(commit e8affd1aa)

现象:新 head 5cbdc5502(上一条回复里的 --red-soft 修复)触发全量重跑——ubuntu×2 全绿,windows-latest Node 22/24 两个节点都红,5241 pass / 1 fail,失败的是本 PR 新增的测试:

✖ #2559: explicit host theme pin overrides the OS palette; #2560 embed frame padding
  AssertionError [ERR_ASSERTION]: the OS-driven dark palette stays out of explicitly pinned documents
      at tests\dsh-settings-ui.test.ts:911

归因:拉了旧 head 4ffde8471(我任何修复之前)的 Windows 日志对照——同一断言、同一位置失败。即不是我上一笔 review commit 引入的,而是这个 PR 的测试从提交起在 Windows 上就是坏的。

根因(平台差异,确定性失败,非 flake):

修复(e8affd1aa,已推到本分支):读取后一行 .replace(/\r\n/g, "\n") 归一化 + 注释说明为何必须保留(Linux 上看着像 dead code,删掉会静默再坏 Windows CI)。纯测试改动,不触碰任何产品代码;我上一笔加的集合相等守卫本身是 trim 解析、天然 CRLF-tolerant,无需改。

验证:本地 A/B——把 src/web/styles.ts 转成 CRLF 模拟 Windows checkout:修复前红(精确复现该断言)、修复后绿;还原 LF 后仍绿;typecheck 干净。

状态:新 head e8affd1aa 的全量 CI 已触发,跑完我再跟一条最终确认。判定不变:全绿后可合;另建议合并后关闭被完全包含的 PR #2561(superseded)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 最终确认:CI 全绿 ✅

新 head e8affd1aa 全量 CI 11/11 通过——test (windows-latest, 22) / test (windows-latest, 24) 均转绿(CRLF 归一化修复在真实 Windows runner 上生效),ubuntu×2、kernel-guard、docs-sync 等其余 job 全过。

收工判定:可合。 本分支现在共两笔 review 附加提交,均独立可回溯:

  1. 5cbdc5502 — --red-soft 绿通道漂移修复 + 双向集合相等守卫;
  2. e8affd1aa — 【ui】dsh 嵌入面板不跟随宿主深色主题——深色底上文字不可读 #2559 CSS-pin 测试的 CRLF 归一化(修掉 windows CI 确定性失败)。

合并权在你:#2564

合并后请顺手关闭 PR #2561(仅含 #2560 padding 一行改动,已被本 PR 完全包含,二者合并顺序会冲突)。

@ranxianglei
ranxianglei merged commit ed24c6b into master Oct 10, 2026
26 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.197-master.ed24c6b (rolling master tag).

npm install -g billion-context@0.0.197-master.ed24c6b  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant