The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 22:15 UTC
fix(web): opening a thread dismisses its notification toasts (#24313)
Julius Marminge committed
Nov 11, 2026 at 15:30 UTC
bba1c13d87a73df9725f9d37be9381a627eb9b03
2 files changed
+80
-12
apps/web/src/components/ThreadNotificationCoordinator.badge.browser.test.ts
+55
-2
@@ -12,6 +12,7 @@ const state = vi.hoisted(() => ({
12
mode: "notifications",
13
inApp: false,
14
toast: vi.fn(),
15
+ closeToast: vi.fn(),
16
shells: null as unknown as { set: (id: string, value: unknown) => void },
17
navigate: vi.fn(),
18
sound: vi.fn(),
@@ -20,7 +21,14 @@ const state = vi.hoisted(() => ({
21
}));
22
vi.mock(import("./ui/toast"), async (original) => {
23
const actual = await original();
23
- return { ...actual, toastManager: { ...actual.toastManager, add: state.toast as never } };
24
+ return {
25
+ ...actual,
26
+ toastManager: {
27
+ ...actual.toastManager,
28
+ add: state.toast as never,
29
+ close: state.closeToast as never,
30
+ },
31
+ };
32
});
33
vi.mock(import("../state/shell"), async (original) => {
34
const actual = await original();
@@ -206,15 +214,25 @@ function setup() {
214
.spyOn(document, "visibilityState", "get")
215
.mockImplementation(() => visibility as DocumentVisibilityState),
216
);
217
+ const routeListeners = new Set<() => void>();
218
+ const route = { params: {} as Record<string, string> };
219
const router = {
210
- state: { matches: [{ params: {} }] },
220
+ state: { matches: [route] },
221
navigate: state.navigate,
222
+ subscribe: (_event: string, listener: () => void) => {
223
+ routeListeners.add(listener);
224
+ return () => routeListeners.delete(listener);
225
+ },
226
} as unknown as AnyRouter;
227
return {
228
start: () => {
229
stack.defer(startThreadNotifications(testRegistry, router));
230
},
231
setEnvironmentIds: (ids: ReadonlyArray<string>) => testRegistry.set(environmentIdsAtom, ids),
232
+ openThread: (environmentId: string, threadId: string) => {
233
+ route.params = { environmentId, threadId };
234
+ for (const listener of routeListeners) listener();
235
+ },
236
changeSettings: () => {
237
for (const listener of state.settingsListeners) listener();
238
},
@@ -400,3 +418,38 @@ it.each([false, true])(
418
expect(TestNotification.sent.map(({ title }) => title)).toEqual(["Thread completed"]);
419
},
420
);
421
+
422
+it("opening a thread closes only its in-app toasts, and disabling notifications closes the rest", async () => {
423
+ await using app = setup();
424
+ state.inApp = true;
425
+ focused = true;
426
+ state.toast
427
+ .mockReturnValueOnce("one-completed")
428
+ .mockReturnValueOnce("one-approval")
429
+ .mockReturnValueOnce("one-other")
430
+ .mockReturnValueOnce("two-completed");
431
+ state.shells.set("one", shell({}, { id: "other" }));
432
+ app.start();
433
+ const completed = {
434
+ latestTurn: { turnId: "turn", state: "completed", completedAt: "2026-09-13T07:01:00Z" },
435
+ };
436
+ state.shells.set("one", shell(completed, { id: "other" }));
437
+ state.shells.set("one", shell({ ...completed, hasPendingApprovals: true }, { id: "other" }));
438
+ state.shells.set(
439
+ "one",
440
+ shell({ ...completed, hasPendingApprovals: true }, { ...completed, id: "other" }),
441
+ );
442
+ state.shells.set("two", shell(completed));
443
+ expect(state.toast).toHaveBeenCalledTimes(4);
444
+
445
+ app.openThread("one", "thread");
446
+ expect(state.closeToast.mock.calls).toEqual([["one-completed"], ["one-approval"]]);
447
+
448
+ state.mode = "off";
449
+ state.inApp = false;
450
+ app.changeSettings();
451
+ expect(state.closeToast.mock.calls.slice(2).flat().toSorted()).toEqual([
452
+ "one-other",
453
+ "two-completed",
454
+ ]);
455
+});
apps/web/src/components/ThreadNotificationCoordinator.tsx
+25
-10
@@ -79,13 +79,31 @@ export function startThreadNotifications(
79
pending.set(notification.tag, { environmentId, threadId, notification });
80
setNotificationBadge(pending.size);
81
};
82
- // Toast ids by thread key, so hiding a thread can close its open toasts.
82
+ // Toast ids by thread key, so hiding or opening a thread can close its open toasts.
83
const openToasts = new Map<string, Array<ToastId>>();
84
const forgetToast = (key: string, toastId: ToastId) => {
85
const remaining = (openToasts.get(key) ?? []).filter((id) => id !== toastId);
86
if (remaining.length === 0) openToasts.delete(key);
87
else openToasts.set(key, remaining);
88
};
89
+ const closeToasts = (shouldClose: (key: string) => boolean) => {
90
+ for (const [key, toastIds] of openToasts) {
91
+ if (!shouldClose(key)) continue;
92
+ for (const toastId of toastIds) toastManager.close(toastId);
93
+ openToasts.delete(key);
94
+ }
95
+ };
96
+ const activeThread = () =>
97
+ (router.state.matches.at(-1)?.params ?? {}) as {
98
+ environmentId?: EnvironmentId;
99
+ threadId?: ThreadId;
100
+ };
101
+ const closeOpenedThreadToasts = () => {
102
+ const { environmentId, threadId } = activeThread();
103
+ if (environmentId === undefined || threadId === undefined) return;
104
+ const opened = threadKey({ environmentId, threadId });
105
+ closeToasts((key) => key === opened);
106
+ };
107
// A notification shown before the tag filter turned on must not stay on screen. While hiding,
108
// one whose thread left the live list (archived) cannot be judged, so it closes too.
109
const closeHiddenPending = () => {
@@ -94,11 +112,7 @@ export function startThreadNotifications(
112
? new Set(registry.get(environmentThreadShells.threadRefsAtom).map(threadKey))
113
: null;
114
const shouldClose = (key: string) => hidden.has(key) || (live !== null && !live.has(key));
97
- for (const [key, toastIds] of openToasts) {
98
- if (!shouldClose(key)) continue;
99
- for (const toastId of toastIds) toastManager.close(toastId);
100
- openToasts.delete(key);
101
- }
115
+ closeToasts(shouldClose);
116
const count = pending.size;
117
for (const [tag, entry] of pending) {
118
if (!shouldClose(threadKey(entry))) continue;
@@ -126,10 +140,7 @@ export function startThreadNotifications(
140
)
141
return;
142
const { notificationMode: mode, inAppNotificationsEnabled } = getClientSettings();
129
- const active = (router.state.matches.at(-1)?.params ?? {}) as {
130
- environmentId?: string;
131
- threadId?: string;
132
- };
143
+ const active = activeThread();
144
const title =
145
kind === "completion"
146
? "Thread completed"
@@ -347,6 +358,7 @@ export function startThreadNotifications(
358
const syncEnvironments = () => {
359
const { notificationMode, inAppNotificationsEnabled } = getClientSettings();
360
const enabled = notificationMode !== "off" || inAppNotificationsEnabled;
361
+ if (!enabled) closeToasts(() => true);
362
const environmentIds = enabled ? registry.get(environmentSummaries.environmentIdsAtom) : [];
363
const activeIds = new Set(environmentIds);
364
for (const [environmentId, entry] of watched) {
@@ -419,14 +431,17 @@ export function startThreadNotifications(
431
registry.subscribe(environmentThreadShells.anyEnvironmentHidingAtom, closeHiddenPending),
432
registry.subscribe(environmentThreadShells.threadRefsAtom, closeHiddenPending),
433
];
434
+ const unsubscribeRoute = router.subscribe("onResolved", closeOpenedThreadToasts);
435
onSettings();
436
437
return () => {
438
unsubscribeSettings();
439
unsubscribeEnvironmentIds();
440
for (const unsubscribe of unsubscribeHidden) unsubscribe();
441
+ unsubscribeRoute();
442
for (const entry of watched.values()) entry.unsubscribe();
443
watched.clear();
444
stopModeListeners();
445
+ closeToasts(() => true);
446
};
447
}