@devries-cameron20 / t3code-1 / commits / b07696a64b
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(web): dismiss removed usage popups without a corner jump (#21879)

Co-authored-by: Rakshith Bhat <rakshith6666@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 19, 2026 at 16:23 UTC b07696a64b154bcbce5cb8ddbe5d1d002a56c38f
2 files changed +55 -11
apps/web/src/components/usage/UsageLimitsPooled.browser.test.tsx
+31 -6
@@ -100,6 +100,28 @@ async function click(label: string) {
100 await act(() => userEvent.click(button!));
101 }
102
103 +/**
104 + * Runs `change`, which takes the open popup's trigger out of the page, then watches the popup
105 + * leave. A detached trigger has no rect, so a popup that keeps positioning against it slides
106 + * to the viewport origin on its way out.
107 + */
108 +async function expectDismissedInPlace(change: () => Promise<void> | void) {
109 + const positioner = () => document.querySelector('[data-slot="popover-positioner"]');
110 + const place = (node: Element) => {
111 + const rect = node.getBoundingClientRect();
112 + return [rect.left, rect.top];
113 + };
114 + const before = place(positioner()!);
115 + await change();
116 + const seen: number[][] = [];
117 + for (let frame = 0; frame < 60 && positioner(); frame += 1) {
118 + seen.push(place(positioner()!));
119 + await new Promise(requestAnimationFrame);
120 + }
121 + expect(positioner()).toBeNull();
122 + expect(seen).toEqual(seen.map(() => before));
123 +}
124 +
125 it.each([
126 {
127 label: "success",
@@ -221,8 +243,9 @@ it("moves the one limit popover between windows on hover", async () => {
243 await act(() => userEvent.hover(session, { position: { x: 4, y: 4 } }));
244 await expect.poll(popups).toEqual([expect.stringContaining("Left60%")]);
245
224 - await act(() => root.render(<UsageLimitsPooled presentations={new Map()} now={0} />));
225 - await expect.poll(popups).toEqual([]);
246 + await expectDismissedInPlace(() =>
247 + act(() => root.render(<UsageLimitsPooled presentations={new Map()} now={0} />)),
248 + );
249 await act(() => userEvent.hover(container, { position: { x: 4, y: 4 } }));
250
251 await act(() => root.render(<UsageLimitsPooled presentations={twoWindows} now={0} />));
@@ -272,13 +295,15 @@ it("closes an open source-account popover when reset availability replaces its t
295 await click("Alpha: 60%");
296 await expect.poll(() => popup()?.textContent).toContain("Use reset");
297
275 - await act(() => root.render(<UsageLimitsPooled presentations={source()} now={0} />));
276 - await expect.poll(popup).toBeNull();
298 + await expectDismissedInPlace(() =>
299 + act(() => root.render(<UsageLimitsPooled presentations={source()} now={0} />)),
300 + );
301 await click("Alpha: 60%");
302 await expect.poll(() => popup()?.textContent).toContain("Left60%");
303
280 - await act(() => root.render(<UsageLimitsPooled presentations={source("credit-2")} now={0} />));
281 - await expect.poll(popup).toBeNull();
304 + await expectDismissedInPlace(() =>
305 + act(() => root.render(<UsageLimitsPooled presentations={source("credit-2")} now={0} />)),
306 + );
307 await click("Alpha: 60%");
308 await expect.poll(() => popup()?.textContent).toContain("Use reset");
309 await click("Use reset");
apps/web/src/components/usage/UsageLimitsPooled.tsx
+24 -5
@@ -14,8 +14,18 @@ import {
14 paceRemainingPercent,
15 remainingPercent,
16 } from "@t3tools/shared/usageLimits";
17 +import type { Popover as PopoverPrimitive } from "@base-ui/react/popover";
18 import { AlertTriangleIcon, ExternalLinkIcon, TicketIcon } from "lucide-react";
18 -import { createContext, Fragment, type ReactNode, use, useEffect, useState } from "react";
19 +import {
20 + createContext,
21 + Fragment,
22 + type ReactNode,
23 + type RefObject,
24 + use,
25 + useLayoutEffect,
26 + useRef,
27 + useState,
28 +} from "react";
29
30 import { ensureLocalApi } from "../../localApi";
31 import { usePrimarySettings } from "../../hooks/useSettings";
@@ -216,11 +226,13 @@ const SegmentPopoverContext = createContext<ReturnType<
226
227 function ActiveSegmentPopover({
228 handle,
229 + actions,
230 payload,
231 pools,
232 now,
233 }: {
234 readonly handle: ReturnType<typeof PopoverCreateHandle<SegmentPayload>>;
235 + readonly actions: RefObject<PopoverPrimitive.Root.Actions | null>;
236 readonly payload: SegmentPayload;
237 readonly pools: readonly LimitPool[];
238 readonly now: number;
@@ -236,9 +248,14 @@ function ActiveSegmentPopover({
248 ),
249 ),
250 );
239 - useEffect(() => {
240 - if (!available) handle.close();
241 - }, [available, handle]);
251 + // The trigger is gone, so the popup has nothing to anchor to: an exit transition would
252 + // slide it to the viewport origin. Unmount it outright, which also clears Base UI's
253 + // active-trigger bookkeeping so the segment can open again when it comes back.
254 + useLayoutEffect(() => {
255 + if (available) return;
256 + handle.close();
257 + actions.current?.unmount();
258 + }, [available, handle, actions]);
259 return (
260 <PopoverPopup side="top" sideOffset={6}>
261 <SegmentPopover
@@ -582,6 +599,7 @@ export function UsageLimitsPooled({
599 readonly cursorPrompt?: ReactNode;
600 }) {
601 const [segmentPopover] = useState(() => PopoverCreateHandle<SegmentPayload>());
602 + const segmentPopoverActions = useRef<PopoverPrimitive.Root.Actions | null>(null);
603 const pools = collectLimitPools(collectLimitAccounts(presentations), now);
604 const notices = collectLimitNotices(presentations);
605 const externalLinks = collectExternalUsageLinks(presentations);
@@ -605,11 +623,12 @@ export function UsageLimitsPooled({
623 </Fragment>
624 ))}
625 </SegmentPopoverContext>
608 - <Popover handle={segmentPopover}>
626 + <Popover handle={segmentPopover} actionsRef={segmentPopoverActions}>
627 {({ payload }) =>
628 payload ? (
629 <ActiveSegmentPopover
630 handle={segmentPopover}
631 + actions={segmentPopoverActions}
632 payload={payload}
633 pools={pools}
634 now={now}