Skip to content

Commit 3d2e060

Browse files
authored
fix breakpoints / flash (#5627)
* fix breakpoints * version bump * I think this work * clear logs * reduce diff * less diff * less diff * where did that import come from? * less diff again * pass the tests
1 parent 9d9ff9e commit 3d2e060

File tree

3 files changed

+13
-21
lines changed

3 files changed

+13
-21
lines changed

reflex/.templates/web/utils/react-theme.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,9 @@ const ThemeContext = createContext({
1818

1919
export function ThemeProvider({ children, defaultTheme = "system" }) {
2020
const [theme, setTheme] = useState(defaultTheme);
21-
22-
// Detect system preference synchronously during initialization
23-
const getInitialSystemTheme = () => {
24-
if (defaultTheme !== "system") return defaultTheme;
25-
if (typeof window === "undefined") return "light";
26-
return window.matchMedia("(prefers-color-scheme: dark)").matches
27-
? "dark"
28-
: "light";
29-
};
30-
31-
const [systemTheme, setSystemTheme] = useState(getInitialSystemTheme);
21+
const [systemTheme, setSystemTheme] = useState(
22+
defaultTheme !== "system" ? defaultTheme : "light",
23+
);
3224
const [isInitialized, setIsInitialized] = useState(false);
3325

3426
const firstRender = useRef(true);
@@ -45,6 +37,7 @@ export function ThemeProvider({ children, defaultTheme = "system" }) {
4537
if (lastCompiledTheme !== defaultColorMode) {
4638
// on app startup, make sure the application color mode is persisted correctly.
4739
localStorage.setItem("last_compiled_theme", defaultColorMode);
40+
setIsInitialized(true);
4841
return;
4942
}
5043
}
@@ -78,19 +71,21 @@ export function ThemeProvider({ children, defaultTheme = "system" }) {
7871
};
7972
});
8073

81-
// Save theme to localStorage whenever it changes (but not on initial mount)
74+
// Save theme to localStorage whenever it changes
75+
// Skip saving only if theme key already exists and we haven't initialized yet
8276
useEffect(() => {
83-
if (isInitialized) {
84-
localStorage.setItem("theme", theme);
85-
}
86-
}, [theme, isInitialized]);
77+
const existingTheme = localStorage.getItem("theme");
78+
if (!isInitialized && existingTheme !== null) return;
79+
localStorage.setItem("theme", theme);
80+
}, [theme]);
8781

8882
useEffect(() => {
83+
if (!isInitialized) return;
8984
const root = window.document.documentElement;
9085
root.classList.remove("light", "dark");
9186
root.classList.add(resolvedTheme);
9287
root.style.colorScheme = resolvedTheme;
93-
}, [resolvedTheme]);
88+
}, [resolvedTheme, isInitialized]);
9489

9590
return createElement(
9691
ThemeContext.Provider,

reflex/constants/installer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def DEPENDENCIES(cls) -> dict[str, str]:
143143
"postcss-import": "16.1.1",
144144
"@react-router/dev": _react_router_version,
145145
"@react-router/fs-routes": _react_router_version,
146-
"rolldown-vite": "7.0.9",
146+
"rolldown-vite": "7.0.11",
147147
}
148148
OVERRIDES = {
149149
# This should always match the `react` version in DEPENDENCIES for recharts compatibility.

reflex/utils/misc.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ def preload_color_theme():
113113
const systemPreference = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
114114
const resolvedTheme = theme === "system" ? systemPreference : theme;
115115
116-
console.log("[PRELOAD] Theme applied:", resolvedTheme, "from theme:", theme, "system:", systemPreference);
117-
118116
// Apply theme immediately - blocks until complete
119117
// Use classList to avoid overwriting other classes
120118
document.documentElement.classList.remove("light", "dark");
@@ -124,7 +122,6 @@ def preload_color_theme():
124122
} catch (e) {
125123
// Fallback to system preference on any error (resolve "system" to actual theme)
126124
const fallbackTheme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
127-
console.log("[PRELOAD] Error, falling back to:", fallbackTheme);
128125
document.documentElement.classList.remove("light", "dark");
129126
document.documentElement.classList.add(fallbackTheme);
130127
document.documentElement.style.colorScheme = fallbackTheme;

0 commit comments

Comments
 (0)