diff --git a/packages/client/ui-chat/README.i18n.yaml b/packages/client/ui-chat/README.i18n.yaml index 2dc317ad69..f9b09eb73f 100644 --- a/packages/client/ui-chat/README.i18n.yaml +++ b/packages/client/ui-chat/README.i18n.yaml @@ -39,8 +39,8 @@ en: f6d8bbae13a1a8f8 zh: 96c8f400c215e33d /deepseek-ai-dsh-client-ui-chat/scroll-ownership: - en: 983f27806146e9ea - zh: bb60333c7a6736ed + en: 26d32be41a7bb8af + zh: 3a5f8a10ec8a271f /deepseek-ai-dsh-client-ui-chat/model-experience: en: c17b4dd43a61c569 zh: f7414309810c3a08 diff --git a/packages/client/ui-chat/README.md b/packages/client/ui-chat/README.md index e4b1ec62d5..fb0bf43efd 100644 --- a/packages/client/ui-chat/README.md +++ b/packages/client/ui-chat/README.md @@ -160,7 +160,7 @@ Chat restores semantic anchors across history prepend and renderer remounts, wit The turn rail and back-to-bottom button sit outside the clipped transcript. They use the shared conversation scrollport for sticky positioning, or the Chat frame for absolute positioning when Chat owns its scrollport. The rail sits at the scrollport's start edge, which leaves the end gutter to the [Session panel](../ui-session-panel/README.md), and its previews open toward the transcript. The rail hides when the transcript's available width, excluding its horizontal padding, is at most 900px; the browser viewport width is not the criterion. -The `conversation.chat.aside` slot holds one Session-level occupant beside the transcript, such as the [Session panel](../ui-session-panel/README.md). Every Chat View occurrence, main or embedded, renders it in a zero-height layer at the top of the Chat frame, positioned like the turn rail, so it stays in place while the transcript scrolls and inherits `--dsh-composer-height` and `--dsh-conversation-viewport-height` from the shared scrollport. The layer stacks above the turn rail and the back-to-bottom button and passes pointer events through. Its owner prop `endGutter` is half the width the frame leaves around the transcript column, in whole CSS px, computed from the widths a `ResizeObserver` reports for the layer and the column. It follows window and sidebar resizes and dragged column widths without reading element geometry, stays zero without `ResizeObserver`, and re-renders the layer only when it changes. +The `conversation.chat.aside` slot holds one Session-level occupant beside the transcript, such as the [Session panel](../ui-session-panel/README.md). Every Chat View occurrence, main or embedded, renders it in a zero-height layer at the top of the Chat frame, positioned like the turn rail, so it stays in place while the transcript scrolls and inherits `--dsh-composer-height` and `--dsh-conversation-viewport-height` from the shared scrollport. The layer stacks above the turn rail and the back-to-bottom button and passes pointer events through. Its owner prop `endGutter` is an observable source of half the width the frame leaves around the transcript column, in whole CSS px, computed from the widths a `ResizeObserver` reports for the layer and the column. It follows window and sidebar resizes and dragged column widths without reading element geometry and stays zero without `ResizeObserver`. The source keeps its identity, so the layer renders once and a resize re-renders only an occupant whose derived value changes; an occupant sizes itself in CSS, where the same gutter is `(100% - var(--dsh-chat-content-width)) / 2` of the layer. The transcript root uses `overflow-x: visible; overflow-y: clip`: vertical overflow is clipped without creating a scroll container. Sticky Markdown code banners and expanded compaction headers therefore retain the actual conversation scrollport as their reference when no nearer scrolling ancestor exists. Capped process groups and terminal sections keep their own scrollports. diff --git a/packages/client/ui-chat/README.zh.md b/packages/client/ui-chat/README.zh.md index d470865a92..dab40b7fbc 100644 --- a/packages/client/ui-chat/README.zh.md +++ b/packages/client/ui-chat/README.zh.md @@ -160,7 +160,7 @@ Chat 会在历史前插与 renderer 重新挂载时恢复语义锚点,并且 轮次轨道与回到底部按钮位于正文裁剪层外。它们相对共享会话滚动容器做 sticky 定位;Chat 自己持有滚动容器时,则相对 Chat 外框做 absolute 定位。轮次轨道贴在滚动容器的起始边,把末端留白让给[会话面板](../ui-session-panel/README.zh.md),预览朝正文方向弹出。正文扣除水平内边距后的可用宽度不超过 900px 时,隐藏轮次轨道;判断依据不是浏览器视口宽度。 -`conversation.chat.aside` slot 放一个位于正文旁边、面向整个会话的组件,例如[会话面板](../ui-session-panel/README.zh.md)。每个 Chat 视图实例(主正文区或嵌入的)都会渲染它:它位于 Chat 外框顶部的零高度图层中,定位方式与轮次轨道相同,因此不随正文滚动,并从共享滚动容器继承 `--dsh-composer-height` 与 `--dsh-conversation-viewport-height`。该图层叠在轮次轨道与回到底部按钮之上,自身不拦截指针事件。owner 属性 `endGutter` 是外框在正文列两侧留出宽度的一半(整数 CSS px),由 `ResizeObserver` 报告的图层与正文列宽度算出。它跟随窗口、侧栏尺寸变化和拖动后的正文宽度,不读取元素几何;没有 `ResizeObserver` 时保持为 0;只有它变化时图层才重新渲染。 +`conversation.chat.aside` slot 放一个位于正文旁边、面向整个会话的组件,例如[会话面板](../ui-session-panel/README.zh.md)。每个 Chat 视图实例(主正文区或嵌入的)都会渲染它:它位于 Chat 外框顶部的零高度图层中,定位方式与轮次轨道相同,因此不随正文滚动,并从共享滚动容器继承 `--dsh-composer-height` 与 `--dsh-conversation-viewport-height`。该图层叠在轮次轨道与回到底部按钮之上,自身不拦截指针事件。owner 属性 `endGutter` 是一个可订阅的数据源,值为外框在正文列两侧留出宽度的一半(整数 CSS px),由 `ResizeObserver` 报告的图层与正文列宽度算出。它跟随窗口、侧栏尺寸变化和拖动后的正文宽度,不读取元素几何;没有 `ResizeObserver` 时保持为 0。数据源的引用不变,因此图层只渲染一次,尺寸变化只让由它推导出的值发生变化的占位组件重新渲染;占位组件用 CSS 决定自身尺寸,同一留白在图层中为 `(100% - var(--dsh-chat-content-width)) / 2`。 正文根节点使用 `overflow-x: visible; overflow-y: clip`:裁剪纵向溢出,但不创建滚动容器。因此,在没有更近的滚动祖先时,Markdown 代码块的 sticky 头栏和展开的压缩摘要头栏仍以实际会话滚动容器为参照。限高过程组和终端区域保留各自的滚动容器。 diff --git a/packages/client/ui-chat/src/client/chat/ChatAside.tsx b/packages/client/ui-chat/src/client/chat/ChatAside.tsx index fd04a76b3f..99f4ecf6e3 100644 --- a/packages/client/ui-chat/src/client/chat/ChatAside.tsx +++ b/packages/client/ui-chat/src/client/chat/ChatAside.tsx @@ -1,5 +1,6 @@ -/** The Chat View's aside layer: one Session-level occupant beside the transcript, given the end gutter it keeps within. */ +/** The Chat View's aside layer: one Session-level occupant beside the transcript, given the end gutter as an observable source. */ import { memo, useLayoutEffect, useMemo, useRef, useState, type RefObject } from 'react' +import { createSnapshotStore, type ObservableSnapshot } from '@deepseek-ai/dsh-client-store' import type { PropsRenderSlots } from '@deepseek-ai/dsh-client-ui-slots' import type { ChatAsideOwnerProps } from '../contract/slots.ts' import css from './ChatView.module.css' @@ -9,12 +10,16 @@ import css from './ChatView.module.css' * layer, which spans the Chat frame, and for the transcript column, which * covers window and sidebar resizes and a dragged column width. The column * is centered in the frame, so the gutter is half their difference; no - * element geometry is read. Without ResizeObserver the gutter stays zero. + * element geometry is read. Each change is published to the returned source, + * so the layer itself never re-renders for a resize. Without ResizeObserver + * the gutter stays zero. * @param layer - the aside layer, a child of the Chat frame that precedes the transcript column. - * @returns the gutter in whole CSS px, zero until both widths are known. + * @returns the gutter in whole CSS px, zero until both widths are known; one source for the layer's lifetime. */ -function useEndGutter(layer: RefObject): number { - const [gutter, setGutter] = useState(0) +function useEndGutter(layer: RefObject): ObservableSnapshot { + const [gutter] = useState(() => createSnapshotStore(0)) + // Observing before the first paint lets the first report land before that paint, so an occupant that the gutter + // shows, such as a docked panel, does not miss the frame in which its Chat View mounts. useLayoutEffect(() => { if (typeof ResizeObserver === 'undefined') return // The frame's DOM is in place, though its own refs attach after this child's layout effect. @@ -28,19 +33,19 @@ function useEndGutter(layer: RefObject): number { else columnWidth = entry.contentRect.width } if (layerWidth === undefined || columnWidth === undefined) return - setGutter(Math.max(0, Math.round((layerWidth - columnWidth) / 2))) + gutter.set(Math.max(0, Math.round((layerWidth - columnWidth) / 2))) }) observer.observe(layerElement) observer.observe(column) return () => { observer.disconnect() } - }, [layer]) + }, [layer, gutter]) return gutter } /** * Render the aside layer with its occupant. The Chat View's `renderSlot` is - * stable per registration, so the layer re-renders only when the gutter - * changes, not with every transcript update. + * stable per registration and the gutter source keeps its identity, so the + * layer renders once: neither transcript updates nor resizes re-render it. * @param props - the Chat View's slot renderer. * @returns the zero-height aside layer. */ diff --git a/packages/client/ui-chat/src/client/contract/slots.ts b/packages/client/ui-chat/src/client/contract/slots.ts index 47566f6a34..4430c81374 100644 --- a/packages/client/ui-chat/src/client/contract/slots.ts +++ b/packages/client/ui-chat/src/client/contract/slots.ts @@ -391,10 +391,14 @@ export type ChatFlowSlotProps = export interface ChatAsideOwnerProps { /** * Inline space in CSS px between the transcript column's end edge and the - * Chat frame's end edge, measured again whenever the frame or the column - * resizes; zero before the first measurement. + * Chat frame's end edge, followed whenever the frame or the column resizes; + * zero before the first measurement. The source keeps its identity for the + * layer's lifetime and publishes changes without re-rendering the layer, so + * an occupant subscribes for the decisions it derives from the gutter and + * sizes itself in CSS, where the gutter is + * `(100% - var(--dsh-chat-content-width)) / 2` of the layer. */ - readonly endGutter: number + readonly endGutter: ObservableSnapshot } /** Full Chat view props. */ @@ -448,7 +452,7 @@ declare module '@deepseek-ai/dsh-client-ui-slots' { * scrolls and inherits the shared scrollport's composer and viewport * heights. The layer passes pointer events through; the occupant * positions itself in it, enables its own pointer events, and keeps - * within `endGutter` to stay clear of the transcript column. + * within the end gutter to stay clear of the transcript column. */ 'conversation.chat.aside': { kind: 'single'; scope: 'session'; owner: ChatAsideOwnerProps } diff --git a/packages/client/ui-chat/tests/chat-view.client.spec.tsx b/packages/client/ui-chat/tests/chat-view.client.spec.tsx index 26797e8de5..47a58a9660 100644 --- a/packages/client/ui-chat/tests/chat-view.client.spec.tsx +++ b/packages/client/ui-chat/tests/chat-view.client.spec.tsx @@ -869,7 +869,7 @@ describe('Chat node rendering', () => { }) describe('ChatView', () => { - it('renders the aside with half the width the frame leaves around the transcript column, following resizes', () => { + it('gives the aside a gutter source that follows half the width the frame leaves around the transcript column, rendering the aside once', () => { const observers: { callback: ResizeObserverCallback; targets: Element[] }[] = [] vi.stubGlobal('ResizeObserver', class { readonly targets: Element[] = [] @@ -892,31 +892,34 @@ describe('ChatView', () => { const entries = sizes.map(([target, width]) => ({ target, contentRect: { width } }) as ResizeObserverEntry) act(() => { gutter?.callback(entries, {} as ResizeObserver) }) } + expect(h.asideOwners).toHaveLength(1) + const source = (h.asideOwners[0] as ChatAsideOwnerProps).endGutter + const published: number[] = [] + const off = source.subscribe(() => { published.push(source.getSnapshot()) }) // Nothing is known until both widths arrive. deliver([layer, 1600.4]) - expect(h.asideOwners.at(-1)).toEqual({ endGutter: 0 }) + expect(source.getSnapshot()).toBe(0) deliver([column, 760]) - expect(h.asideOwners.at(-1)).toEqual({ endGutter: 420 }) + expect(source.getSnapshot()).toBe(420) deliver([column, 880]) - expect(h.asideOwners.at(-1)).toEqual({ endGutter: 360 }) - // Height-only growth reports the same widths and keeps the owner identity. - const owner = h.asideOwners.at(-1) + expect(source.getSnapshot()).toBe(360) + // Height-only growth reports the same widths and publishes nothing. deliver([column, 880]) - expect(h.asideOwners.at(-1)).toBe(owner) deliver([layer, 700]) - expect(h.asideOwners.at(-1)).toEqual({ endGutter: 0 }) + expect(source.getSnapshot()).toBe(0) + expect(published).toEqual([420, 360, 0]) + off() expect(rect).not.toHaveBeenCalled() - // Transcript updates do not re-render the aside. - const settled = h.asideOwners.length + // Neither resizes nor transcript updates re-render the aside. act(() => { h.setSession({ running: true }) }) - expect(h.asideOwners).toHaveLength(settled) + expect(h.asideOwners).toHaveLength(1) }) it('keeps the aside gutter at zero without ResizeObserver', () => { vi.stubGlobal('ResizeObserver', undefined) const h = makeHarness({}, {}, chatSnapshotFixture({ nodes: [user(1, 'hello')] })) render() - expect(h.asideOwners.at(-1)).toEqual({ endGutter: 0 }) + expect((h.asideOwners.at(-1) as ChatAsideOwnerProps).endGutter.getSnapshot()).toBe(0) }) it('renders only referenced Nodes without deleting unreferenced Node data', () => { diff --git a/packages/client/ui-session-panel/README.i18n.yaml b/packages/client/ui-session-panel/README.i18n.yaml index 046ccc1665..2029add923 100644 --- a/packages/client/ui-session-panel/README.i18n.yaml +++ b/packages/client/ui-session-panel/README.i18n.yaml @@ -24,11 +24,11 @@ en: a297c196bb631928 zh: 523b71276d8f847e /deepseek-ai-dsh-client-ui-session-panel/understand-the-implementation: - en: f996b40c78ce18ba - zh: d66ed6289f8eed50 + en: a6e70aa8e7e3e7fa + zh: 2633f04bbf1e6711 /deepseek-ai-dsh-client-ui-session-panel/further-exploration: - en: 5fa707ada69696c4 - zh: 595d8b2d7de42181 + en: 413e4e321768d4b2 + zh: 85444059cd1dc565 /deepseek-ai-dsh-client-ui-session-panel/model-experience: en: 7e8bbe318a76fd54 zh: c60e87da2a37642a diff --git a/packages/client/ui-session-panel/README.md b/packages/client/ui-session-panel/README.md index 14e46b9f2a..af48338ced 100644 --- a/packages/client/ui-session-panel/README.md +++ b/packages/client/ui-session-panel/README.md @@ -54,7 +54,7 @@ Summary rows from every package use the `PanelRow` primitive, so icon, text, and
Implementation internals — click to expand -The panel is the `conversation.chat.aside` occupant of [`dsh-client-ui-chat`](../ui-chat/README.md#scroll-ownership), so it renders only in Chat Views. The toggle and the panel are separate Slot entries that share one plugin-owned state: the persisted docking preference, the Session whose overlay is open, and the end gutter each mounted panel reports from its `endGutter` owner prop. A panel withdraws its report when it unmounts or its Chat View moves to another Session. The panel decides its presentation from its own gutter; the toggle reads the widest gutter of its Session, and a Session without one shows no Chat View. Both decide with the same pure function, so the toggle's state never disagrees with the panel. The aside layer inherits the scrollport's composer and viewport heights, and the docked width follows the gutter through `--dsh-session-panel-gutter`. +The panel is the `conversation.chat.aside` occupant of [`dsh-client-ui-chat`](../ui-chat/README.md#scroll-ownership), so it renders only in Chat Views. The toggle and the panel are separate Slot entries that share one plugin-owned state: the persisted docking preference, the Session whose overlay is open, and whether each Session has room to dock. Each mounted panel registers the `endGutter` source of its Chat View with that state, and stops when it unmounts or its Chat View moves to another Session; a Session has room while any of its sources holds the docked panel, and a Session without a source shows no Chat View. The panel decides its presentation from its own source, and both decide with the same pure function, so the toggle's state never disagrees with the panel. The panel and the toggle subscribe only to whether the gutter holds the docked panel, so a resize renders them again only when it crosses the 344px threshold, and opening, closing, or docking the panel renders nothing in the Chat View. The aside layer inherits the scrollport's composer and viewport heights and the transcript width `--dsh-chat-content-width`, from which CSS sizes the docked panel. The panel projects the section list's live registrations (`entriesOfSlot`, so a higher-priority registration with the same `id` replaces a shipped section) into `{ id, label }` rows, recomputed only when the ledger version or the locale revision changes. It renders each section through `renderSlot(..., { only: id })` inside its own title and body; a CSS `:has()` rule hides a section whose body outlet stayed empty, including a shared section whose row outlet stayed empty. @@ -62,7 +62,7 @@ The panel projects the section list's live registrations (`entriesOfSlot`, so a |---|---| | [`src/client/index.ts`](src/client/index.ts) | Dictionaries, the toggle, the panel, the Environment section, and the project row | | [`src/client/slots.ts`](src/client/slots.ts) | Slot declarations and component props | -| [`src/client/visibility.ts`](src/client/visibility.ts) | Docking threshold, presentation, the shared visibility state, and the reported gutters | +| [`src/client/visibility.ts`](src/client/visibility.ts) | Docking threshold, presentation, the shared visibility state, and each Session's room to dock | | [`src/client/sections.ts`](src/client/sections.ts) | Section roster projection | | [`src/client/SessionPanel.tsx`](src/client/SessionPanel.tsx) | The panel, its section titles, and Escape handling | | [`src/client/SessionPanelToggle.tsx`](src/client/SessionPanelToggle.tsx) | The header toggle and its indicators | @@ -76,7 +76,7 @@ The panel projects the section list's live registrations (`entriesOfSlot`, so a ## Further Exploration - [Web Client Slots](../../../docs/subsystems/slots.md) — list, keyed, and owner-prop semantics the sections rely on. -- [`dsh-client-ui-chat`](../ui-chat/README.md#scroll-ownership) — the `conversation.chat.aside` layer and its end gutter. +- [`dsh-client-ui-chat`](../ui-chat/README.md#scroll-ownership) — the `conversation.chat.aside` layer and its end gutter source. - [`dsh-client-ui-conversation`](../ui-conversation/README.md) — the Session header utilities. - [`dsh-client-ui-primitives`](../ui-primitives/README.md#component-catalog) — `PanelRow` and `PathLabel`. diff --git a/packages/client/ui-session-panel/README.zh.md b/packages/client/ui-session-panel/README.zh.md index 0940e82797..5a6f62edc0 100644 --- a/packages/client/ui-session-panel/README.zh.md +++ b/packages/client/ui-session-panel/README.zh.md @@ -54,7 +54,7 @@ kind: "package-reference"
实现内幕——点击展开 -面板是 [`dsh-client-ui-chat`](../ui-chat/README.zh.md#scroll-ownership) 中 `conversation.chat.aside` 的占位组件,因此只渲染在 Chat 视图中。开关与面板是两个独立的 Slot 条目,共享一份插件持有的状态:持久化的停靠偏好、打开了浮层的会话,以及每个已挂载面板从 owner 属性 `endGutter` 上报的末端留白。面板卸载或其 Chat 视图换到另一个会话时撤回上报。面板根据自己的留白决定呈现方式;开关读取该会话最宽的留白,没有留白的会话表示没有 Chat 视图在显示它。两者用同一个纯函数决定,因此开关状态始终与面板一致。侧边层从滚动容器继承输入框区域与视口高度,停靠宽度通过 `--dsh-session-panel-gutter` 跟随留白。 +面板是 [`dsh-client-ui-chat`](../ui-chat/README.zh.md#scroll-ownership) 中 `conversation.chat.aside` 的占位组件,因此只渲染在 Chat 视图中。开关与面板是两个独立的 Slot 条目,共享一份插件持有的状态:持久化的停靠偏好、打开了浮层的会话,以及每个会话是否有停靠空间。每个已挂载的面板把所在 Chat 视图的 `endGutter` 数据源登记到这份状态里,面板卸载或其 Chat 视图换到另一个会话时取消登记;会话的任一数据源能容纳停靠面板时,该会话就有停靠空间,没有数据源的会话表示没有 Chat 视图在显示它。面板根据自己的数据源决定呈现方式,两者用同一个纯函数决定,因此开关状态始终与面板一致。面板与开关只订阅留白能否容纳停靠面板,因此尺寸变化只在跨过 344px 阈值时才让它们重新渲染;打开、关闭或停靠面板也不会让 Chat 视图重新渲染。侧边层从滚动容器继承输入框区域与视口高度,以及正文宽度 `--dsh-chat-content-width`,停靠宽度由 CSS 据此算出。 面板把分栏列表的实时注册(`entriesOfSlot`,因此同 `id` 且优先级更高的注册会替换已发布的分栏)投影为 `{ id, label }` 行,只在台账版本或语言版本变化时重新计算。它在各分栏自己的标题和正文容器里用 `renderSlot(..., { only: id })` 渲染内容;CSS `:has()` 规则隐藏正文出口为空的分栏,也包括行出口为空的共享分栏。 @@ -62,7 +62,7 @@ kind: "package-reference" |---|---| | [`src/client/index.ts`](src/client/index.ts) | 字典、开关、面板、「环境」分栏与项目行 | | [`src/client/slots.ts`](src/client/slots.ts) | Slot 声明与组件 props | -| [`src/client/visibility.ts`](src/client/visibility.ts) | 停靠阈值、呈现方式、共享可见性状态与上报的留白 | +| [`src/client/visibility.ts`](src/client/visibility.ts) | 停靠阈值、呈现方式、共享可见性状态与每个会话的停靠空间 | | [`src/client/sections.ts`](src/client/sections.ts) | 分栏名单投影 | | [`src/client/SessionPanel.tsx`](src/client/SessionPanel.tsx) | 面板、分栏标题与 Esc 处理 | | [`src/client/SessionPanelToggle.tsx`](src/client/SessionPanelToggle.tsx) | 标题栏开关及其角标 | @@ -76,7 +76,7 @@ kind: "package-reference" ## 进一步探索 - [Web Client Slots](../../../docs/subsystems/slots.zh.md)——分栏依赖的 list、keyed 与 owner props 语义。 -- [`dsh-client-ui-chat`](../ui-chat/README.zh.md#scroll-ownership)——`conversation.chat.aside` 图层及其末端留白。 +- [`dsh-client-ui-chat`](../ui-chat/README.zh.md#scroll-ownership)——`conversation.chat.aside` 图层及其末端留白数据源。 - [`dsh-client-ui-conversation`](../ui-conversation/README.zh.md)——会话标题栏工具区。 - [`dsh-client-ui-primitives`](../ui-primitives/README.zh.md#component-catalog)——`PanelRow` 与 `PathLabel`。 diff --git a/packages/client/ui-session-panel/src/client/SessionPanel.module.css b/packages/client/ui-session-panel/src/client/SessionPanel.module.css index 69655e3ea6..c54051e831 100644 --- a/packages/client/ui-session-panel/src/client/SessionPanel.module.css +++ b/packages/client/ui-session-panel/src/client/SessionPanel.module.css @@ -1,15 +1,16 @@ -/* The panel floats in the Chat View's aside layer, a zero-height box at the - top of the Chat frame that passes pointer events through. The layer +/* The panel floats in the Chat View's aside layer, a zero-height box across + the top of the Chat frame that passes pointer events through. The layer inherits the scrollport's --dsh-conversation-viewport-height and - --dsh-composer-height; the panel receives the Chat View's end gutter as - --dsh-session-panel-gutter. */ + --dsh-composer-height, and the transcript width --dsh-chat-content-width, + so the end gutter is half the layer width the transcript leaves. */ .panel { position: absolute; top: 12px; right: 16px; box-sizing: border-box; - /* The docked width keeps 48px clear of the transcript column and its width handle. */ - width: clamp(280px, calc(var(--dsh-session-panel-gutter, 0px) - 64px), 340px); + /* The docked width keeps 48px clear of the transcript column and its width handle, + as the back-to-bottom control computes the same gutter. */ + width: clamp(280px, calc((100% - var(--dsh-chat-content-width, 100%)) / 2 - 64px), 340px); /* Stops above the composer stack, whose seat fades and takes presses across the body's full width. */ max-height: calc(var(--dsh-conversation-viewport-height, 100dvh) - var(--dsh-composer-height, 152px) - 24px); overflow-y: auto; diff --git a/packages/client/ui-session-panel/src/client/SessionPanel.tsx b/packages/client/ui-session-panel/src/client/SessionPanel.tsx index 6061155c7f..93000a6266 100644 --- a/packages/client/ui-session-panel/src/client/SessionPanel.tsx +++ b/packages/client/ui-session-panel/src/client/SessionPanel.tsx @@ -1,6 +1,6 @@ /** Floating Session panel in the Chat View's aside: section titles drawn from the section roster, bodies from the section slot. */ import { - useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, type CSSProperties, type FocusEvent, type ReactNode, + useCallback, useEffect, useLayoutEffect, useMemo, useRef, useSyncExternalStore, type FocusEvent, type ReactNode, } from 'react' import { isBehindModal, observeComposition } from '@deepseek-ai/dsh-client-ui-primitives' import { panelElementId, toggleElementId } from './element-ids.ts' @@ -75,33 +75,23 @@ function useFocusReturn(hidden: boolean, toggleId: string): { }), []) } -/** - * Report the Chat View's end gutter for this panel while it is mounted, and - * withdraw it when the panel unmounts or its Chat View moves to another - * Session. A changed gutter replaces the report without withdrawing it. - * @param measure - records one panel's gutter. - * @param sessionId - Session the Chat View shows. - * @param endGutter - the Chat View's end gutter in CSS px. - */ -function useGutterReport(measure: SessionPanelProps['measure'], sessionId: SessionPanelProps['sessionId'], endGutter: number): void { - const instance = useId() - useLayoutEffect(() => () => { measure(sessionId, instance, null) }, [measure, sessionId, instance]) - useLayoutEffect(() => { measure(sessionId, instance, endGutter) }, [measure, sessionId, instance, endGutter]) -} - /** * Render the panel while it docks or shows as an overlay. Each section keeps * its title row and body; CSS hides a section whose body rendered nothing. - * The overlay closes on Escape and on an outside pointerdown. The docked - * width follows the Chat View's end gutter. - * @param props - Session values, the Chat View's end gutter, shared visibility, sections, the gutter report, and copy. + * The overlay closes on Escape and on an outside pointerdown. CSS sizes the + * docked panel from the transcript width; the gutter source decides only + * whether it can dock, so a resize re-renders the panel only when it crosses + * the docking threshold. + * @param props - Session values, the Chat View's end gutter source, shared visibility, sections, the gutter tracking, and copy. * @returns the panel, or null while it is hidden. */ export function SessionPanel({ - sessionId, endGutter, useVisibility, useSections, measure, closeOverlay, renderSlot, t, + sessionId, endGutter, useVisibility, useSections, track, closeOverlay, renderSlot, t, }: SessionPanelProps): ReactNode { - useGutterReport(measure, sessionId, endGutter) - const fits = fitsGutter(endGutter) + // Registered before paint, so a Chat View remount keeps the header toggle available instead of flashing unavailable. + useLayoutEffect(() => track(sessionId, endGutter), [track, sessionId, endGutter]) + const followGutter = useCallback((listener: () => void) => endGutter.subscribe(listener), [endGutter]) + const fits = useSyncExternalStore(followGutter, () => fitsGutter(endGutter.getSnapshot())) const presentation = useVisibility(visibility => presentationOf(fits, visibility, sessionId)) const sections = useSections(entries => entries) const panel = useRef(null) @@ -117,7 +107,6 @@ export function SessionPanel({