@@ -51,6 +51,8 @@ const $overwriteGetInitialProps = createStatefulObservable<(() => void) | undefi
51
51
( ) => undefined
52
52
) ;
53
53
54
+ let defaultColorScheme : ColorScheme | "system" ;
55
+
54
56
export function getColorSchemeSsrUtils ( ) {
55
57
$overwriteGetInitialProps . current ?.( ) ;
56
58
@@ -63,7 +65,17 @@ export function getColorSchemeSsrUtils() {
63
65
function readColorSchemeFromCookie ( ctx : DocumentContext ) {
64
66
const cookie = ctx . req ?. headers . cookie ;
65
67
66
- colorScheme = cookie === undefined ? undefined : readColorSchemeInCookie ( cookie ) ;
68
+ colorScheme =
69
+ ( cookie === undefined ? undefined : readColorSchemeInCookie ( cookie ) ) ??
70
+ ( ( ) => {
71
+ switch ( defaultColorScheme ) {
72
+ case "light" :
73
+ case "dark" :
74
+ return defaultColorScheme ;
75
+ case "system" :
76
+ return undefined ;
77
+ }
78
+ } ) ( ) ;
67
79
68
80
isNextTickCleared = false ;
69
81
@@ -107,7 +119,10 @@ export function withAppDsfr<AppComponent extends NextComponentType<any, any, any
107
119
108
120
if ( isBrowser ) {
109
121
startDsfrReact ( startDsfrReactParams ) ;
122
+ } else {
123
+ defaultColorScheme = startDsfrReactParams . defaultColorScheme ;
110
124
}
125
+
111
126
function AppWithDsfr ( props : AppProps ) {
112
127
return (
113
128
< >
@@ -133,6 +148,7 @@ export function withAppDsfr<AppComponent extends NextComponentType<any, any, any
133
148
href = { faviconWebmanifestUrl }
134
149
crossOrigin = "use-credentials"
135
150
/>
151
+ < style > { `:root { color-scheme: ${ $colorScheme . current } ; }` } </ style >
136
152
</ Head >
137
153
< App { ...( props as any ) } />
138
154
</ >
@@ -155,7 +171,16 @@ export function withAppDsfr<AppComponent extends NextComponentType<any, any, any
155
171
const cookie = appContext . ctx . req ?. headers . cookie ;
156
172
157
173
return cookie === undefined ? undefined : readColorSchemeInCookie ( cookie ) ;
158
- } ) ( ) ?? "light" ;
174
+ } ) ( ) ??
175
+ ( ( ) => {
176
+ switch ( startDsfrReactParams . defaultColorScheme ) {
177
+ case "dark" :
178
+ case "light" :
179
+ return startDsfrReactParams . defaultColorScheme ;
180
+ case "system" :
181
+ return "light" ;
182
+ }
183
+ } ) ( ) ;
159
184
}
160
185
161
186
return { ...initialProps } ;
0 commit comments