Skip to content

Commit 4491cc1

Browse files
committed
add one more comment
Signed-off-by: Ankit Rewar <AnkitRewar11@users.noreply.github.com>
1 parent f60787a commit 4491cc1

File tree

4 files changed

+6
-29
lines changed

4 files changed

+6
-29
lines changed

onRenderBody.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import lighttheme, { darktheme } from "./src/theme/app/themeStyles";
55
const themes = { light: lighttheme, dark: darktheme };
66

77
const MagicScriptTag = (props) => {
8-
// FIX: Stringify the theme object outside the template literal to prevent
8+
// FIX: Stringify the theme object outside the template literal to prevent syntax errors caused by unescaped quotes inside theme values.
99
const themeJSON = JSON.stringify(props.theme);
1010

1111
// Injects CSS variables and theme state strictly before the first paint to prevent FOUC.

src/html.js

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,41 +25,20 @@ export default function HTML(props) {
2525
{props.headComponents}
2626
</head>
2727
<body {...props.bodyAttributes}>
28-
{/* Script for theme initialization - needs to run before React renders to prevent flicker */}
28+
{/* Script for banner initialization */}
2929
<script
3030
dangerouslySetInnerHTML={{
3131
__html: `
3232
(function() {
3333
try {
34-
// Theme initialization
35-
const darkThemeKey = 'theme';
36-
let initialTheme = 'system';
37-
try {
38-
initialTheme = localStorage.getItem(darkThemeKey) || 'system';
39-
} catch (e) {}
40-
41-
// Determine initial dark mode
42-
let isDarkMode = false;
43-
if (initialTheme === 'dark') {
44-
isDarkMode = true;
45-
} else if (initialTheme === 'system') {
46-
isDarkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
47-
}
48-
49-
// Set initial color mode
50-
document.documentElement.style.setProperty(
51-
'--initial-color-mode',
52-
isDarkMode ? 'dark' : 'light'
53-
);
54-
5534
// Banner initialization
5635
var banner = sessionStorage.getItem('banner');
5736
if (banner === null)
5837
document.body.classList.add('banner1');
5938
else
6039
document.body.classList.add('banner' + banner);
6140
} catch (e) {
62-
console.error('Error in theme initialization:', e);
41+
console.error('Error in banner initialization:', e);
6342
}
6443
})();
6544
`,

src/theme/app/StyledThemeProvider.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ import React, { useContext } from "react";
55
import { ThemeProvider } from "styled-components";
66
import { ThemeManagerContext } from "./ThemeManager";
77

8-
// Safe check for browser environment
9-
const isBrowser = typeof window !== "undefined";
10-
118
export const StyledThemeProvider = (props) => {
129
const { children, darkTheme, lightTheme } = props;
1310
const { isDark, didLoad } = useContext(ThemeManagerContext);

src/theme/app/ThemeManager.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ export const ThemeManagerProvider = (props) => {
5757

5858
const root = window.document.documentElement;
5959
const initialColorValue = (root.style.getPropertyValue("--initial-color-mode") || "").trim();
60-
const actualTheme = window.__theme || initialColorValue || ThemeSetting.LIGHT;
61-
60+
const actualTheme = window.__theme || initialColorValue || ThemeSetting.DARK;
61+
62+
// Get stored theme from localStorage
6263
const storedTheme = localStorage.getItem(DarkThemeKey);
6364

6465
if (storedTheme && storedTheme !== ThemeSetting.SYSTEM) {

0 commit comments

Comments
 (0)