fix(webui): align context sidebar through viewport layout changes
This commit is contained in:
1 parent
e4e04768d2
commit
283e486e0b
3 files changed
+29
-16
No files matched your search
@@ -289,8 +289,9 @@ test("synthetic HTTP-first cumulative text suppresses delayed covered chunks but
|
||||
backend.healthy();
|
||||
});
|
||||
|
||||
test("the open context sidebar keeps its slot while a new conversation hydrates", async ({ page }) => {
|
||||
test("the open context sidebar keeps its slot through hydration and empty conversation transitions", async ({ page }) => {
|
||||
const { backend } = await openFixture(page);
|
||||
await page.emulateMedia({ reducedMotion: "no-preference" });
|
||||
const contextHistory = (chatId: string, name: string, tokens: number) => {
|
||||
const turn = `${chatId}-context`;
|
||||
return history([
|
||||
@@ -311,6 +312,9 @@ test("the open context sidebar keeps its slot while a new conversation hydrates"
|
||||
await expect(sidebar.getByRole("progressbar")).toHaveAttribute("aria-valuenow", "10");
|
||||
await sidebar.evaluate((node) => node.setAttribute("data-session-slot", "retained"));
|
||||
const expectSlot = async () => {
|
||||
await page.locator(".thread-layout").evaluate(async (node) => {
|
||||
await Promise.all(node.getAnimations().map((animation) => animation.finished));
|
||||
});
|
||||
await expect(sidebar).toHaveAttribute("data-session-slot", "retained");
|
||||
await expect.poll(() => sidebar.evaluate((node) => node.getBoundingClientRect().width)).toBe(420);
|
||||
await expect.poll(() => sidebar.locator(".file-preview-content").evaluate((node) => {
|
||||
@@ -328,7 +332,10 @@ test("the open context sidebar keeps its slot while a new conversation hydrates"
|
||||
await expect(sidebar.getByRole("progressbar")).not.toHaveAttribute("aria-valuenow");
|
||||
await expectSlot();
|
||||
|
||||
await backend.release(target, contextHistory(B, "second.md", 2000));
|
||||
await backend.release(target, history([], { chatId: B }));
|
||||
await expect(page.locator('.thread-layout[data-layout="hero"]')).toBeVisible();
|
||||
await expectSlot();
|
||||
for (const event of contextHistory(B, "second.md", 2000).events) await backend.send(event);
|
||||
await expect(sidebar.getByRole("button", { name: "second.md", exact: true })).toBeVisible();
|
||||
await expect(sidebar.getByRole("progressbar")).toHaveAttribute("aria-valuenow", "20");
|
||||
await expectSlot();
|
||||
|
||||
@@ -586,23 +586,22 @@ export function ThreadShell({
|
||||
const shellRef = useRef<HTMLElement | null>(null);
|
||||
const [conversationElement, setConversationElement] = useState<HTMLDivElement | null>(null);
|
||||
const [composerSurface, setComposerSurface] = useState<HTMLDivElement | null>(null);
|
||||
const alignSidebar = useCallback(() => {
|
||||
if (!sidebarOpen || !inlineComposer || !contextSidebarHost || !composerSurface) return;
|
||||
// Metadata can wrap below the input card. The viewport also reports grid
|
||||
// movement, which changes the surface's position without resizing it.
|
||||
const inset = contextSidebarHost.getBoundingClientRect().bottom - composerSurface.getBoundingClientRect().bottom;
|
||||
contextSidebarHost.style.setProperty("--sidebar-bottom-inset", `${Math.max(0, inset)}px`);
|
||||
}, [contextSidebarHost, composerSurface, sidebarOpen, inlineComposer]);
|
||||
useLayoutEffect(() => {
|
||||
const shell = contextSidebarHost;
|
||||
const surface = composerSurface;
|
||||
if (!sidebarOpen || !inlineComposer || !shell || !surface) return;
|
||||
// Metadata can wrap below the input card. Align sidebars to the visible
|
||||
// surface, rather than assuming a fixed composer/footer padding.
|
||||
const alignSidebar = () => {
|
||||
const inset = shell.getBoundingClientRect().bottom - surface.getBoundingClientRect().bottom;
|
||||
shell.style.setProperty("--sidebar-bottom-inset", `${Math.max(0, inset)}px`);
|
||||
};
|
||||
if (!sidebarOpen || !inlineComposer || !contextSidebarHost || !composerSurface) return;
|
||||
alignSidebar();
|
||||
const observer = new ResizeObserver(alignSidebar);
|
||||
observer.observe(shell);
|
||||
observer.observe(contextSidebarHost);
|
||||
observer.observe(composerMount);
|
||||
observer.observe(surface);
|
||||
observer.observe(composerSurface);
|
||||
return () => observer.disconnect();
|
||||
}, [contextSidebarHost, sidebarOpen, inlineComposer, composerDestination, composerMount, composerSurface]);
|
||||
}, [alignSidebar, contextSidebarHost, sidebarOpen, inlineComposer, composerDestination, composerMount, composerSurface]);
|
||||
const filePreviewWidthRef = useRef(FILE_PREVIEW_DEFAULT_WIDTH);
|
||||
const filePreviewCloseTimerRef = useRef<number | null>(null);
|
||||
const filePreviewResizeCleanupRef = useRef<(() => void) | null>(null);
|
||||
@@ -1555,6 +1554,7 @@ export function ThreadShell({
|
||||
emptyState={emptyState}
|
||||
initialLoading={initialHistoryLoading}
|
||||
composer={inlineComposer ? <div ref={setLocalComposerHost} /> : null}
|
||||
onComposerLayoutChange={alignSidebar}
|
||||
activeTurnId={viewportTurnId}
|
||||
activeTurnStartedHere={activeTurnStartedHere}
|
||||
conversationKey={historyKey}
|
||||
|
||||
@@ -46,6 +46,7 @@ interface ThreadViewportProps {
|
||||
runStartedAt?: number | null;
|
||||
retryStatus?: RetryStatus | null;
|
||||
composer?: ReactNode;
|
||||
onComposerLayoutChange?: () => void;
|
||||
navigationFrame?: HTMLElement | null;
|
||||
emptyState?: ReactNode;
|
||||
initialLoading?: boolean;
|
||||
@@ -259,6 +260,7 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
|
||||
runStartedAt = null,
|
||||
retryStatus = null,
|
||||
composer,
|
||||
onComposerLayoutChange,
|
||||
navigationFrame,
|
||||
emptyState,
|
||||
initialLoading = false,
|
||||
@@ -302,6 +304,8 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
|
||||
const messageContentRef = useRef<HTMLDivElement>(null);
|
||||
const emptyStateRef = useRef<HTMLDivElement>(null);
|
||||
const composerDockRef = useRef<HTMLDivElement>(null);
|
||||
const composerLayoutChangeRef = useRef(onComposerLayoutChange);
|
||||
composerLayoutChangeRef.current = onComposerLayoutChange;
|
||||
const bottomRef = useRef<HTMLDivElement>(null);
|
||||
const lastConversationKeyRef = useRef<string | null>(conversationKey);
|
||||
const conversationHandoffPendingRef = useRef(false);
|
||||
@@ -399,6 +403,7 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
|
||||
};
|
||||
},
|
||||
onGeometry: (geometry: ThreadMotionGeometry) => {
|
||||
composerLayoutChangeRef.current?.();
|
||||
if (Math.abs(composerDockHeightRef.current - geometry.composerHeight) >= 1) {
|
||||
composerDockHeightRef.current = geometry.composerHeight;
|
||||
setComposerDockHeight(geometry.composerHeight);
|
||||
@@ -878,7 +883,8 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
|
||||
useLayoutEffect(() => {
|
||||
const el = scrollRef.current;
|
||||
const content = contentRef.current;
|
||||
const messageRegion = messageRegionRef.current;
|
||||
// The flexible first grid row moves the composer during hero/thread transitions.
|
||||
const contentRegion = messageRegionRef.current ?? emptyStateRef.current;
|
||||
const messageContent = messageContentRef.current;
|
||||
const composerDock = composerDockRef.current;
|
||||
if (!el) return;
|
||||
@@ -896,7 +902,7 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
|
||||
: new ResizeObserver(reconcileObservedGeometry);
|
||||
observer?.observe(el);
|
||||
if (content) observer?.observe(content);
|
||||
if (messageRegion) observer?.observe(messageRegion);
|
||||
if (contentRegion) observer?.observe(contentRegion);
|
||||
if (messageContent) observer?.observe(messageContent);
|
||||
if (composerDock) observer?.observe(composerDock);
|
||||
window.addEventListener("resize", invalidateGeometry);
|
||||
|
||||
Reference in new issue
Block a user