mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-12-27 02:21:27 +08:00
chore: TypeError when deleting in zen (@byseif21) (#7282)
* fix error from race condition `Cannot read properties of null (reading 'remove')` when deletion in zen mode, added null check. The active word could already be removed when the debounced update runs, which caused a null error --------- Co-authored-by: Jack <jack@monkeytype.com>
This commit is contained in:
parent
a1240d3d7e
commit
fd177c9ed4
1 changed files with 9 additions and 10 deletions
|
|
@ -133,18 +133,17 @@ export function updateActiveElement(
|
|||
|
||||
let previousActiveWordTop: number | null = null;
|
||||
if (initial === undefined) {
|
||||
const previousActiveWord = wordsEl.querySelector(
|
||||
".active",
|
||||
) as HTMLElement;
|
||||
if (direction === "forward") {
|
||||
previousActiveWord.classList.add("typed");
|
||||
} else if (direction === "back") {
|
||||
if (Config.mode === "zen") {
|
||||
previousActiveWord.remove();
|
||||
const previousActiveWord = wordsEl.querySelector<HTMLElement>(".active");
|
||||
// in zen mode, because of the animation frame, previousActiveWord will be removed at this point, so check for null
|
||||
if (previousActiveWord !== null) {
|
||||
if (direction === "forward") {
|
||||
previousActiveWord.classList.add("typed");
|
||||
} else if (direction === "back") {
|
||||
//
|
||||
}
|
||||
previousActiveWord.classList.remove("active");
|
||||
previousActiveWordTop = previousActiveWord.offsetTop;
|
||||
}
|
||||
previousActiveWord.classList.remove("active");
|
||||
previousActiveWordTop = previousActiveWord.offsetTop;
|
||||
}
|
||||
|
||||
const newActiveWord = getActiveWordElement();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue