next-themes: System preference doesn't work by default
When I read the docs it looks like system preference is set to true by default.
enableSystem = true: Whether to switch between dark and light based on prefers-color-scheme
But when I implement this or just browse the demo https://next-themes-example.vercel.app/ or the one with Tailwind — even though my macOS preference is set to dark, the theme gets set to light.
This doesn’t look like a sane default or a bug. My thought process is that next-themes would by default prefer the system’s preference when available and only fallback to light if it’s not.
Am I doing something wrong?
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 16 (5 by maintainers)
I published
0.0.13-beta.1with the following changes:systemis now the default theme isenableSystem === true, otherwise it’s stilllightlocalStorageon first load, only when you switch themeThese should resolve this issue. Please test, and let me know if you have any feedback.
Thanks for the response. I did read through the issue. It seems like a bad default. The main purpose of this library is to be able to adopt to the user preference since it doesn’t provide a UI (for setTheme which is a feature and is opt-in). Please consider making the
systemsetting default.My setup did start working I have no idea how. Bunch of cache removals and then setting themese manually etc — and now it works with:
But when I set
Post.theme =light;— that page theme doesn’t change to thelighttheme.If console log the the theme being forced
Then it logs
Component.theme light. This is not working because of the same caching issue?Sounds like you’re running into the same issue as #15. The documentation states:
So by default, your app will use
lighttheme, not system. You can change this by settingdefaultTheme(basically, just read through that issue as it’s the same discussion).The second problem you’re running into is one I plan to fix shortly: the theme is cached into localStorage immediately. This means the first time you loaded the website, it cached
light. Now, even though you’re changingdefaultTheme, we are respecting the cache. Try callingsetThemeor clearing the local storage cache yourself.I’m going to remove this behavior, so that the theme isn’t cached until a call to
setThemehas been made.