Skip to content

Commit 5bd1acb

Browse files
committed
fix(web): usage limit banner no longer hides behind waiting subagents
An activity banner such as waiting subagents takes the attached slot, which collapsed the usage limit banner and its auto-resume actions into the hover-only peek. Urgent notices now keep their expanded place above the front item.
1 parent 5070a83 commit 5bd1acb

2 files changed

Lines changed: 81 additions & 29 deletions

File tree

‎apps/web/src/components/chat/ComposerBannerStack.test.tsx‎

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { cloneElement, type ReactElement, type ReactNode } from "react";
2-
import { act, create, type ReactTestRenderer } from "react-test-renderer";
2+
import { act, create, type ReactTestInstance, type ReactTestRenderer } from "react-test-renderer";
33
import { afterEach, expect, it, vi } from "vite-plus/test";
44

55
import { ComposerBannerStack } from "./ComposerBannerStack";
@@ -101,3 +101,45 @@ it("only offers notice details when the description cannot fit", async () => {
101101
await act(() => resize());
102102
expect(details()).toHaveLength(0);
103103
});
104+
105+
it("keeps an urgent notice out of the collapsed stack behind activity", async () => {
106+
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
107+
await act(() => {
108+
renderer = create(
109+
<ComposerBannerStack
110+
items={[
111+
{
112+
id: "limit",
113+
variant: "warning",
114+
priority: "urgent",
115+
icon: null,
116+
title: "Usage limit reached",
117+
},
118+
{ id: "usage", variant: "info", priority: "notice", icon: null, title: "Usage limits" },
119+
{
120+
id: "work",
121+
variant: "default",
122+
priority: "activity",
123+
icon: null,
124+
title: "Waiting on 2 subagents",
125+
},
126+
]}
127+
/>,
128+
);
129+
});
130+
const titles = (root: ReactTestInstance) =>
131+
root
132+
.findAll((node) => node.type === "div" && node.props["data-slot"] === "composer-banner")
133+
.map((banner) => banner.findByProps({ "data-slot": "composer-banner-content" }).children)
134+
.map(([title]) => (typeof title === "string" ? title : title?.children.join("")));
135+
// Order is unchanged: activity stays attached, with the notices above it.
136+
expect(titles(renderer.root)).toEqual([
137+
"Usage limit reached",
138+
"Usage limits",
139+
"Waiting on 2 subagents",
140+
]);
141+
// Only the ordinary notice waits behind the hover-to-expand peek.
142+
expect(titles(renderer.root.findByProps({ "aria-label": "Other notices" }))).toEqual([
143+
"Usage limits",
144+
]);
145+
});

‎apps/web/src/components/chat/ComposerBannerStack.tsx‎

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,19 @@ export function ComposerBannerStack({ className, items, attachedAbove }: Compose
7070
};
7171
}, []);
7272

73+
// Activity stays attached. Urgency and severity only order the notices behind it.
74+
const orderedItems = items.toSorted((a, b) => bannerPriority(a) - bannerPriority(b));
75+
const frontItem = orderedItems[0];
76+
const stackedItems = orderedItems.slice(1);
77+
// An urgent notice is waiting on the user, so it keeps its expanded place above the
78+
// front item instead of collapsing behind it with the other notices.
79+
const pinnedItems = stackedItems.filter((item) => item.priority === "urgent");
80+
const collapsedItems = stackedItems.filter((item) => item.priority !== "urgent");
81+
const hasStack = collapsedItems.length > 0;
82+
7383
useEffect(() => {
74-
if (items.length < 2) setStackExpanded(false);
75-
}, [items.length]);
84+
if (!hasStack) setStackExpanded(false);
85+
}, [hasStack]);
7686

7787
useLayoutEffect(() => {
7888
if (stackExpanded && pendingFocusRef.current === "notice") {
@@ -87,9 +97,6 @@ export function ComposerBannerStack({ className, items, attachedAbove }: Compose
8797
}
8898
}, [stackExpanded]);
8999

90-
// Activity stays attached. Urgency and severity only order the notices behind it.
91-
const orderedItems = items.toSorted((a, b) => bannerPriority(a) - bannerPriority(b));
92-
const frontItem = orderedItems[0];
93100
if (!frontItem) {
94101
return (
95102
<>
@@ -99,10 +106,8 @@ export function ComposerBannerStack({ className, items, attachedAbove }: Compose
99106
</>
100107
);
101108
}
102-
const stackedItems = orderedItems.slice(1);
103-
const hasStack = stackedItems.length > 0;
104109
const showCollapsedStackCap = hasStack && exitingItemId !== frontItem.id;
105-
const firstStackedItem = stackedItems[0];
110+
const firstCollapsedItem = collapsedItems[0];
106111

107112
const requestDismiss = (item: ComposerBannerStackEntry) => {
108113
if (!("onDismiss" in item) || !item.onDismiss || exitingItemId) {
@@ -118,8 +123,30 @@ export function ComposerBannerStack({ className, items, attachedAbove }: Compose
118123
}, DISMISS_TRANSITION_MS);
119124
};
120125

126+
const renderStackedItem = (item: ComposerBannerStackEntry) => (
127+
<div
128+
key={item.id}
129+
className={cn(
130+
"transition-[opacity,translate] duration-220 ease-in",
131+
exitingItemId === item.id ? "pointer-events-none translate-y-28 opacity-0" : "opacity-100",
132+
)}
133+
>
134+
<ComposerBannerStackAlert
135+
item={item}
136+
attached={false}
137+
exiting={exitingItemId === item.id}
138+
onDismissRequest={() => requestDismiss(item)}
139+
/>
140+
</div>
141+
);
142+
121143
return (
122144
<>
145+
{pinnedItems.length > 0 ? (
146+
<div data-chat-composer-collapsed-controls="true" className="relative z-20 space-y-2 pb-2">
147+
{pinnedItems.map(renderStackedItem)}
148+
</div>
149+
) : null}
123150
{hasStack ? (
124151
<div
125152
ref={noticesRef}
@@ -151,10 +178,10 @@ export function ComposerBannerStack({ className, items, attachedAbove }: Compose
151178
setStackExpanded(false);
152179
}}
153180
>
154-
{showCollapsedStackCap && firstStackedItem ? (
181+
{showCollapsedStackCap && firstCollapsedItem ? (
155182
<ComposerBanner.Peek
156183
ref={peekRef}
157-
variant={firstStackedItem.variant}
184+
variant={firstCollapsedItem.variant}
158185
aria-label="Show other notices"
159186
aria-expanded={stackExpanded}
160187
aria-controls={expandedItemsId}
@@ -189,24 +216,7 @@ export function ComposerBannerStack({ className, items, attachedAbove }: Compose
189216
: "pointer-events-none invisible translate-y-1 opacity-0",
190217
)}
191218
>
192-
{stackedItems.map((item) => (
193-
<div
194-
key={item.id}
195-
className={cn(
196-
"transition-[opacity,translate] duration-220 ease-in",
197-
exitingItemId === item.id
198-
? "pointer-events-none translate-y-28 opacity-0"
199-
: "opacity-100",
200-
)}
201-
>
202-
<ComposerBannerStackAlert
203-
item={item}
204-
attached={false}
205-
exiting={exitingItemId === item.id}
206-
onDismissRequest={() => requestDismiss(item)}
207-
/>
208-
</div>
209-
))}
219+
{collapsedItems.map(renderStackedItem)}
210220
</div>
211221
</div>
212222
</div>

0 commit comments

Comments
 (0)