Skip to content

Commit

Permalink
fix: Add the theme attribute explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
gorzelinski committed Nov 25, 2024
1 parent d697a8a commit 810f9b3
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions hooks/use-theme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ export function useTheme() {
const saveTheme = (theme: Theme) => {
setTheme(theme)
setThemeAttribute(theme)
setCookie(COOKIES.theme, theme)
setCookie(COOKIES.theme, theme, {
sameSite: 'lax'
})
}

const toggleTheme = (theme: Theme): void =>
Expand All @@ -20,7 +22,11 @@ export function useTheme() {
const savedTheme = getThemeAttribute()
setTheme(savedTheme)

if (!hasCookie(COOKIES.theme)) setCookie(COOKIES.theme, savedTheme)
if (!hasCookie(COOKIES.theme)) {
setCookie(COOKIES.theme, savedTheme, {
sameSite: 'lax'
})
}

const listenOsThemeChange = (event: MediaQueryListEvent) => {
saveTheme(event.matches ? 'light' : 'dark')
Expand Down

0 comments on commit 810f9b3

Please sign in to comment.