File tree Expand file tree Collapse file tree 2 files changed +7
-6
lines changed Expand file tree Collapse file tree 2 files changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ export type ColorScheme = "light" | "dark";
8
8
9
9
export const data_fr_theme = "data-fr-theme" ;
10
10
export const data_fr_scheme = "data-fr-scheme" ;
11
-
11
+ export const rootColorSchemeStyleTagId = "root-color-scheme" ;
12
12
//export const $colorScheme = createStatefulObservable<ColorScheme>(() => "light");
13
13
export const $isDark = createStatefulObservable ( ( ) => false ) ;
14
14
@@ -121,10 +121,8 @@ export function startObservingColorSchemeHtmlAttribute() {
121
121
const setRootColorScheme = ( isDark : boolean ) => {
122
122
const colorScheme : ColorScheme = isDark ? "dark" : "light" ;
123
123
124
- const id = "root-color-scheme" ;
125
-
126
124
remove_existing_element: {
127
- const element = document . getElementById ( id ) ;
125
+ const element = document . getElementById ( rootColorSchemeStyleTagId ) ;
128
126
129
127
if ( element === null ) {
130
128
break remove_existing_element;
@@ -135,7 +133,7 @@ export function startObservingColorSchemeHtmlAttribute() {
135
133
136
134
const element = document . createElement ( "style" ) ;
137
135
138
- element . id = id ;
136
+ element . id = rootColorSchemeStyleTagId ;
139
137
140
138
element . innerHTML = `:root { color-scheme: ${ colorScheme } ; }` ;
141
139
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ import faviconWebmanifestUrl from "./dsfr/favicon/manifest.webmanifest";
25
25
import {
26
26
data_fr_scheme ,
27
27
data_fr_theme ,
28
+ rootColorSchemeStyleTagId ,
28
29
isDarkContext ,
29
30
refDoPersistDarkModePreferenceWithCookie
30
31
} from "./lib/darkMode" ;
@@ -195,7 +196,9 @@ export function createNextDsfrIntegrationApi(params: Params): NextDsfrIntegratio
195
196
href = { faviconWebmanifestUrl }
196
197
crossOrigin = "use-credentials"
197
198
/>
198
- < style > { `:root { color-scheme: ${ colorScheme } ; }` } </ style >
199
+ < style
200
+ id = { rootColorSchemeStyleTagId }
201
+ > { `:root { color-scheme: ${ colorScheme } ; }` } </ style >
199
202
</ Head >
200
203
{ isBrowser ? (
201
204
< App { ...( props as any ) } />
You can’t perform that action at this time.
0 commit comments