Skip to content

Commit 990ae84

Browse files
committed
Fix theme color not idrated correctly
1 parent f5f1527 commit 990ae84

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/lib/darkMode.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { assert } from "tsafe/assert";
33
import { createStatefulObservable, useRerenderOnChange } from "./tools/StatefulObservable";
44
import { useConstCallback } from "./tools/powerhooks/useConstCallback";
55
import { createContext, useContext } from "react";
6-
import { memoize } from "./tools/memoize";
76
import { getColors } from "./colors";
87

98
export type ColorScheme = "light" | "dark";
@@ -16,8 +15,6 @@ const $clientSideIsDark = createStatefulObservable<boolean>(() => {
1615
throw new Error("not initialized yet");
1716
});
1817

19-
export const getClientSideIsDark = memoize(() => $clientSideIsDark.current);
20-
2118
type UseIsDark = () => {
2219
isDark: boolean;
2320
setIsDark: (isDark: boolean | "system") => void;

src/next.tsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import type { AppProps, AppContext } from "next/app";
66
import type { DocumentProps, DocumentContext } from "next/document";
77
import { startReactDsfrNext } from "./lib/start";
88
import {
9-
getClientSideIsDark,
109
rootColorSchemeStyleTagId,
1110
SsrIsDarkProvider,
1211
data_fr_scheme,
@@ -145,8 +144,7 @@ export function createNextDsfrIntegrationApi(params: Params): NextDsfrIntegratio
145144
...props
146145
}: AppProps & Record<typeof isDarkPropKey, boolean | undefined>) {
147146
if (isDark === undefined) {
148-
//NOTE: No cookie and default "system" or client side
149-
isDark = isBrowser ? getClientSideIsDark() : false;
147+
isDark = isBrowser ? /*we do not use it*/ (null as any as boolean) : false;
150148
}
151149

152150
useEffect(() => {
@@ -182,13 +180,19 @@ export function createNextDsfrIntegrationApi(params: Params): NextDsfrIntegratio
182180
href={faviconWebmanifestUrl}
183181
crossOrigin="use-credentials"
184182
/>
185-
<style id={rootColorSchemeStyleTagId}>{`:root { color-scheme: ${
186-
isDark ? "dark" : "light"
187-
}; }`}</style>
188-
<meta
189-
name="theme-color"
190-
content={getColors(isDark).decisions.background.default.grey.default}
191-
></meta>
183+
{!isBrowser && ( //NOTE: On browser we handle this manually
184+
<>
185+
<style id={rootColorSchemeStyleTagId}>{`:root { color-scheme: ${
186+
isDark ? "dark" : "light"
187+
}; }`}</style>
188+
<meta
189+
name="theme-color"
190+
content={
191+
getColors(isDark).decisions.background.default.grey.default
192+
}
193+
/>
194+
</>
195+
)}
192196
</Head>
193197
{isBrowser ? (
194198
<App {...(props as any)} />

0 commit comments

Comments
 (0)