The best way to control Claude Code, Codex and more from any computer or phone
fix(web): show reset credit progress after the usage popover closes (#19808)
Gabriel Cruz committed
Oct 18, 2026 at 16:16 UTC
a651a52ecfffa053c1cc225b092ceae379f46cb0
2 files changed
+141
-3
apps/web/src/components/usage/UsageLimitsPooled.test.tsx
new
+137
@@ -0,0 +1,137 @@
1
+// @vitest-environment jsdom
2
+
3
+import {
4
+ EnvironmentId,
5
+ ProviderDriverKind,
6
+ ProviderInstanceId,
7
+ type ServerProvider,
8
+} from "@t3tools/contracts";
9
+import type { LimitPresentations } from "@t3tools/shared/usageLimits";
10
+import { act } from "react";
11
+import { createRoot, type Root } from "react-dom/client";
12
+import { afterEach, beforeEach, expect, it, vi } from "vite-plus/test";
13
+
14
+const consume = vi.hoisted(() => vi.fn());
15
+vi.mock("../../state/session", () => ({
16
+ useEnvironmentScope: () => true,
17
+ readEnvironmentScope: () => true,
18
+}));
19
+vi.mock("../../state/server", () => ({ serverEnvironment: { consumeResetCredit: null } }));
20
+vi.mock("../../state/use-atom-command", () => ({ useAtomCommand: () => consume }));
21
+vi.mock("../../hooks/useSettings", () => ({ usePrimarySettings: () => "24h" }));
22
+vi.mock("../chat/ProviderInstanceIcon", () => ({ ProviderInstanceIcon: () => null }));
23
+vi.mock("../settings/RedactedSensitiveText", () => ({ RedactedSensitiveText: () => null }));
24
+
25
+import { UsageLimitsPooled } from "./UsageLimitsPooled";
26
+
27
+const presentations: LimitPresentations = new Map([
28
+ [
29
+ EnvironmentId.make("env-a"),
30
+ {
31
+ entry: { target: { label: "Test" } },
32
+ serverConfig: {
33
+ usageLimitSources: [],
34
+ providers: [
35
+ {
36
+ instanceId: ProviderInstanceId.make("alpha"),
37
+ driver: ProviderDriverKind.make("codex"),
38
+ displayName: "Alpha",
39
+ enabled: true,
40
+ installed: true,
41
+ version: null,
42
+ status: "ready",
43
+ auth: { status: "authenticated", email: "alpha@example.com" },
44
+ checkedAt: "2026-09-03T11:00:00Z",
45
+ models: [],
46
+ slashCommands: [],
47
+ skills: [],
48
+ usageLimits: {
49
+ checkedAt: "2026-09-03T11:00:00Z",
50
+ resetCredits: { availableCount: 1 },
51
+ windows: [
52
+ {
53
+ id: "five_hour",
54
+ kind: "session",
55
+ label: "Session",
56
+ usedPercent: 40,
57
+ windowDurationMins: 300,
58
+ resetsAt: "2026-09-03T14:00:00Z",
59
+ },
60
+ ],
61
+ },
62
+ } satisfies ServerProvider,
63
+ ],
64
+ },
65
+ },
66
+ ],
67
+]);
68
+
69
+let root: Root;
70
+let container: HTMLDivElement;
71
+
72
+beforeEach(async () => {
73
+ vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
74
+ vi.stubGlobal(
75
+ "ResizeObserver",
76
+ class {
77
+ observe() {}
78
+ disconnect() {}
79
+ unobserve() {}
80
+ },
81
+ );
82
+ consume.mockReset();
83
+ container = document.createElement("div");
84
+ document.body.append(container);
85
+ root = createRoot(container);
86
+ await act(() => root.render(<UsageLimitsPooled presentations={presentations} now={0} />));
87
+});
88
+
89
+afterEach(async () => {
90
+ await act(() => root.unmount());
91
+ container.remove();
92
+ vi.unstubAllGlobals();
93
+});
94
+
95
+async function click(label: string) {
96
+ const button = Array.from(document.querySelectorAll("button")).find(
97
+ (node) => node.textContent === label || node.getAttribute("aria-label")?.startsWith(label),
98
+ );
99
+ expect(button).toBeDefined();
100
+ await act(() => button!.click());
101
+}
102
+
103
+it.each([
104
+ {
105
+ label: "success",
106
+ result: { _tag: "Success", value: { outcome: "reset" } },
107
+ text: "Reset applied. Your windows have cleared.",
108
+ },
109
+ {
110
+ label: "failure",
111
+ result: { _tag: "Failure", cause: { error: new Error("Codex rejected the credit.") } },
112
+ text: "Codex rejected the credit.",
113
+ },
114
+])("keeps pending feedback outside the closed popup until $label", async ({ result, text }) => {
115
+ let answer!: (result: unknown) => void;
116
+ consume.mockReturnValue(new Promise((resolve) => (answer = resolve)));
117
+ await click("Alpha:");
118
+ await click("Use reset");
119
+ expect(consume).not.toHaveBeenCalled();
120
+ await click("Cancel");
121
+ expect(consume).not.toHaveBeenCalled();
122
+ await click("Alpha:");
123
+ await click("Use reset");
124
+ await click("Use credit");
125
+ expect(consume).toHaveBeenCalledOnce();
126
+ expect(document.querySelector('[role="alertdialog"]')).toBeNull();
127
+ expect(document.querySelector('[data-slot="popover-popup"]')).toBeNull();
128
+ const status = document.querySelector('[role="status"]');
129
+ expect(status?.textContent).toBe("Alpha Using reset credit…");
130
+ await click("Alpha:");
131
+ const using = Array.from(document.querySelectorAll("button")).find(
132
+ (node) => node.textContent === "Using…",
133
+ );
134
+ expect(using?.disabled).toBe(true);
135
+ await act(async () => answer(result));
136
+ expect(status?.textContent).toBe(`Alpha ${text}`);
137
+});
apps/web/src/components/usage/UsageLimitsPooled.tsx
+4
-3
@@ -404,10 +404,11 @@ function RedeemableSegmentPopup({
404
onConfirm={() => void redeem.redeem()}
405
disabled={!redeem.canManageProviders}
406
/>
407
- {/* The popover closed before the confirm, so the outcome needs a home outside it. */}
408
- {redeem.status ? (
407
+ {/* The popover closed before the confirm, so progress and the outcome need a home outside it. */}
408
+ {redeem.busy || redeem.status ? (
409
<span role="status" className="col-span-full text-xs text-muted-foreground">
410
- <AccountName account={account} className="font-medium text-foreground" /> {redeem.status}
410
+ <AccountName account={account} className="font-medium text-foreground" />{" "}
411
+ {redeem.busy ? "Using reset credit…" : redeem.status}
412
</span>
413
) : null}
414
</>