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();
|
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);
|
const { backend } = await openFixture(page);
|
||||||
|
await page.emulateMedia({ reducedMotion: "no-preference" });
|
||||||
const contextHistory = (chatId: string, name: string, tokens: number) => {
|
const contextHistory = (chatId: string, name: string, tokens: number) => {
|
||||||
const turn = `${chatId}-context`;
|
const turn = `${chatId}-context`;
|
||||||
return history([
|
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 expect(sidebar.getByRole("progressbar")).toHaveAttribute("aria-valuenow", "10");
|
||||||
await sidebar.evaluate((node) => node.setAttribute("data-session-slot", "retained"));
|
await sidebar.evaluate((node) => node.setAttribute("data-session-slot", "retained"));
|
||||||
const expectSlot = async () => {
|
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(sidebar).toHaveAttribute("data-session-slot", "retained");
|
||||||
await expect.poll(() => sidebar.evaluate((node) => node.getBoundingClientRect().width)).toBe(420);
|
await expect.poll(() => sidebar.evaluate((node) => node.getBoundingClientRect().width)).toBe(420);
|
||||||
await expect.poll(() => sidebar.locator(".file-preview-content").evaluate((node) => {
|
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 expect(sidebar.getByRole("progressbar")).not.toHaveAttribute("aria-valuenow");
|
||||||
await expectSlot();
|
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("button", { name: "second.md", exact: true })).toBeVisible();
|
||||||
await expect(sidebar.getByRole("progressbar")).toHaveAttribute("aria-valuenow", "20");
|
await expect(sidebar.getByRole("progressbar")).toHaveAttribute("aria-valuenow", "20");
|
||||||
await expectSlot();
|
await expectSlot();
|
||||||
|
|||||||
@@ -586,23 +586,22 @@ export function ThreadShell({
|
|||||||
const shellRef = useRef<HTMLElement | null>(null);
|
const shellRef = useRef<HTMLElement | null>(null);
|
||||||
const [conversationElement, setConversationElement] = useState<HTMLDivElement | null>(null);
|
const [conversationElement, setConversationElement] = useState<HTMLDivElement | null>(null);
|
||||||
const [composerSurface, setComposerSurface] = 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(() => {
|
useLayoutEffect(() => {
|
||||||
const shell = contextSidebarHost;
|
if (!sidebarOpen || !inlineComposer || !contextSidebarHost || !composerSurface) return;
|
||||||
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`);
|
|
||||||
};
|
|
||||||
alignSidebar();
|
alignSidebar();
|
||||||
const observer = new ResizeObserver(alignSidebar);
|
const observer = new ResizeObserver(alignSidebar);
|
||||||
observer.observe(shell);
|
observer.observe(contextSidebarHost);
|
||||||
observer.observe(composerMount);
|
observer.observe(composerMount);
|
||||||
observer.observe(surface);
|
observer.observe(composerSurface);
|
||||||
return () => observer.disconnect();
|
return () => observer.disconnect();
|
||||||
}, [contextSidebarHost, sidebarOpen, inlineComposer, composerDestination, composerMount, composerSurface]);
|
}, [alignSidebar, contextSidebarHost, sidebarOpen, inlineComposer, composerDestination, composerMount, composerSurface]);
|
||||||
const filePreviewWidthRef = useRef(FILE_PREVIEW_DEFAULT_WIDTH);
|
const filePreviewWidthRef = useRef(FILE_PREVIEW_DEFAULT_WIDTH);
|
||||||
const filePreviewCloseTimerRef = useRef<number | null>(null);
|
const filePreviewCloseTimerRef = useRef<number | null>(null);
|
||||||
const filePreviewResizeCleanupRef = useRef<(() => void) | null>(null);
|
const filePreviewResizeCleanupRef = useRef<(() => void) | null>(null);
|
||||||
@@ -1555,6 +1554,7 @@ export function ThreadShell({
|
|||||||
emptyState={emptyState}
|
emptyState={emptyState}
|
||||||
initialLoading={initialHistoryLoading}
|
initialLoading={initialHistoryLoading}
|
||||||
composer={inlineComposer ? <div ref={setLocalComposerHost} /> : null}
|
composer={inlineComposer ? <div ref={setLocalComposerHost} /> : null}
|
||||||
|
onComposerLayoutChange={alignSidebar}
|
||||||
activeTurnId={viewportTurnId}
|
activeTurnId={viewportTurnId}
|
||||||
activeTurnStartedHere={activeTurnStartedHere}
|
activeTurnStartedHere={activeTurnStartedHere}
|
||||||
conversationKey={historyKey}
|
conversationKey={historyKey}
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ interface ThreadViewportProps {
|
|||||||
runStartedAt?: number | null;
|
runStartedAt?: number | null;
|
||||||
retryStatus?: RetryStatus | null;
|
retryStatus?: RetryStatus | null;
|
||||||
composer?: ReactNode;
|
composer?: ReactNode;
|
||||||
|
onComposerLayoutChange?: () => void;
|
||||||
navigationFrame?: HTMLElement | null;
|
navigationFrame?: HTMLElement | null;
|
||||||
emptyState?: ReactNode;
|
emptyState?: ReactNode;
|
||||||
initialLoading?: boolean;
|
initialLoading?: boolean;
|
||||||
@@ -259,6 +260,7 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
|
|||||||
runStartedAt = null,
|
runStartedAt = null,
|
||||||
retryStatus = null,
|
retryStatus = null,
|
||||||
composer,
|
composer,
|
||||||
|
onComposerLayoutChange,
|
||||||
navigationFrame,
|
navigationFrame,
|
||||||
emptyState,
|
emptyState,
|
||||||
initialLoading = false,
|
initialLoading = false,
|
||||||
@@ -302,6 +304,8 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
|
|||||||
const messageContentRef = useRef<HTMLDivElement>(null);
|
const messageContentRef = useRef<HTMLDivElement>(null);
|
||||||
const emptyStateRef = useRef<HTMLDivElement>(null);
|
const emptyStateRef = useRef<HTMLDivElement>(null);
|
||||||
const composerDockRef = useRef<HTMLDivElement>(null);
|
const composerDockRef = useRef<HTMLDivElement>(null);
|
||||||
|
const composerLayoutChangeRef = useRef(onComposerLayoutChange);
|
||||||
|
composerLayoutChangeRef.current = onComposerLayoutChange;
|
||||||
const bottomRef = useRef<HTMLDivElement>(null);
|
const bottomRef = useRef<HTMLDivElement>(null);
|
||||||
const lastConversationKeyRef = useRef<string | null>(conversationKey);
|
const lastConversationKeyRef = useRef<string | null>(conversationKey);
|
||||||
const conversationHandoffPendingRef = useRef(false);
|
const conversationHandoffPendingRef = useRef(false);
|
||||||
@@ -399,6 +403,7 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
onGeometry: (geometry: ThreadMotionGeometry) => {
|
onGeometry: (geometry: ThreadMotionGeometry) => {
|
||||||
|
composerLayoutChangeRef.current?.();
|
||||||
if (Math.abs(composerDockHeightRef.current - geometry.composerHeight) >= 1) {
|
if (Math.abs(composerDockHeightRef.current - geometry.composerHeight) >= 1) {
|
||||||
composerDockHeightRef.current = geometry.composerHeight;
|
composerDockHeightRef.current = geometry.composerHeight;
|
||||||
setComposerDockHeight(geometry.composerHeight);
|
setComposerDockHeight(geometry.composerHeight);
|
||||||
@@ -878,7 +883,8 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
|
|||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
const el = scrollRef.current;
|
const el = scrollRef.current;
|
||||||
const content = contentRef.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 messageContent = messageContentRef.current;
|
||||||
const composerDock = composerDockRef.current;
|
const composerDock = composerDockRef.current;
|
||||||
if (!el) return;
|
if (!el) return;
|
||||||
@@ -896,7 +902,7 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
|
|||||||
: new ResizeObserver(reconcileObservedGeometry);
|
: new ResizeObserver(reconcileObservedGeometry);
|
||||||
observer?.observe(el);
|
observer?.observe(el);
|
||||||
if (content) observer?.observe(content);
|
if (content) observer?.observe(content);
|
||||||
if (messageRegion) observer?.observe(messageRegion);
|
if (contentRegion) observer?.observe(contentRegion);
|
||||||
if (messageContent) observer?.observe(messageContent);
|
if (messageContent) observer?.observe(messageContent);
|
||||||
if (composerDock) observer?.observe(composerDock);
|
if (composerDock) observer?.observe(composerDock);
|
||||||
window.addEventListener("resize", invalidateGeometry);
|
window.addEventListener("resize", invalidateGeometry);
|
||||||
|
|||||||
Reference in new issue
Block a user