Skip to content

Commit 7cc8e7c

Browse files
committed
Updae tw-ssg example and test the changes -> everyhting ok except FOUC
1 parent 4880f58 commit 7cc8e7c

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

examples/tailwind-ssg/app/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default function RootLayout({ children }: { children: React.ReactNode })
1515
return (
1616
<html lang="en">
1717
<body className={[inter.className, "bg-white dark:bg-black dark:text-white"].join(" ")}>
18-
<Core t="background .3s" dp />
18+
<Core t="background .3s" />
1919
{children}
2020
</body>
2121
</html>

examples/tailwind-ssg/tailwind.config.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ const config: Config = {
88
],
99
theme: {},
1010
plugins: [],
11-
darkMode: [
12-
"variant",
13-
["@media (prefers-color-scheme: dark) { &:not(.light *) }", "&:is(.dark *)"],
14-
],
11+
darkMode: "class",
1512
};
1613
export default config;

lib/src/client/core/core.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ const modifyTransition = (themeTransition = "none", nonce = "") => {
3838
*/
3939
export const Core = ({ t, nonce }: CoreProps) => {
4040
const [{ m: mode, s: systemMode }, setThemeState] = useStore();
41-
const resolvedMode = mode === SYSTEM ? systemMode : mode; // resolvedMode is the actual mode that will be used
4241

4342
useEffect(() => {
4443
const media = matchMedia(MEDIA);
@@ -55,9 +54,11 @@ export const Core = ({ t, nonce }: CoreProps) => {
5554
}, []);
5655

5756
useEffect(() => {
57+
const resolvedMode = mode === SYSTEM ? systemMode : mode;
5858
const restoreTransitions = modifyTransition(t, nonce);
5959
const el = document.documentElement;
60-
el.classList[resolvedMode === DARK ? "add" : "remove"](resolvedMode);
60+
if (resolvedMode === DARK) el.classList.add(DARK);
61+
else el.classList.remove(DARK);
6162
[
6263
["sm", systemMode],
6364
["rm", resolvedMode],
@@ -66,7 +67,7 @@ export const Core = ({ t, nonce }: CoreProps) => {
6667
restoreTransitions();
6768
// System mode is decided by current system state and need not be stored in localStorage
6869
localStorage.setItem(COOKIE_KEY, mode);
69-
}, [resolvedMode, systemMode, mode, t, nonce]);
70+
}, [systemMode, mode, t, nonce]);
7071

7172
return null;
7273
};

0 commit comments

Comments
 (0)