Skip to content

Commit 8a9a7fc

Browse files
J-Karthikeyanmshareef-git
authored andcommitted
fix(test-timer): slow timer notification reappearing after new test (@J-Karthikeyan) (monkeytypegame#7808)
### Description When a test fails due to the slow timer, the error notification ("Stopping the test due to bad performance...") has no auto dismiss timeout so it stays in the notification store indefinitely so it reappears once the next test is completed. When we start a new test, the notification gets visually hidden by focus mode (non important notifications get a `hidden` class when getFocus() is true). When the test ends, focus mode turns off and the notification reappears making it look like it fired again when it didn't. ### Steps to Reproduce 1. Start a test and let the slow timer trigger the notification by just typing one or two letter and leaving it. 2. Do NOT dismiss the notification 3. Start and complete a new test without a page refresh 4. The notification reappears at the end of the new test ### Fix Fix: track the error notification's ID when the slow timer fires, and remove it from the store when a new test starts via TestTimer.start().
1 parent 745ac7c commit 8a9a7fc

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

frontend/src/ts/states/notifications.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export function addNotificationWithLevel(
115115
message: string,
116116
level: NotificationLevel,
117117
options: AddNotificationOptions = {},
118-
): void {
118+
): number {
119119
let details = options.details;
120120

121121
if (options.response !== undefined) {
@@ -174,25 +174,27 @@ export function addNotificationWithLevel(
174174
}, durationMs + 250);
175175
autoRemoveTimers.set(notifId, timer);
176176
}
177+
178+
return notifId;
177179
}
178180

179181
export function showNoticeNotification(
180182
message: string,
181183
options?: AddNotificationOptions,
182-
): void {
183-
addNotificationWithLevel(message, "notice", options);
184+
): number {
185+
return addNotificationWithLevel(message, "notice", options);
184186
}
185187

186188
export function showSuccessNotification(
187189
message: string,
188190
options?: AddNotificationOptions,
189-
): void {
190-
addNotificationWithLevel(message, "success", options);
191+
): number {
192+
return addNotificationWithLevel(message, "success", options);
191193
}
192194

193195
export function showErrorNotification(
194196
message: string,
195197
options?: AddNotificationOptions,
196-
): void {
197-
addNotificationWithLevel(message, "error", options);
198+
): number {
199+
return addNotificationWithLevel(message, "error", options);
198200
}

frontend/src/ts/test/test-timer.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import * as Numbers from "@monkeytype/util/numbers";
1414
import {
1515
showNoticeNotification,
1616
showErrorNotification,
17+
removeNotification,
1718
} from "../states/notifications";
1819
import * as Caret from "./caret";
1920
import * as SlowTimer from "../legacy-states/slow-timer";
@@ -52,6 +53,7 @@ type TimerStats = {
5253
};
5354

5455
let slowTimerCount = 0;
56+
let slowTimerNotifIds: number[] = [];
5557
let timer: NodeJS.Timeout | null = null;
5658
const interval = 1000;
5759
let expected = 0;
@@ -284,8 +286,10 @@ function checkIfTimerIsSlow(drift: number): void {
284286
'This could be caused by "efficiency mode" on Microsoft Edge.',
285287
);
286288

287-
showErrorNotification(
288-
"Stopping the test due to bad performance. This would cause test calculations to be incorrect. If this happens a lot, please report this.",
289+
slowTimerNotifIds.push(
290+
showErrorNotification(
291+
"Stopping the test due to bad performance. This would cause test calculations to be incorrect. If this happens a lot, please report this.",
292+
),
289293
);
290294

291295
timerEvent.dispatch({ key: "fail", value: "slow timer" });
@@ -296,6 +300,10 @@ function checkIfTimerIsSlow(drift: number): void {
296300
export async function start(): Promise<void> {
297301
SlowTimer.clear();
298302
slowTimerCount = 0;
303+
for (const id of slowTimerNotifIds) {
304+
removeNotification(id, "clear");
305+
}
306+
slowTimerNotifIds = [];
299307
void _startNew();
300308
// void _startOld();
301309
}

0 commit comments

Comments
 (0)