File tree Expand file tree Collapse file tree 2 files changed +15
-19
lines changed Expand file tree Collapse file tree 2 files changed +15
-19
lines changed Original file line number Diff line number Diff line change @@ -72,6 +72,8 @@ function getCurrentIsDarkFromHtmlAttribute(): boolean {
7272 assert ( false ) ;
7373}
7474
75+ export const refDoPersistDarkModePreferenceWithCookie = { "current" : false } ;
76+
7577export function startObservingColorSchemeHtmlAttribute ( ) {
7678 $isDark . current = getCurrentIsDarkFromHtmlAttribute ( ) ;
7779
@@ -84,26 +86,11 @@ export function startObservingColorSchemeHtmlAttribute() {
8486 ) ;
8587
8688 {
87- /*
88- const setColorSchemeCookie = (colorScheme: ColorScheme) => {
89- let newCookie = `${data_fr_theme}=${colorScheme};path=/;max-age=31536000`;
90-
91- set_domain: {
92- const { hostname } = window.location;
93-
94- //We do not set the domain if we are on localhost or an ip
95- if (/(^localhost$)|(^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$)/.test(hostname)) {
96- break set_domain;
97- }
98-
99- newCookie += `;domain=${hostname}`;
89+ const setColorSchemeCookie = ( isDark : boolean ) => {
90+ if ( ! refDoPersistDarkModePreferenceWithCookie . current ) {
91+ return ;
10092 }
10193
102- document.cookie = newCookie;
103- };
104- */
105-
106- const setColorSchemeCookie = ( isDark : boolean ) => {
10794 const colorScheme : ColorScheme = isDark ? "dark" : "light" ;
10895
10996 let newCookie = `${ data_fr_theme } =${ colorScheme } ;path=/;max-age=31536000;SameSite=Strict` ;
Original file line number Diff line number Diff line change @@ -22,7 +22,12 @@ import appleTouchIcon from "./dsfr/favicon/apple-touch-icon.png";
2222import faviconSvg from "./dsfr/favicon/favicon.svg" ;
2323import faviconIco from "./dsfr/favicon/favicon.ico" ;
2424import faviconWebmanifestUrl from "./dsfr/favicon/manifest.webmanifest" ;
25- import { data_fr_scheme , data_fr_theme , isDarkContext } from "./lib/darkMode" ;
25+ import {
26+ data_fr_scheme ,
27+ data_fr_theme ,
28+ isDarkContext ,
29+ refDoPersistDarkModePreferenceWithCookie
30+ } from "./lib/darkMode" ;
2631import type { ColorScheme } from "./lib/darkMode" ;
2732import DefaultDocument from "next/document" ;
2833
@@ -119,6 +124,10 @@ export function createNextDsfrIntegrationApi(params: Params): NextDsfrIntegratio
119124 ...startDsfrReactParams
120125 } = params ;
121126
127+ if ( doPersistDarkModePreferenceWithCookie ) {
128+ refDoPersistDarkModePreferenceWithCookie . current = true ;
129+ }
130+
122131 if ( isBrowser ) {
123132 startDsfrReact ( startDsfrReactParams ) ;
124133 } else {
You can’t perform that action at this time.
0 commit comments