diff --git a/web/__test__/store/theme.test.ts b/web/__test__/store/theme.test.ts index f301ac2f2d..286bdfd9c7 100644 --- a/web/__test__/store/theme.test.ts +++ b/web/__test__/store/theme.test.ts @@ -298,5 +298,17 @@ describe('Theme Store', () => { expect(document.body.classList.remove).toHaveBeenCalledWith('dark'); expect(store.darkMode).toBe(false); }); + + it('should remove stale dark classes when only the dark mode CSS variable is light', () => { + document.documentElement.style.setProperty('--theme-dark-mode', '0'); + originalDocumentElementAddClass.call(document.documentElement.classList, 'dark'); + originalAddClassFn.call(document.body.classList, 'dark'); + + const store = createStore(); + + expect(document.documentElement.classList.remove).toHaveBeenCalledWith('dark'); + expect(document.body.classList.remove).toHaveBeenCalledWith('dark'); + expect(store.darkMode).toBe(false); + }); }); }); diff --git a/web/src/store/theme.ts b/web/src/store/theme.ts index cd0f6178ef..e4f3208330 100644 --- a/web/src/store/theme.ts +++ b/web/src/store/theme.ts @@ -68,12 +68,6 @@ const applyDarkClass = (isDark: boolean, darkModeRef?: { value: boolean }) => { } }; -const bootstrapDarkClass = (darkModeRef?: { value: boolean }) => { - if (isDarkModeActive()) { - applyDarkClass(true, darkModeRef); - } -}; - const sanitizeTheme = (data: Partial | null | undefined): Theme | null => { if (!data || typeof data !== 'object') { return null; @@ -216,8 +210,7 @@ export const useThemeStore = defineStore('theme', () => { setTheme({ name: domThemeName }); applyDarkClass(isDarkThemeName(domThemeName), darkMode); } else if (isDomAvailable()) { - darkMode.value = isDarkModeActive(); - bootstrapDarkClass(darkMode); + applyDarkClass(isDarkModeActive(), darkMode); } return {