Persist the theme selector choice across page loads

Save an explicit light/dark choice to localStorage and clear it when
switching back to system. An inline head script applies the saved
colour scheme before first paint to avoid a flash of the system theme.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jonny Barnes 2026-10-24 20:20:21 +01:00
commit c3cf597950
Signed by: jonny
SSH key fingerprint: SHA256:CTuSlns5U7qlD9jqHvtnVmfYV3Zwl2Z7WnJ4/dqOaL8

View file

@ -25,6 +25,15 @@
<link rel="pgpkey" href="{{ config('app.url')}}/gpg.key">
@endif
@stack('head')
<script>
{{-- Apply a saved theme choice before first paint to avoid a flash of the system theme --}}
try {
const theme = localStorage.getItem('theme');
if (theme === 'light' || theme === 'dark') {
document.documentElement.style.setProperty('color-scheme', theme);
}
} catch {}
</script>
</head>
<body>
<header>