From 8dd133fdd75615e493545fea54e2c1a6dfb2e58b Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Sun, 10 Sep 2023 02:12:18 +0200 Subject: [PATCH] [system] Remove getInitColorSchemeScript leading spaces (#38794) --- .../src/cssVars/getInitColorSchemeScript.tsx | 51 ++++++++++--------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/packages/mui-system/src/cssVars/getInitColorSchemeScript.tsx b/packages/mui-system/src/cssVars/getInitColorSchemeScript.tsx index d938a0ef8aeb2e..4170e0ace8cd9c 100644 --- a/packages/mui-system/src/cssVars/getInitColorSchemeScript.tsx +++ b/packages/mui-system/src/cssVars/getInitColorSchemeScript.tsx @@ -57,31 +57,32 @@ export default function getInitColorSchemeScript(options?: GetInitColorSchemeScr key="mui-color-scheme-init" // eslint-disable-next-line react/no-danger dangerouslySetInnerHTML={{ - __html: `(function() { try { - var mode = localStorage.getItem('${modeStorageKey}') || '${defaultMode}'; - var cssColorScheme = mode; - var colorScheme = ''; - if (mode === 'system') { - // handle system mode - var mql = window.matchMedia('(prefers-color-scheme: dark)'); - if (mql.matches) { - cssColorScheme = 'dark'; - colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}'; - } else { - cssColorScheme = 'light'; - colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || '${defaultLightColorScheme}'; - } - } - if (mode === 'light') { - colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || '${defaultLightColorScheme}'; - } - if (mode === 'dark') { - colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}'; - } - if (colorScheme) { - ${colorSchemeNode}.setAttribute('${attribute}', colorScheme); - } - } catch (e) {} })();`, + __html: `(function() { +try { + var mode = localStorage.getItem('${modeStorageKey}') || '${defaultMode}'; + var cssColorScheme = mode; + var colorScheme = ''; + if (mode === 'system') { + // handle system mode + var mql = window.matchMedia('(prefers-color-scheme: dark)'); + if (mql.matches) { + cssColorScheme = 'dark'; + colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}'; + } else { + cssColorScheme = 'light'; + colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || '${defaultLightColorScheme}'; + } + } + if (mode === 'light') { + colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || '${defaultLightColorScheme}'; + } + if (mode === 'dark') { + colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}'; + } + if (colorScheme) { + ${colorSchemeNode}.setAttribute('${attribute}', colorScheme); + } +} catch (e) {} })();`, }} /> );