Skip to content
TypeScript

fix(web): keep subagent links visible in long background-work banners (#20054)

Andrey Velts3a69f7ada4cb
diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx
index 51c468261b0..d1baa2cafb9 100644
--- a/apps/web/src/components/ChatView.tsx
+++ b/apps/web/src/components/ChatView.tsx
@@ -5273,6 +5273,7 @@ export default function ChatView(props: ChatViewProps) {
/>
),
title: presentation.title,
+ descriptionPlacement: "below",
description:
presentation.items.length === 1 && presentation.items[0]?.childThreadId === undefined
? undefined
@@ -5288,7 +5289,7 @@ export default function ChatView(props: ChatViewProps) {
{separator}
</>
) : (
- <span className="whitespace-nowrap">
+ <span>
<InlineButton
tone="muted"
aria-label={`${presentation.items.length === 1 ? "Show" : "Open"} subagent ${item.label}`}
diff --git a/apps/web/src/components/chat/ComposerBannerStack.browser.test.tsx b/apps/web/src/components/chat/ComposerBannerStack.browser.test.tsx
index ecb56eab5de..d82dca7b54c 100644
--- a/apps/web/src/components/chat/ComposerBannerStack.browser.test.tsx
+++ b/apps/web/src/components/chat/ComposerBannerStack.browser.test.tsx
@@ -5,6 +5,8 @@ import { createRoot, type Root } from "react-dom/client";
import { afterEach, beforeEach, expect, it, vi } from "vite-plus/test";
import { page, userEvent } from "vite-plus/test/browser";
+import { Button, InlineButton } from "../ui/button";
+
import { ComposerBannerStack } from "./ComposerBannerStack";
let root: Root;
@@ -60,6 +62,94 @@ it("only offers notice details when the description cannot fit", async () => {
expect(hasDetails()).toBe(true);
});
+it.each([320, 800])(
+ "keeps long background-work links reachable beside Stop in a %ipx composer",
+ async (width) => {
+ await page.viewport(width + 32, 800);
+ container.style.width = `${width}px`;
+ const openThread = vi.fn();
+ const label = "Review the background task layout and child-thread navigation ".repeat(6);
+ await act(async () =>
+ root.render(
+ <ComposerBannerStack
+ items={[
+ {
+ id: "background-work",
+ variant: "default",
+ priority: "activity",
+ icon: null,
+ title: "12 background tasks",
+ descriptionPlacement: "below",
+ description: Array.from({ length: 12 }, (_, index) => (
+ <span key={index}>
+ {index > 0 ? " " : null}
+ <InlineButton
+ tone="muted"
+ aria-label={`Open subagent ${index + 1}`}
+ onClick={() => openThread(index + 1)}
+ >
+ {label}
+ </InlineButton>
+ {index < 11 ? "," : null}
+ </span>
+ )),
+ actions: (
+ <Button size="xs" variant="ghost">
+ Stop
+ </Button>
+ ),
+ },
+ ]}
+ />,
+ ),
+ );
+ await nextFrame();
+
+ const firstLink = page.getByRole("button", { name: "Open subagent 1", exact: true });
+ const lastLink = page.getByRole("button", { name: "Open subagent 12", exact: true });
+ const stop = page.getByRole("button", { name: "Stop", exact: true });
+ expect(firstLink.element().getBoundingClientRect().height).toBeGreaterThan(
+ Number.parseFloat(getComputedStyle(firstLink.element()).lineHeight) * 2,
+ );
+ const viewport = container.querySelector<HTMLElement>('[data-slot="scroll-area-viewport"]')!;
+ expect(viewport).not.toBeNull();
+ expect(viewport.clientHeight).toBeGreaterThan(0);
+ expect(viewport.clientHeight).toBeLessThanOrEqual(window.innerHeight / 2);
+ expect(viewport.scrollHeight).toBeGreaterThan(viewport.clientHeight);
+ expect(viewport.scrollWidth).toBeLessThanOrEqual(viewport.clientWidth + 1);
+
+ const scrollBounds = viewport.getBoundingClientRect();
+ const stopBounds = stop.element().getBoundingClientRect();
+ expect(stopBounds.top).toBe(
+ page.getByText("12 background tasks", { exact: true }).element().getBoundingClientRect().top,
+ );
+ expect(scrollBounds.right).toBeLessThanOrEqual(stopBounds.left);
+ expect(stopBounds.right).toBeLessThanOrEqual(container.getBoundingClientRect().right);
+ expect(stopBounds.bottom).toBeLessThanOrEqual(scrollBounds.bottom);
+ expect(lastLink.element().getBoundingClientRect().top).toBeGreaterThan(scrollBounds.bottom);
+ await firstLink.click();
+ expect(openThread).toHaveBeenLastCalledWith(1);
+
+ viewport.scrollTop = viewport.scrollHeight;
+ await nextFrame();
+ expect(viewport.scrollTop).toBeGreaterThan(0);
+ const lastBounds = lastLink.element().getBoundingClientRect();
+ expect(lastBounds.top).toBeGreaterThanOrEqual(scrollBounds.top);
+ expect(lastBounds.bottom).toBeLessThanOrEqual(scrollBounds.bottom + 1);
+ expect(stop.element().getBoundingClientRect().top).toBe(stopBounds.top);
+ for (const control of [lastLink.element(), stop.element()]) {
+ const bounds = control.getBoundingClientRect();
+ expect(
+ control.contains(
+ document.elementFromPoint(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2),
+ ),
+ ).toBe(true);
+ }
+ await lastLink.click();
+ expect(openThread).toHaveBeenLastCalledWith(12);
+ },
+);
+
it("keeps only the usage limit attached while an active goal waits in the collapsible stack", async () => {
await act(async () =>
root.render(
diff --git a/apps/web/src/components/chat/ComposerBannerStack.tsx b/apps/web/src/components/chat/ComposerBannerStack.tsx
index fc309c5352a..e2e7ecc42d0 100644
--- a/apps/web/src/components/chat/ComposerBannerStack.tsx
+++ b/apps/web/src/components/chat/ComposerBannerStack.tsx
@@ -17,6 +17,7 @@ export interface ComposerBannerStackItem {
readonly icon: ReactNode;
readonly title: ReactNode;
readonly description?: ReactNode;
+ readonly descriptionPlacement?: "inline" | "below";
readonly children?: ReactNode;
readonly actions?: ReactNode;
readonly dismissLabel?: string;
@@ -347,6 +348,7 @@ function ComposerBannerStackAlert({
</ComposerBanner.Root>
);
}
+ const descriptionBelow = item.descriptionPlacement === "below";
return (
<ComposerBanner.Root
role="alert"
@@ -354,11 +356,15 @@ function ComposerBannerStackAlert({
variant={item.variant}
density="comfortable"
>
- <ComposerBanner.Row layout={item.priority === "activity" ? "inline" : "wrap-actions"}>
+ <ComposerBanner.Row
+ layout={descriptionBelow || item.priority === "activity" ? "inline" : "wrap-actions"}
+ >
<ComposerBanner.Icon className="h-(--composer-banner-icon-column) self-start">
{item.icon}
</ComposerBanner.Icon>
- <ComposerBanner.Content className="whitespace-nowrap">
+ <ComposerBanner.Content
+ className={descriptionBelow ? "flex-col items-stretch gap-0" : "whitespace-nowrap"}
+ >
<NoticeText
detailsLabel="Show title details"
className="min-w-0 truncate font-medium leading-7 sm:leading-6"
@@ -366,16 +372,22 @@ function ComposerBannerStackAlert({
{item.title}
</NoticeText>
{item.description ? (
- <NoticeText
- detailsLabel="Show notice details"
- className="w-0 min-w-0 grow truncate text-muted-foreground @max-[400px]:sr-only"
- >
- {item.description}
- </NoticeText>
+ descriptionBelow ? (
+ <ComposerBanner.Scroll className="text-muted-foreground whitespace-normal wrap-anywhere [--inline-button-text-align:start] [--inline-button-white-space:normal] [&_[data-slot=inline-button]]:max-w-full">
+ <span className="block pb-1">{item.description}</span>
+ </ComposerBanner.Scroll>
+ ) : (
+ <NoticeText
+ detailsLabel="Show notice details"
+ className="w-0 min-w-0 grow truncate text-muted-foreground @max-[400px]:sr-only"
+ >
+ {item.description}
+ </NoticeText>
+ )
) : null}
</ComposerBanner.Content>
{item.actions || item.onDismiss ? (
- <ComposerBanner.Actions>
+ <ComposerBanner.Actions className={descriptionBelow ? "self-start" : undefined}>
{item.actions}
{item.onDismiss ? (
<ComposerBanner.Dismiss