From 8292fe90e371310da5cc8f6b05aa2e313ba4f90d Mon Sep 17 00:00:00 2001 From: Abijeet Date: Tue, 16 May 2023 17:47:19 +0530 Subject: [PATCH] uls.lcd: Add auto-correcting code when index goes beyond max index Leave the error logging code in place in order to identify any other places where this issue occurs. Bug: https://phabricator.wikimedia.org/T328956 --- src/jquery.uls.lcd.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/jquery.uls.lcd.js b/src/jquery.uls.lcd.js index 39bf8f7..c5f5da4 100644 --- a/src/jquery.uls.lcd.js +++ b/src/jquery.uls.lcd.js @@ -112,8 +112,15 @@ if ( this.navigationIndex === null ) { this.navigationIndex = 0; } else { - this.navigationIndex++; + // Auto-correct the index. It has been noticed that the navigationIndex goes beyond the + // max index sometimes. See: phab:T328956#8854835 + if ( this.navigationIndex > maxIndex ) { + this.navigationIndex = maxIndex; + } else { + this.navigationIndex++; + } } + this.highlightLanguageOption(); },