@@ -126,6 +126,7 @@ export function getColorSchemeSsrUtils() {
126
126
return { getColorSchemeHtmlAttributes, augmentDocumentByReadingColorSchemeFromCookie } ;
127
127
}
128
128
129
+ /** the App returned by witAppDsfr should be directly exported default as is */
129
130
export function withAppDsfr < AppComponent extends NextComponentType < any , any , any > > (
130
131
App : AppComponent ,
131
132
params : Params
@@ -170,40 +171,38 @@ export function withAppDsfr<AppComponent extends NextComponentType<any, any, any
170
171
) ;
171
172
}
172
173
173
- Object . keys ( App ) . forEach (
174
- staticMethod => ( ( AppWithDsfr as any ) [ staticMethod ] = ( App as any ) [ staticMethod ] )
175
- ) ;
176
-
177
- $overwriteGetInitialProps . current = ( ) => {
174
+ {
178
175
const super_getInitialProps =
179
- ( AppWithDsfr as any ) . getInitialProps . bind ( AppWithDsfr ) ??
180
- App . getInitialProps ?. bind ( App ) ??
181
- DefaultApp . getInitialProps . bind ( DefaultApp ) ;
182
-
183
- ( AppWithDsfr as any ) . getInitialProps = async ( appContext : AppContext ) => {
184
- const initialProps = await super_getInitialProps ( appContext ) ;
185
-
186
- if ( ! isBrowser ) {
187
- $colorScheme . current =
188
- ( ( ) => {
189
- const cookie = appContext . ctx . req ?. headers . cookie ;
190
-
191
- return cookie === undefined ? undefined : readColorSchemeInCookie ( cookie ) ;
192
- } ) ( ) ??
193
- ( ( ) => {
194
- switch ( startDsfrReactParams . defaultColorScheme ) {
195
- case "dark" :
196
- case "light" :
197
- return startDsfrReactParams . defaultColorScheme ;
198
- case "system" :
199
- return "light" ;
200
- }
201
- } ) ( ) ;
202
- }
203
-
204
- return { ...initialProps } ;
176
+ App . getInitialProps ?. bind ( App ) ?? DefaultApp . getInitialProps . bind ( DefaultApp ) ;
177
+
178
+ $overwriteGetInitialProps . current = ( ) => {
179
+ ( AppWithDsfr as any ) . getInitialProps = async ( appContext : AppContext ) => {
180
+ const initialProps = await super_getInitialProps ( appContext ) ;
181
+
182
+ if ( ! isBrowser ) {
183
+ $colorScheme . current =
184
+ ( ( ) => {
185
+ const cookie = appContext . ctx . req ?. headers . cookie ;
186
+
187
+ return cookie === undefined
188
+ ? undefined
189
+ : readColorSchemeInCookie ( cookie ) ;
190
+ } ) ( ) ??
191
+ ( ( ) => {
192
+ switch ( startDsfrReactParams . defaultColorScheme ) {
193
+ case "dark" :
194
+ case "light" :
195
+ return startDsfrReactParams . defaultColorScheme ;
196
+ case "system" :
197
+ return "light" ;
198
+ }
199
+ } ) ( ) ;
200
+ }
201
+
202
+ return { ...initialProps } ;
203
+ } ;
205
204
} ;
206
- } ;
205
+ }
207
206
208
207
AppWithDsfr . displayName = AppWithDsfr . name ;
209
208
0 commit comments