Skip to content

Commit 2f9195e

Browse files
committed
fix: rare issue where previous test mistakes would show in a new test
1 parent 088ca5d commit 2f9195e

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

frontend/src/ts/test/test-ui.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ import {
2626
} from "./funbox/list";
2727
import * as TestState from "./test-state";
2828
import * as PaceCaret from "./pace-caret";
29-
import { requestDebouncedAnimationFrame } from "../utils/debounced-animation-frame";
29+
import {
30+
cancelPendingAnimationFramesStartingWith,
31+
requestDebouncedAnimationFrame,
32+
} from "../utils/debounced-animation-frame";
3033
import * as SoundController from "../controllers/sound-controller";
3134
import * as Numbers from "@monkeytype/util/numbers";
3235
import * as TestStats from "./test-stats";
@@ -165,6 +168,7 @@ export function setResultCalculating(val: boolean): void {
165168

166169
export function reset(): void {
167170
currentTestLine = 0;
171+
cancelPendingAnimationFramesStartingWith("test-ui");
168172
}
169173

170174
export function focusWords(force = false): void {

frontend/src/ts/utils/debounced-animation-frame.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,15 @@ function cancelIfPending(frameId: string): void {
1919
pendingFrames.delete(frameId);
2020
}
2121
}
22+
23+
export function cancelPendingAnimationFrame(frameId: string): void {
24+
cancelIfPending(frameId);
25+
}
26+
27+
export function cancelPendingAnimationFramesStartingWith(prefix: string): void {
28+
for (const frameId of pendingFrames.keys()) {
29+
if (frameId.startsWith(prefix)) {
30+
cancelIfPending(frameId);
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)