From a17590b5f9c792d21bdf74af93db1d993de34785 Mon Sep 17 00:00:00 2001 From: J-Karthikeyan Date: Fri, 10 Apr 2026 21:50:50 +0530 Subject: [PATCH 1/2] fix(test-timer): clear slow timer notifications on test restart --- frontend/src/ts/states/notifications.ts | 12 +++++++----- frontend/src/ts/test/test-timer.ts | 12 ++++++++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/frontend/src/ts/states/notifications.ts b/frontend/src/ts/states/notifications.ts index d003750fb3d8..503c49296815 100644 --- a/frontend/src/ts/states/notifications.ts +++ b/frontend/src/ts/states/notifications.ts @@ -115,7 +115,7 @@ export function addNotificationWithLevel( message: string, level: NotificationLevel, options: AddNotificationOptions = {}, -): void { +): number { let details = options.details; if (options.response !== undefined) { @@ -174,13 +174,15 @@ export function addNotificationWithLevel( }, durationMs + 250); autoRemoveTimers.set(notifId, timer); } + + return notifId; } export function showNoticeNotification( message: string, options?: AddNotificationOptions, -): void { - addNotificationWithLevel(message, "notice", options); +): number { + return addNotificationWithLevel(message, "notice", options); } export function showSuccessNotification( @@ -193,6 +195,6 @@ export function showSuccessNotification( export function showErrorNotification( message: string, options?: AddNotificationOptions, -): void { - addNotificationWithLevel(message, "error", options); +): number { + return addNotificationWithLevel(message, "error", options); } diff --git a/frontend/src/ts/test/test-timer.ts b/frontend/src/ts/test/test-timer.ts index 26cf66b694e3..cff4ac39940d 100644 --- a/frontend/src/ts/test/test-timer.ts +++ b/frontend/src/ts/test/test-timer.ts @@ -14,6 +14,7 @@ import * as Numbers from "@monkeytype/util/numbers"; import { showNoticeNotification, showErrorNotification, + removeNotification, } from "../states/notifications"; import * as Caret from "./caret"; import * as SlowTimer from "../legacy-states/slow-timer"; @@ -52,6 +53,7 @@ type TimerStats = { }; let slowTimerCount = 0; +let slowTimerNotifIds: number[] = []; let timer: NodeJS.Timeout | null = null; const interval = 1000; let expected = 0; @@ -282,8 +284,10 @@ function checkIfTimerIsSlow(drift: number): void { 'This could be caused by "efficiency mode" on Microsoft Edge.', ); - showErrorNotification( - "Stopping the test due to bad performance. This would cause test calculations to be incorrect. If this happens a lot, please report this.", + slowTimerNotifIds.push( + showErrorNotification( + "Stopping the test due to bad performance. This would cause test calculations to be incorrect. If this happens a lot, please report this.", + ), ); timerEvent.dispatch({ key: "fail", value: "slow timer" }); @@ -294,6 +298,10 @@ function checkIfTimerIsSlow(drift: number): void { export async function start(): Promise { SlowTimer.clear(); slowTimerCount = 0; + for (const id of slowTimerNotifIds) { + removeNotification(id, "clear"); + } + slowTimerNotifIds = []; void _startNew(); // void _startOld(); } From c288fe879228e5aa0473d3ab98fa85b73916e0b5 Mon Sep 17 00:00:00 2001 From: J-Karthikeyan Date: Fri, 10 Apr 2026 22:08:34 +0530 Subject: [PATCH 2/2] fix(notifications): make showSuccessNotification return notification id --- frontend/src/ts/states/notifications.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/ts/states/notifications.ts b/frontend/src/ts/states/notifications.ts index 503c49296815..3108c1594d1d 100644 --- a/frontend/src/ts/states/notifications.ts +++ b/frontend/src/ts/states/notifications.ts @@ -188,8 +188,8 @@ export function showNoticeNotification( export function showSuccessNotification( message: string, options?: AddNotificationOptions, -): void { - addNotificationWithLevel(message, "success", options); +): number { + return addNotificationWithLevel(message, "success", options); } export function showErrorNotification(