Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should resolvedTheme obey forcedTheme? #252

Closed
shekharkhedekar opened this issue Feb 9, 2024 · 3 comments
Closed

Should resolvedTheme obey forcedTheme? #252

shekharkhedekar opened this issue Feb 9, 2024 · 3 comments

Comments

@shekharkhedekar
Copy link

shekharkhedekar commented Feb 9, 2024

We currently have enableSystem=true and use resolvedTheme all over our app. We also have a feature flag that turns theming on and off. But, if we set forcedTheme="light" and the system theme is dark, resolvedTheme still resolves to dark.

Unless I'm misunderstanding, it seems like resolvedTheme should be the same as forcedTheme if it is set.

Expected:

System Theme Theme Forced Theme Resolved Theme
light system undefined light
dark system undefined dark
light light undefined light
dark light undefined light
light system light light
dark system light light
light system dark dark
dark system dark dark
light custom-theme dark dark
dark custom-theme dark dark
@shekharkhedekar
Copy link
Author

cc @zachalbert

@shekharkhedekar
Copy link
Author

Here's what we are doing in the meantime:

import { useTheme as nextUseTheme } from "next-themes";

export const useTheme = () => {
	const nextTheme = nextUseTheme();

	const resolvedTheme = useMemo(
		() =>
			nextTheme.forcedTheme !== undefined ? nextTheme.forcedTheme : nextTheme.resolvedTheme,
		[nextTheme.forcedTheme, nextTheme.resolvedTheme]
	);

	return {
		...nextTheme,
		resolvedTheme,
	};
};

@trm217
Copy link
Collaborator

trm217 commented Apr 22, 2024

This behaviour will be in v1

@trm217 trm217 closed this as completed Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants