File tree Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -59,9 +59,9 @@ const useIsDarkServerSide: UseIsDark = () => {
5959export const useIsDark = isBrowser ? useIsDarkClientSide : useIsDarkServerSide ;
6060
6161function getCurrentIsDarkFromHtmlAttribute ( ) : boolean {
62- const colorSchemeReadFromDom = document . documentElement . getAttribute ( data_fr_theme ) ;
62+ const colorSchemeReadFromHtmlAttribute = document . documentElement . getAttribute ( data_fr_theme ) ;
6363
64- switch ( colorSchemeReadFromDom ) {
64+ switch ( colorSchemeReadFromHtmlAttribute ) {
6565 case null :
6666 case "light" :
6767 return false ;
Original file line number Diff line number Diff line change @@ -140,6 +140,21 @@ export function createNextDsfrIntegrationApi(params: Params): NextDsfrIntegratio
140140
141141 const colorSchemeKey = "dsfrColorScheme" ;
142142
143+ const isDarkFromHtmlAttribute = ( ( ) => {
144+ if ( ! isBrowser ) {
145+ return undefined ;
146+ }
147+
148+ const colorSchemeReadFromHtmlAttribute =
149+ document . documentElement . getAttribute ( data_fr_theme ) ;
150+
151+ if ( colorSchemeReadFromHtmlAttribute === null ) {
152+ return undefined ;
153+ }
154+
155+ return colorSchemeReadFromHtmlAttribute as ColorScheme ;
156+ } ) ( ) ;
157+
143158 function withDsfr < AppComponent extends NextComponentType < any , any , any > > (
144159 App : AppComponent
145160 ) : AppComponent {
@@ -148,7 +163,7 @@ export function createNextDsfrIntegrationApi(params: Params): NextDsfrIntegratio
148163 ...props
149164 } : AppProps & Record < typeof colorSchemeKey , ColorScheme | undefined > ) {
150165 if ( colorScheme === undefined ) {
151- colorScheme = "light" ;
166+ colorScheme = isBrowser ? isDarkFromHtmlAttribute ?? "light" : "light" ;
152167 }
153168
154169 useEffect ( ( ) => {
You can’t perform that action at this time.
0 commit comments