merge fix/1014-panel-host-dvh: use 100dvh for the panel host (#1014)

This commit is contained in:
Menghuan1918 committed 2026-10-29 23:45:22 +08:00
commit dcd5cf66b1
3 files changed
+45 -15

No files matched your search

+1 -1
View File
@@ -1193,7 +1193,7 @@ interface SettingsDescriptor {
- **面板表面**:右/底面板背景 = `var(--dsw-alias-bg-layer-1)`。**绝不消费 `--dsw-specific-sidebar-fill`**(宿主左导航专属,皮肤按左导航语义覆盖它,面板消费会失去填充)。换面板表面 = 覆写 `--dsw-alias-bg-layer-1`。
- **终端/编辑器表面**:`effectiveTokenValue` 读 `--dsw-alias-bg-base`——`transparent` 与 alpha < 0.9 的半透明值回退不透明底色(文字不叠背景画,issue #90);≥ 0.9 放行。
- **根锚点**:宿主 div 带 `data-dsh-better-sidebar`(append 到 body);其内**面板宿主层** `[data-dsh-panel-host]`(`fixed; inset:0; z-25; pointer-events:none; overflow:hidden+clip`,v0.13.1+),面板/开关簇 absolute 定位,免疫中间层 transform 劫持;页面级 transform 触发 `data-dsh-panel-host-degraded` 降级。`overflow` 级联是**契约**(`hidden` 兜底 + `clip` 收尾,`tests/panel-host-css.spec.ts` 守护):`hidden` 盒子仍是滚动容器,脚本滚动或浏览器 scroll-into-view 修正(焦点移入视口外区域、嵌套 iframe/工作台加载时抢焦点、面板滑出动画中 focus() 落点)会沿最近可滚祖先滚走整层——面板与开关簇集体偏离视口角(computed left/right 仍"正确",偏移藏在盒子自身 scroll offset 里);`clip` 裁剪语义相同但不产生滚动盒,任何路径都滚不动这层。皮肤作用域覆盖限定在 `[data-dsh-better-sidebar]` 内。
- **根锚点**:宿主 div 带 `data-dsh-better-sidebar`(append 到 body);其内**面板宿主层** `[data-dsh-panel-host]`(`fixed; inset:0; height:100vh 兜底 + 100dvh; z-25; pointer-events:none; overflow:hidden+clip`,v0.13.1+),面板/开关簇 absolute 定位,免疫中间层 transform 劫持;页面级 transform 触发 `data-dsh-panel-host-degraded` 降级。显式高度同样**契约**(`tests/panel-host-css.spec.ts` 守护):不得依赖包含块(`100%` / `auto`,issue #616);`dvh` 必须排在 `vh` 之后——`vh` 取的是大视口,手机地址栏展开时该层高于布局视口,会误触发挂载自检、把宿主降级成 `absolute` 并撑高文档(issue #1014)。`overflow` 级联是**契约**(`hidden` 兜底 + `clip` 收尾,`tests/panel-host-css.spec.ts` 守护):`hidden` 盒子仍是滚动容器,脚本滚动或浏览器 scroll-into-view 修正(焦点移入视口外区域、嵌套 iframe/工作台加载时抢焦点、面板滑出动画中 focus() 落点)会沿最近可滚祖先滚走整层——面板与开关簇集体偏离视口角(computed left/right 仍"正确",偏移藏在盒子自身 scroll offset 里);`clip` 裁剪语义相同但不产生滚动盒,任何路径都滚不动这层。皮肤作用域覆盖限定在 `[data-dsh-better-sidebar]` 内。
- **布局变量**(`<html>` 上,面板打开时有效):`--dsh-sidebar-width` / `--dsh-sidebar-height`。右面板宽度 = AppFrame 的 `padding-right` 预留(新版 `#root [data-dsh-frame]` / rc.8 `#root > [data-slot="root"] > div` 双锚点),AppFrame border box 保持完整桌面视口宽度(Harness 以此判定桌面/窄屏布局,避免插件面板展开误入窄屏);AppFrame 的 details 拖拽手柄按同一变量向左平移贴合列边缘。底部面板仍走 centerCol `margin-bottom`;centerCol 锚点 = **JS 标注**(禁止 `nth-child`):侧栏 shell 的定位器给测得的 centerCol 节点打 `[data-dsh-center-col]` 标签(`Sidebar.tsx` locate,节点更换/HMR 时随 ref 迁移),`layout.css` 用 `#root [data-dsh-center-col]` 选中(`drag-layout.e2e.ts` 断言恰一节点且为对话槽宿主的父级——alpha.2 起 shell 把 `#root [data-slot="main.conversation"]` 解析进列并跳过 `display: contents` 祖先(`center-column.ts` 的 `CENTER_COLUMN_SELECTOR` 同时认 `main.conversation` 与 alpha.1 的 `conversation`),定位器从槽宿主向上取第一个非 `contents` 的祖先;frame 宽度与桌面 Session Log 由 `desktop-layout.e2e.ts` 断言)。
- **用户空间 CSS(v0.14.1+;titleBar 让位机制移除后只剩它)**:`SidebarPrefs.customCss`(设置页「自定义 CSS」分组)注入 `<style data-dsh-custom-css="custom">` 到 head 末尾(后写胜出;覆盖 JS 内联需 `!important`),fiber 卸载即移除,**非空即生效**(不再有方案门控)。稳定寻址面:`[data-dsh-toggle-cluster]` / `[data-dsh-panel]` / `[data-dsh-bottom-panel]`。
- **已移除:位置兼容模式 / titleBar 让位机制**(v0.14.1 引入,本次整体删除,见 [docs/plans/2026-10-05-remove-titlebar-compat-strip.md](plans/2026-10-05-remove-titlebar-compat-strip.md))。历史模型是四方案 `titleBarScheme`(`auto` / `web` / 壳预设 / `custom`),由 `src/client/titlebar-strip.ts` 的纯函数按「壳自带 `ctx.desktopWindow` 契约 → `navigator.windowControlsOverlay` 真实几何 → URL `dsh-desktop-titlebar-inset` → 壳预设 → 手动 px」求出顶栏让位高度,写 `body[data-dsh-title-bar-compat]` + `--dsh-title-bar-strip`。删除原因:插件自 v0.19.0 起不再自绘顶部 chrome,**CSS 里没有任何规则读这两个值**,宿主也不读这条契约(用户想移动的侧边栏按钮是宿主原生控件,插件没有它的位置 API),于是改设置只写变量、什么都不动;而设置项描述与现实不符。
+21 -7
View File
@@ -42,12 +42,26 @@
containing block with the ancestor's own padding box. The shell's content
is itself fixed/viewport-sized, so that box is zero-height: the host
collapses to 0px and the whole native right sidebar goes invisible while
its DOM (and every panel in it) is fully present. `vh` is measured
against the viewport instead, so the height survives any ancestor's
containing-block games; the over-constrained triple (top: 0 + height +
bottom: 0) resolves by ignoring `bottom`, keeping this a top-anchored
viewport-height layer. */
its DOM (and every panel in it) is fully present. Viewport units are
measured against the viewport instead, so the height survives any
ancestor's containing-block games; the over-constrained triple (top: 0 +
height + bottom: 0) resolves by ignoring `bottom`, keeping this a
top-anchored viewport-height layer.
TWO declarations, cascade order is the contract (issue #1014). `vh` is
the LARGE viewport: on a mobile browser with its URL bar showing, the
layer resolves taller than the layout viewport (`innerHeight`), and the
mount self-check in index.tsx reads a rect.height that far from
`innerHeight` as a page-level transform. It then flips degraded mode,
whose `position: absolute` DOES contribute to the document's height —
the whole page starts scrolling and the shifted layer keeps the check
failing, so it never recovers (#1014's "exit and re-enter" repro).
`dvh` tracks the dynamic viewport, which is what `innerHeight`
reports. Declared last so it wins; `vh` stays first as the fallback for
engines without dvh — they keep the #616 fix unchanged and only mobile
browsers with a retractable URL bar are affected by the old value. */
height: 100vh;
height: 100dvh;
z-index: 25;
pointer-events: none;
/* Clip at the viewport edge: collapsed panels slide off-screen with
@@ -55,8 +69,8 @@
contributes to its ancestors' scrollable overflow — without this the
hidden panels extended the document's scrollable area, making the whole
page draggable left-right and up-down while any panel was collapsed.
The host is exactly viewport-sized (inset: 0 + the explicit 100vh
height above), so the clip is invisible
The host is exactly viewport-sized (inset: 0 + the explicit viewport
height above, `vh` fallback then `dvh`), so the clip is invisible
until a panel slides in from the edge; internal scroll containers and
the app's fixed overlay stack are unaffected. `clip`, not `hidden`: a
hidden box stays a PROGRAMMATICALLY scrollable container, and a
+23 -7
View File
@@ -13,6 +13,9 @@
* own scroll offset). `overflow: clip` declared AFTER `hidden` keeps the
* `hidden` fallback for engines without clip support and removes the
* scrollability everywhere else; the cascade order is part of the contract.
*
* The rule's explicit viewport height is the other half of the contract
* (issues #616 / #1014) — see the height test below.
*/
import { readFileSync } from 'node:fs'
import { describe, expect, it } from 'vitest'
@@ -37,7 +40,7 @@ describe('panel host layer css', () => {
expect(hostRule).toMatch(/inset:\s*0/)
})
it('pins an explicit viewport height, never a containing-block derivation (#616)', () => {
it('pins an explicit viewport height, never a containing-block derivation (#616), dynamic unit last (#1014)', () => {
// `inset: 0` alone sizes a fixed box from its CONTAINING BLOCK, and a
// page-level `filter` / `backdrop-filter` / `transform` — exactly what a
// glass skin puts on the shell wrapper or on <body> itself — REPLACES
@@ -45,16 +48,29 @@ describe('panel host layer css', () => {
// content is itself fixed/viewport-sized, so that box is zero-height: the
// host collapses to 0px and the entire native right sidebar goes
// invisible while its DOM (and every panel inside) is fully present.
// `vh` resolves against the viewport, so the explicit height survives the
// swap; `auto` / `100%` do not, which is what this pin rejects.
// Viewport units resolve against the viewport, so the explicit height
// survives the swap; `auto` / `100%` do not, which is what this pin
// rejects.
//
// CASCADE ORDER is the rest of the contract (#1014): `vh` measures the
// LARGE viewport, so on a mobile browser whose URL bar is showing the
// layer is taller than the layout viewport (`innerHeight`). The mount
// self-check (src/client/index.tsx, `rect.height - innerHeight` beyond
// 8px) reads that mismatch as a page-level transform, flips degraded mode
// (`position: absolute`) — and an absolute oversized layer DOES
// contribute to document height, so the whole page becomes scrollable.
// `dvh` tracks the dynamic viewport (what `innerHeight` reports), so it
// is declared LAST and wins; `vh` stays FIRST as the no-dvh fallback
// (those engines keep today's #616 fix and simply ignore the `dvh` line).
expect(hostRule, 'the [data-dsh-panel-host] rule must exist').toBeDefined()
const heights = stripComments(hostRule!).match(/(?:^|[;{])\s*height\s*:\s*[^;}]+/g) ?? []
// Pin the WHOLE list, not the first hit: a second, later `height`
// (`auto` / `100%`) would win the cascade and silently restore the
// collapse. Sub-properties (`max-height`, `line-height`) do not match.
// Pin the WHOLE list, not the first hit: a later `height` (`auto` /
// `100%`) would win the cascade and silently restore the collapse, and a
// dropped `dvh` silently restores the mobile whole-page scroll.
// Sub-properties (`max-height`, `line-height`) do not match.
expect(
heights.map((declaration) => declaration.replace(/^[;{]\s*/, '').replace(/\s+/g, ' ').trim()),
).toEqual(['height: 100vh'])
).toEqual(['height: 100vh', 'height: 100dvh'])
})
it('does not reintroduce overflow on the degraded (absolute) layer', () => {