diff --git a/webui/browser/history-hydration.spec.ts b/webui/browser/history-hydration.spec.ts index 88e962b57..1c708b26c 100644 --- a/webui/browser/history-hydration.spec.ts +++ b/webui/browser/history-hydration.spec.ts @@ -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(); diff --git a/webui/src/components/thread/ThreadShell.tsx b/webui/src/components/thread/ThreadShell.tsx index 487ce9c02..069640f97 100644 --- a/webui/src/components/thread/ThreadShell.tsx +++ b/webui/src/components/thread/ThreadShell.tsx @@ -586,23 +586,22 @@ export function ThreadShell({ const shellRef = useRef(null); const [conversationElement, setConversationElement] = useState(null); const [composerSurface, setComposerSurface] = useState(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(null); const filePreviewResizeCleanupRef = useRef<(() => void) | null>(null); @@ -1555,6 +1554,7 @@ export function ThreadShell({ emptyState={emptyState} initialLoading={initialHistoryLoading} composer={inlineComposer ?
: null} + onComposerLayoutChange={alignSidebar} activeTurnId={viewportTurnId} activeTurnStartedHere={activeTurnStartedHere} conversationKey={historyKey} diff --git a/webui/src/components/thread/ThreadViewport.tsx b/webui/src/components/thread/ThreadViewport.tsx index 58850abde..1693a0959 100644 --- a/webui/src/components/thread/ThreadViewport.tsx +++ b/webui/src/components/thread/ThreadViewport.tsx @@ -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(null); const emptyStateRef = useRef(null); const composerDockRef = useRef(null); + const composerLayoutChangeRef = useRef(onComposerLayoutChange); + composerLayoutChangeRef.current = onComposerLayoutChange; const bottomRef = useRef(null); const lastConversationKeyRef = useRef(conversationKey); const conversationHandoffPendingRef = useRef(false); @@ -399,6 +403,7 @@ export const ThreadViewport = forwardRef { + 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 { 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