From 91db8a5fe05cb31d591d093b367755c3f5c9619a Mon Sep 17 00:00:00 2001 From: mkelvers Date: Tue, 26 May 2026 23:11:33 +0200 Subject: [PATCH] refactor: remove cookie-based theme persistence --- static/theme.ts | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/static/theme.ts b/static/theme.ts index d5d137d..3f07af2 100644 --- a/static/theme.ts +++ b/static/theme.ts @@ -1,7 +1,6 @@ type Theme = 'light' | 'dark'; const STORAGE_KEY = 'theme'; -const COOKIE_KEY = 'theme'; const getLocalStorage = (): Storage | null => { try { @@ -11,24 +10,6 @@ const getLocalStorage = (): Storage | null => { } }; -const readCookie = (key: string): string | null => { - const entries = document.cookie.split(';').map(part => part.trim()); - for (const entry of entries) { - if (!entry) continue; - const eqIndex = entry.indexOf('='); - if (eqIndex === -1) continue; - const k = entry.slice(0, eqIndex).trim(); - if (k !== key) continue; - return decodeURIComponent(entry.slice(eqIndex + 1)); - } - return null; -}; - -const writeCookie = (key: string, value: string): void => { - const maxAgeSeconds = 60 * 60 * 24 * 365; - document.cookie = `${encodeURIComponent(key)}=${encodeURIComponent(value)}; Max-Age=${maxAgeSeconds}; Path=/; SameSite=Lax`; -}; - const getPreferredTheme = (): Theme => { const prefersDark = window.matchMedia?.('(prefers-color-scheme: dark)')?.matches ?? false; return prefersDark ? 'dark' : 'light'; @@ -44,9 +25,6 @@ const getSavedTheme = (): Theme => { const fromStorage = normalizeTheme(storage?.getItem(STORAGE_KEY) ?? null); if (fromStorage) return fromStorage; - const fromCookie = normalizeTheme(readCookie(COOKIE_KEY)); - if (fromCookie) return fromCookie; - return getPreferredTheme(); }; @@ -59,7 +37,6 @@ const applyTheme = (theme: Theme): void => { } catch { // ignore } - writeCookie(COOKIE_KEY, theme); }; const cycleTheme = (): void => {