@@ -126,6 +126,7 @@ export function getColorSchemeSsrUtils() {
126126 return { getColorSchemeHtmlAttributes, augmentDocumentByReadingColorSchemeFromCookie } ;
127127}
128128
129+ /** the App returned by witAppDsfr should be directly exported default as is */
129130export function withAppDsfr < AppComponent extends NextComponentType < any , any , any > > (
130131 App : AppComponent ,
131132 params : Params
@@ -170,40 +171,38 @@ export function withAppDsfr<AppComponent extends NextComponentType<any, any, any
170171 ) ;
171172 }
172173
173- Object . keys ( App ) . forEach (
174- staticMethod => ( ( AppWithDsfr as any ) [ staticMethod ] = ( App as any ) [ staticMethod ] )
175- ) ;
176-
177- $overwriteGetInitialProps . current = ( ) => {
174+ {
178175 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+ } ;
205204 } ;
206- } ;
205+ }
207206
208207 AppWithDsfr . displayName = AppWithDsfr . name ;
209208
0 commit comments