Skip to content

Commit 1a7054d

Browse files
authored
fix: page re-render on theme detection (#104)
1 parent 30a86d1 commit 1a7054d

19 files changed

Lines changed: 237 additions & 101 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ name = "tuono"
88
path = ".tuono/main.rs"
99

1010
[dependencies]
11-
tuono_lib = "0.19.6"
11+
tuono_lib = "0.19.7"
1212
glob = "0.3.1"
1313
time = { version = "0.3", features = ["macros"] }
1414
serde = { version = "1.0.202", features = ["derive"] }

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
"@mdx-js/react": "3.1.0",
1717
"clsx": "2.1.1",
1818
"modern-normalize": "3.0.1",
19-
"next-themes": "0.4.6",
2019
"posthog-js": "1.215.6",
2120
"react": "19.0.0",
2221
"react-aria-components": "1.8.0",
2322
"react-dom": "19.0.0",
2423
"remark-gfm": "4.0.1",
25-
"tuono": "0.19.6"
24+
"tuono": "0.19.7",
25+
"usehooks-ts": "3.1.1"
2626
},
2727
"devDependencies": {
2828
"@eslint/js": "9.21.0",

pnpm-lock.yaml

Lines changed: 32 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/App/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { TuonoLayoutProps } from 'tuono'
33

44
import { Navbar } from '@/components/Navbar'
55

6-
import MdxProvider from '@/components/MdxProvider'
6+
import { MdxProvider } from '@/contexts/MdxProvider'
77

88
import styles from './App.module.scss'
99

src/components/Breadcrumbs/Breadcrumbs.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import {
77
Breadcrumbs as AriaBreadcrumbs,
88
} from 'react-aria-components'
99

10-
import type { Page } from '@/components/ContentManager/ContentManagerContext'
11-
import { useContentManager } from '@/components/ContentManager/ContentManagerContext'
10+
import { useContentManager } from '@/contexts/ContentManager'
11+
import type { Page } from '@/contexts/ContentManager'
1212
import { BreadcrumbsDivider } from '@/icons/breadcrumbs-divider'
1313

1414
import styles from './Breadcrumbs.module.scss'

src/components/MdxProvider/MdxProvider.tsx

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/components/MdxProvider/index.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/components/SideNavigation/SideNavigation.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import {
99
Button,
1010
} from 'react-aria-components'
1111

12-
import { useContentManager } from '@/components/ContentManager/ContentManagerContext'
12+
import { useContentManager } from '@/contexts/ContentManager'
1313
import { IconArrow } from '@/icons'
14-
import type { Page } from '@/components/ContentManager/ContentManagerContext'
14+
import type { Page } from '@/contexts/ContentManager'
1515

1616
import styles from './SideNavigation.module.scss'
1717

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,22 @@
1-
import { useState, useEffect } from 'react'
21
import type { JSX } from 'react'
32

4-
import { useTheme } from 'next-themes'
53
import { Button } from 'react-aria-components'
64

5+
import { useTheme } from '@/hooks/useTheme'
6+
77
import styles from './theme-switch.module.scss'
88

99
export default function ThemeSwitch(): JSX.Element {
10-
const [mounted, setMounted] = useState(false)
11-
const { resolvedTheme, setTheme } = useTheme()
12-
13-
useEffect(() => {
14-
setMounted(true)
15-
}, [])
16-
17-
// useTheme will be undefined until mounted on the client. This means if we
18-
// try to render UI based on the current theme before mounting on the client,
19-
// we will get a hydration mismatch error.
20-
// docs: https://www.npmjs.com/package/next-themes
21-
if (!mounted) {
22-
return <div className={styles['theme-switcher-container']} />
23-
}
10+
const { toggle } = useTheme()
2411

2512
return (
2613
<Button
2714
onPress={() => {
28-
setTheme(resolvedTheme === 'dark' ? 'light' : 'dark')
15+
toggle()
2916
}}
3017
className={styles['theme-switch-button']}
3118
>
32-
<span className="caption bold">
33-
{resolvedTheme === 'dark' ? `Light` : `Dark`}
34-
</span>
19+
<span className="caption bold" />
3520
</Button>
3621
)
3722
}

src/components/ThemeSwitch/theme-switch.module.scss

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@use '@/styles/typography' as *;
2+
13
.theme-switch-button {
24
color: var(--content-primary);
35
border: none;
@@ -7,13 +9,29 @@
79
gap: 8px;
810
width: 54px;
911
height: 16px;
12+
cursor: pointer;
1013

1114
&::before {
1215
min-width: 10px;
1316
height: 10px;
1417
background-color: var(--content-primary);
1518
border-radius: 50%;
1619
content: '';
20+
margin-left: -7px;
21+
}
22+
23+
&::after {
24+
@extend .caption;
25+
@extend .semi-bold;
26+
margin-left: -8px;
27+
28+
:root[data-theme='dark'] & {
29+
content: 'Ligth';
30+
}
31+
32+
:root[data-theme='light'] & {
33+
content: 'Dark';
34+
}
1735
}
1836
}
1937

0 commit comments

Comments
 (0)