Skip to content

Commit

Permalink
Store dark mode in cross-subdomain cookie (#8132)
Browse files Browse the repository at this point in the history
  • Loading branch information
Twixes authored Mar 26, 2024
1 parent e3cd2dd commit 391debc
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions gatsby-ssr.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ export const onRenderBody = function ({ setPreBodyComponents }) {
})
try {
preferredTheme =
(localStorage.getItem('theme') || (darkQuery.matches ? 'dark' : 'light')) ||
'light'
document.cookie.split('; ').find(row => row.startsWith('theme='))?.split('=')[1]
|| localStorage.getItem('theme')
|| darkQuery.matches ? 'dark' : 'light'
|| 'light'
} catch (err) {}
window.__setPreferredTheme = function (newTheme) {
setTheme(newTheme)
try {
localStorage.setItem('theme', newTheme)
} catch (err) {}
document.cookie = \`theme=\${preferredTheme}; Path=/; Domain=posthog.com\`
}
setTheme(preferredTheme)
})()
Expand Down

0 comments on commit 391debc

Please sign in to comment.