File tree Expand file tree Collapse file tree 1 file changed +7
-1
lines changed
Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Original file line number Diff line number Diff line change 1+ //uses isDark state to choose styled-component theme (in themeStyles.js)
2+ //and use ThemeProvider to allow all styled components access to values via props.theme
3+
14import React , { useContext } from "react" ;
25import { ThemeProvider } from "styled-components" ;
36import { ThemeManagerContext } from "./ThemeManager" ;
47
8+ // Safe check for browser environment
59const isBrowser = typeof window !== "undefined" ;
610
711export const StyledThemeProvider = ( props ) => {
812 const { children, darkTheme, lightTheme } = props ;
913 const { isDark, didLoad } = useContext ( ThemeManagerContext ) ;
1014
15+ // For SSR, we need to provide a consistent theme initially
16+ // This ensures the server and client render the same thing initially
1117 const currentTheme = isDark ? darkTheme : lightTheme ;
1218 const theme = {
1319 ...( didLoad ? currentTheme : transformTheme ( currentTheme ) ) ,
@@ -20,7 +26,7 @@ export const StyledThemeProvider = (props) => {
2026 ) ;
2127} ;
2228
23- const transformTheme = ( theme ) => {
29+ // Maps JS theme object to raw CSS variables (--key) initialized via onRenderBody. const transformTheme = (theme) => {
2430 const newTheme = { } ;
2531 Object . keys ( theme ) . forEach ( ( key ) => {
2632 const value = theme [ key ] ;
You can’t perform that action at this time.
0 commit comments