From 751f25914f8e7b6cda93e371fdad657a7f4ebbc5 Mon Sep 17 00:00:00 2001 From: Josh Hunt Date: Thu, 14 Aug 2025 10:32:01 +0100 Subject: [PATCH] FS: Fix theme- class name not being set on body (#109631) --- pkg/services/frontend/index.html | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/pkg/services/frontend/index.html b/pkg/services/frontend/index.html index f582df4604e..97dacad25ae 100644 --- a/pkg/services/frontend/index.html +++ b/pkg/services/frontend/index.html @@ -262,18 +262,14 @@ const theme = window.grafanaBootData.user.theme; if (theme === "system") { const darkQuery = window.matchMedia("(prefers-color-scheme: dark)"); - - if (darkQuery.matches) { - document.body.classList.add("theme-dark"); - window.grafanaBootData.user.lightTheme = false; - } else { - document.body.classList.add("theme-light"); - window.grafanaBootData.user.lightTheme = true; - } + window.grafanaBootData.user.lightTheme = !darkQuery.matches; } - const isLightTheme = window.grafanaBootData.user.lightTheme; - cssLink.href = window.grafanaBootData.assets[isLightTheme ? 'light' : 'dark']; + const isLightTheme = window.grafanaBootData.user.lightTheme; + + document.body.classList.add(isLightTheme ? "theme-light" : "theme-dark"); + + cssLink.href = window.grafanaBootData.assets[isLightTheme ? 'light' : 'dark']; document.head.appendChild(cssLink); }