question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

System preference doesn't work by default

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:16 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
pacocourseycommented, Feb 23, 2021

I published 0.0.13-beta.1 with the following changes:

  • system is now the default theme is enableSystem === true, otherwise it’s still light
  • The default theme is not immediately saved to localStorage on first load, only when you switch theme

These should resolve this issue. Please test, and let me know if you have any feedback.

1reaction
ahmadawaiscommented, Jan 5, 2021

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 system setting 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:


<ThemeProvider attribute="class" defaultTheme="system" forcedTheme={Component.theme || undefined}>
			<Component {...pageProps} />
		</ThemeProvider>

But when I set Post.theme = light; — that page theme doesn’t change to the light theme.

If console log the the theme being forced

import { ThemeProvider } from 'next-themes';

function MyApp({ Component, pageProps }) {
	console.log(`Component.theme`, Component.theme);
	return (
		<ThemeProvider attribute="class" defaultTheme="system" forcedTheme={Component.theme || undefined}>
			<Component {...pageProps} />
		</ThemeProvider>
	);
}

export default MyApp;

Then it logs Component.theme light. This is not working because of the same caching issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Here's what to do if System Settings is not responding - MacPaw
Press Command + Option + Escape, choose System Settings in the window, and press Force Quit. 2. Restart your Mac in safe mode....
Read more >
Fix System Preferences Not Responding & Preferences Errors
Press Command + Space bar to bring up Spotlight search, then type in System Preferences. Open System Preferences from Finder > Applications > ......
Read more >
Default browser setting not working - Apple Community
Do NOT go to System Preferences instead Open Safari and go to Safari Preferences, the first drop down should offer the choice of...
Read more >
Why won't the system preferences on my Mac open? How can ...
By Pressing CMD and Space, typing in 'System Preferences', and pressing enter. OR by pressing CTRL, FN and F3, then using the left...
Read more >
Why cannot I see any browsers in system preferences?
That's what worked for me. Try setting Safari as the default browser in Safari prefs (General Tab). Restart your machine then go back...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found