diff --git a/static/settings.ts b/static/settings.ts index 903d7e06f..54854315e 100644 --- a/static/settings.ts +++ b/static/settings.ts @@ -30,7 +30,7 @@ import {themes, Themes} from './themes'; import {AppTheme, ColourScheme, ColourSchemeInfo} from './colour'; import {Hub} from './hub'; import {EventHub} from './event-hub'; -import {keys} from '../lib/common-utils'; +import {keys, isString} from '../lib/common-utils'; import {assert, unwrapString} from './assert'; import {LanguageKey} from '../types/languages.interfaces'; @@ -459,12 +459,16 @@ export class Settings { const themeSelect = this.root.find('.theme'); const colourSchemeSelect = this.root.find('.colourScheme'); - if (!colourSchemeSelect.val()) { - return; - } - const oldScheme = unwrapString(colourSchemeSelect.val()); + const oldScheme = colourSchemeSelect.val(); const newTheme = unwrapString(themeSelect.val()); + // Small check to make sure we aren't getting something completely unexpected, like a string[] or number + assert( + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition + isString(oldScheme) || oldScheme === undefined || oldScheme == null, + 'Unexpected value received from colourSchemeSelect.val()' + ); + this.fillColourSchemeSelector(colourSchemeSelect, newTheme); const newThemeStoredScheme = $.data(themeSelect, 'theme-' + newTheme) as colour.AppTheme | undefined; @@ -473,7 +477,7 @@ export class Settings { // If we have one old one stored, check if it's still valid and set it if so if (newThemeStoredScheme && this.selectorHasOption(colourSchemeSelect, newThemeStoredScheme)) { newScheme = newThemeStoredScheme; - } else if (this.selectorHasOption(colourSchemeSelect, oldScheme)) { + } else if (isString(oldScheme) && this.selectorHasOption(colourSchemeSelect, oldScheme)) { newScheme = oldScheme; }