Commit 2d878b8
authored
fix(commandline): improve caching to fix stale checkmark and UI state (@byseif21, @fehmer) (monkeytypegame#6586)
### Description
Previously, when selecting a language via the text button on the test
page, the checkmark (fa-check) in the commandline language list wouldn't
update until a page refresh. This was due to the commandline's caching
mechanism not detecting changes triggered outside its own control.
Although it first appeared to be a language-specific issue, it was later
identified that the caching logic was generally insufficient — it didn’t
account for updates to the active command state or configuration flags
like usingSingleList.
## Solution
Fixed the caching logic in the commandline module by tracking a more
complete internal state. The system now correctly detects changes in the
command list, active state, and configuration, and rebuilds the list UI
when necessary.
## Technical Details
- The commandline uses a caching mechanism (`lastList`) to avoid
rebuilding the HTML if the list hasn't changed done in monkeytypegame#6559
- Replaced the old lastList cache with a new lastState object that
stores: the list of commands, each with its isActive flag, the
usingSingleList configuration flag
- Improved the cache comparison logic, uses areSortedArraysEqual to
compare command lists including active state ,compares the
usingSingleList flag
- Previously, this cache wasn't being cleared when the language changed
through the text button
- Now we clear the cache on changes, forcing a rebuild of the list with
the correct checkmark
## Performance Impact
- Minimal performance impact
- The list is only rebuilt when:
1. The language actually changes
2. The list content changes
3. The input value changes
- The caching mechanism still prevents unnecessary rebuilds in all other
cases
## Testing
- [x] Language selection through text button updates checkmark
immediately
- [x] Language selection through commandline works as before
- [x] No unnecessary rebuilds when language hasn't changed
- [x] Checkmark appears next to correct language in all cases1 parent 5695245 commit 2d878b8
1 file changed
+50
-37
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
42 | 51 | | |
43 | 52 | | |
44 | 53 | | |
| |||
328 | 337 | | |
329 | 338 | | |
330 | 339 | | |
331 | | - | |
| 340 | + | |
332 | 341 | | |
333 | 342 | | |
334 | 343 | | |
| |||
353 | 362 | | |
354 | 363 | | |
355 | 364 | | |
356 | | - | |
357 | | - | |
358 | 365 | | |
359 | 366 | | |
360 | 367 | | |
| |||
366 | 373 | | |
367 | 374 | | |
368 | 375 | | |
369 | | - | |
370 | | - | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
371 | 405 | | |
372 | 406 | | |
373 | | - | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
374 | 412 | | |
375 | 413 | | |
376 | 414 | | |
| |||
387 | 425 | | |
388 | 426 | | |
389 | 427 | | |
390 | | - | |
391 | | - | |
392 | | - | |
393 | | - | |
394 | | - | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | | - | |
406 | | - | |
407 | | - | |
408 | | - | |
409 | | - | |
410 | | - | |
411 | | - | |
412 | | - | |
413 | | - | |
414 | | - | |
415 | | - | |
416 | | - | |
417 | | - | |
418 | | - | |
419 | | - | |
420 | | - | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
421 | 433 | | |
| 434 | + | |
422 | 435 | | |
423 | 436 | | |
424 | 437 | | |
| |||
0 commit comments